Cron based rule with Rule On/Off switch and Telegram reporting fails

First what I try to accomplish: I have a small fountain in the garden, and I would like to make it every half hour for one minute to turn on so the freezing cold (-10) doesn’t break the pump and the casing. Taking it all apart is lots of work, so I would like to avoid that. When it’s not freezing, I want a switch to turn the rule on and off. Even better would be that I can do it automatically based on the forecast, but that’s a next step.

What I made:

A switch:

Switch Winterrule "Winter in de tuin"

The rule:

rule "WinterTimer"

when
    Time cron "0 */30 * ? * * "
then 
    if (Winterrule.state == OFF) return false
    light_Zithoek_Schilderij.sendCommand(ON)
      createTimer(now.plusMinutes(1) [ |
            light_Zithoek_Schilderij.sendCommand(OFF)
        ]
    sendTelegram("OHBot", "Fontein draait nu")
end

I based this on Disabling a rule with a switch and My first Rule - light on and off every 10 seconds (can't make most basic rule work) with code from @5iver and @watou and @Spaceman_Spiff

rule “Coffee on 630am”
when
Time cron “00 30 06 * * ?”
then
if (coffeetimer.state == OFF) return false

sendCommand(plug5, ON)

end

Try going even simpler…

rule "My first rule"
when
   Time cron "0/10 0 0 ? * * *"
   //Every 10 seconds starting at second 00, at minute :00, at 00am, of every day 
then 
    logInfo("Test","My first rule just ran")
end

Now tail the openhab.log and you should see the log entry every 10s. If that works, then add in your command with another logInfo after it, and see if the rule still runs.

I already have different succesfull rules, the Telegram bot works no problem, but

  1. the simple rule does not show up. in my logging, while everything else shows up prefectly.
2019-01-21 22:52:04.672 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'cron.rules'

==> /var/log/openhab2/events.log <==

2019-01-21 22:52:49.493 [vent.ItemStateChangedEvent] - Time changed from 2019-01-21T22:51:49.431+0100 to 2019-01-21T22:52:49.452+0100

2019-01-21 22:52:49.506 [vent.ItemStateChangedEvent] - Date changed from 2019-01-21T22:51:49.431+0100 to 2019-01-21T22:52:49.452+0100

2019-01-21 22:53:49.514 [vent.ItemStateChangedEvent] - Time changed from 2019-01-21T22:52:49.452+0100 to 2019-01-21T22:53:49.461+0100

2019-01-21 22:53:49.526 [vent.ItemStateChangedEvent] - Date changed from 2019-01-21T22:52:49.452+0100 to 2019-01-21T22:53:49.461+0100

2019-01-21 22:54:49.511 [vent.ItemStateChangedEvent] - Time changed from 2019-01-21T22:53:49.461+0100 to 2019-01-21T22:54:49.470+0100

2019-01-21 22:54:49.523 [vent.ItemStateChangedEvent] - Date changed from 2019-01-21T22:53:49.461+0100 to 2019-01-21T22:54:49.470+0100

2019-01-21 22:55:49.528 [vent.ItemStateChangedEvent] - Time changed from 2019-01-21T22:54:49.470+0100 to 2019-01-21T22:55:49.492+0100

2019-01-21 22:55:49.534 [vent.ItemStateChangedEvent] - Date changed from 2019-01-21T22:54:49.470+0100 to 2019-01-21T22:55:49.492+0100

2019-01-21 22:56:49.542 [vent.ItemStateChangedEvent] - Time changed from 2019-01-21T22:55:49.492+0100 to 2019-01-21T22:56:49.506+0100

2019-01-21 22:56:49.557 [vent.ItemStateChangedEvent] - Date changed from 2019-01-21T22:55:49.492+0100 to 2019-01-21T22:56:49.506+0100

2019-01-21 22:57:49.556 [vent.ItemStateChangedEvent] - Time changed from 2019-01-21T22:56:49.506+0100 to 2019-01-21T22:57:49.518+0100

2019-01-21 22:57:49.568 [vent.ItemStateChangedEvent] - Date changed from 2019-01-21T22:56:49.506+0100 to 2019-01-21T22:57:49.518+0100
  1. I copy pasted the code together, but it doesn’t do a darn thing.

Any pointers please?

logInfo goes into openhab.log, not events.log

I would expect that you have errors in your file which are preventing it form loading, due to how you are using the return. There should be log entries in openhab.log for this. I also changed your cron expression. Look here, and try…

rule "WinterTimer"
when
    Time cron "0 0/30 * * * ? "
then 
    if (Winterrule.state == OFF) return;
    light_Zithoek_Schilderij.sendCommand(ON)
        createTimer(now.plusMinutes(1) [ |
            light_Zithoek_Schilderij.sendCommand(OFF)
        ]
    sendTelegram("OHBot", "Fontein draait nu")
end

Hi, thx for the reply.

I do see

==> /var/log/openhab2/openhab.log <==

2019-01-22 08:20:52.714 [INFO ] [class.ZWaveMultiInstanceCommandClass] - NODE 6: Received a multi instance encapsulation with a destination endpoint = 2. 

So I supposed I saw the whole log from openhab.log too. For these simple pointers, do I need to set it to debug too?

This has nothing to do with the rule (Look at the time stamp)
You rule will trigger at xx:00 and xx:30 (Every 30 minutes)
The rule posted by @5iveris missing a closing bracket for the timer.
I use this syntax:

rule "WinterTimer"
when
    Time cron "0 0/30 * * * ? "
then 
    if (Winterrule.state == OFF) return; // Do nothing
    light_Zithoek_Schilderij.sendCommand(ON)
    createTimer(now.plusMinutes(1), [ |
        light_Zithoek_Schilderij.sendCommand(OFF)
    ])
    sendTelegram("OHBot", "Fontein draait nu")
end

Hi

It wasn’t for the Zwave that I wrote that, but for the part ==> /var/log/openhab2/openhab.log <== :slight_smile:
I’ll play around with the log levels a little, but from the original post I quoted in OP I understood that this would be standard log behaviour.

Your syntax doesn’t give me errors, so I’ll try from that one on. Thanks a lot!

Thank you for catching that… I just copied what the OP had posted, and didn’t look at the Timer format.

@bdv, this should have also thrown an error when the file was saved. If you’re watching the log and not seeing errors when saving the file, then something is funky with your logging.

It indeed threw an error, but I couldn’t figure out what it was.

All works, so /me is a happy camper! Thanks a lot!

Using VS code to edit your files would have shown you your error straight away: