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

**URL:** <https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104>\
**Category:** Scripts & Rules\
**Created:** [January 21, 2019, 10:17pm UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104 "2019-01-21T22:17:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 21, 2019, 10:17pm UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/1 "2019-01-21T22:17:51Z")

</div>

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:

```csv
Switch Winterrule "Winter in de tuin"

```

The rule:

```csv
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](https://community.openhab.org/t/disabling-a-rule-with-a-switch/3869) and [My first Rule - light on and off every 10 seconds (can't make most basic rule work) - #12 by KevinHab](https://community.openhab.org/t/my-first-rule-light-on-and-off-every-10-seconds-cant-make-most-basic-rule-work/42066/12) 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…
> 
> ```auto
> 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](https://docs.openhab.org/administration/logging.html) 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.

```csv
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?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [January 21, 2019, 11:06pm UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/2 "2019-01-21T23:06:56Z")

</div>

logInfo goes into openhab.log, not events.log

---

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [January 22, 2019, 4:05am UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/3 "2019-01-22T04:05:02Z")

</div>

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](https://www.openhab.org/docs/configuration/rules-dsl.html#early-returns), and try…

```auto
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

```

---

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 22, 2019, 7:44am UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/4 "2019-01-22T07:44:00Z")

</div>

Hi, thx for the reply.

I do see

```csv
==> /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?

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [January 22, 2019, 9:44am UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/5 "2019-01-22T09:44:21Z")

</div>

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

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:

```php
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

```

---

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 22, 2019, 12:50pm UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/6 "2019-01-22T12:50:08Z")

</div>

Hi

> [@vzorglub](#):
>
> > [@bdv](#):
> >
> > 2019-01-22 08:20:52.714 [INFO] [class.ZWaveMultiInstanceCommandClass] - NODE 6: Received a multi instance encapsulation with a destination endpoint = 2.
> 
> 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)

It wasn’t for the Zwave that I wrote that, but for the part ==\> /var/log/openhab2/openhab.log \<== 🙂  
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!

---

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [January 22, 2019, 3:32pm UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/7 "2019-01-22T15:32:25Z")

</div>

> [@vzorglub](#):
>
> The rule posted by @5iveris missing a closing bracket for the timer.

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.

---

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 22, 2019, 8:17pm UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/8 "2019-01-22T20:17:39Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [January 22, 2019, 8:22pm UTC](https://community.openhab.org/t/cron-based-rule-with-rule-on-off-switch-and-telegram-reporting-fails/65104/9 "2019-01-22T20:22:20Z")

</div>

> [@bdv](#):
>
> It indeed threw an error, but I couldn’t figure out what it was.

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

> [@VS Code openHAB Extension!](https://community.openhab.org/t/vs-code-openhab-extension/30205):
>
> I’m pleased to announce that openHAB has now an official [Visual Studio Code](https://code.visualstudio.com/) extension. trumpet trumpet trumpet[GitHub - openhab/openhab-vscode: VS Code extension for openHAB configuration files](https://github.com/openhab/openhab-vscode)Features Code snippets for openHAB including [Design Patterns](https://community.openhab.org/tags/designpattern) by @rlkoshakSyntax highlighting for openHAB DSL (rules, items, scripts and sitemaps). Integrated quick search of openHAB docs page (Alt + Shift + O) Integrated Basic UI preview window (Ctrl + Alt + O or editor title icon) Screenshots o…
