Simple Timer switch rule help

Hi There,

I’m trying to get a really simple rule working which switches my tellstick nexa switch on and off everyday, but I don’t seem to be getting something right. My rule is below

rule “Switch on”
when
Time cron “0 55 7 1/1 * ? *"
then
sendCommand(bedsw,ON)
end

rule “Switch off”
when
Time cron “0 0 8 ? * MON-FRI *”
then
sendCommand(bedsw,OFF)
end

I have been watching the logs and I see the rule refreshes, but there is nothing being triggered in the logs :frowning:

PLEASE HELP!

First add some logging messages to the THEN clauses of your rules to see if they are even being triggered. (ie to see if your cron clauses are correctly formed).

If the rules are being triggered correctly via cron, then look to your item definition. Can you manipulate “bedsw” as defined thru a UI widget ?

Hi Bob,

Thanks for the reply, I have the switches already working in the openhab web UI just fine, so I’m slightly confused as to why the rule isn’t working? I have running openhab on a rasperberrypi 2 with the latest version of Rasbian jesse.

Are you able to tell me how to add logging messages? or is there a good guide somewhere? Thanks

In your case something like

rule "Switch on"
when
    Time cron "0 55 7 1/1 * ? *"
then
    logInfo("My switch rule", "cron has been triggered")
    sendCommand(bedsw,ON)
end

should help

good luck

Just to clarify @sam 's comment, the first phrase in the LogInfo command must match the name of a logger defined in logback.xml…a literal “My switch rule” may lead to (cough) “perplexing behavior”. Personally I have 8-10 loggers defined which route messages to different logfiles based on this behavior. NB you need both <appender…> and <logger…> definitions…



    
        
            %d{HH:mm:ss.SSS} %-5level %logger{30}[:%line] - %msg%n%ex{0}
        
    

    
        ${openhab.logdir:-logs}/openhab.log
        

            %d{HH:mm:ss.SSS} %-5level %logger{30}[:%line]- %msg%n%ex{5}
        
    

    
        ${openhab.logdir:-logs}/events.log
        
            
            ${openhab.logdir:-logs}/events-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %msg%n
        
    
    
    
        ${openhab.logdir:-logs}/rulelog.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    

 
        ${openhab.logdir:-logs}/startup.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    
 
        ${openhab.logdir:-logs}/2f.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    



        ${openhab.logdir:-logs}/shutdown.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    


        ${openhab.logdir:-logs}/kitchen.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    


        ${openhab.logdir:-logs}/stairwell.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    


        ${openhab.logdir:-logs}/hvac.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    
    
    
        ${openhab.logdir:-logs}/living.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    

    
        ${openhab.logdir:-logs}/zwave.log
        
        
            ${openhab.logdir:-logs}/zwave-%d{yyyy-ww}.log.zip
        
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{30}[:%line]- %msg%n%ex{5}
        
    
    
        ${openhab.logdir:-logs}/mqtt.log
        
        
            ${openhab.logdir:-logs}/mqtt-%d{yyyy-ww}.log.zip
        
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{30}[:%line]- %msg%n%ex{5}
        
    


    
        
    

    
        
    

    
        
    

    
        
        
    

    
        
    

    
        
    

    
        
    

    
        
    

    
        
    
         

    
        
    

    
        
    
    
        
    
    

    
    
    

    
    
    
    
    
    
    
        
        
    


Thanks @bob_dickenson

:smile:

Can you expand a little more on what you mean?

Perhaps with an example of how you then write to your 8-10 logs?

I have successfully been using lines like:

logInfo("Fon_IFTTT_Switch", "received command")
logInfo("Lux_Sensor", "received changed")

They all write to the same openhab.log file, but that is fine. I use iTerm to search and filter a tail when I am looking for something.

I thought perhaps you were referring to the spaces in "My Switch Rule" as I typically use an item or variable name in the first bit.

But I tested exact example given and it seemed to output what it was supposed to do correctly.

logWarn("My switch rule", "cron has been triggered")
2016-01-22 21:33:00.505 [WARN ] [.o.model.script.My switch rule] - cron has been triggered

Granted my knowledge of logging is cobbled together from scripts written by others. So I am always keen to learn where I am going wrong and why.

Many thanks

you can direct message to the appropriate log via the first argument to your logInfo (or logDebug etc) statement. E.g. logInfo(“KITCHEN”,“foobar”) will write “foobar” to the logfile described by appender and logger elements for “KITCHEN”.


        ${openhab.logdir:-logs}/kitchen.log
        
            
            ${openhab.logdir:-logs}/rulelog-%d{yyyy-ww}.log.zip
            
            30
        
        
            %d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{30}[:%line]- %msg%n
        
    


    

Thanks… and I think I can assume that anything that doesn’t match “KITCHEN” would be sent to default?

yes – or to anything it DID match. Personally I have 8-10 different loggers for various rooms/subsystems in my house.