Scheduling rule for coffee maker with delay/timer (Beginner)

  • Platform information:

    • Hardware: Raspberry Pi 3b+ Processor: BCM2835; Linux 4.19.50-v7+ armv7l
    • OS: Raspbian GNU/Linux 10 (buster); Firmware #896
    • Java Runtime Environment: (build 11.0.8+10-post-Raspbian-1deb10u1); Version 11.0.8" 2020-07-14
    • openHAB version: 2.5.9 Release Build
  • Please post configurations (if applicable):

  • Issue of the topic: please be detailed explaining your issue:

Dear community,
After setting up my openHAB successfully on the above mentioned environment I am now getting in touch with my first rule:

The goal is to prepare my coffee machine in terms of power on and rinse action on a specific time in the morning with a delay of 2 minutes / 120 seconds between both actions.

  1. Power on coffee maker every Monday and Wednesday at 04:45am
  2. Wait 120 seconds
  3. Start mandatory rinse action

Both actions are successfully covered with two switch items using the http-binding which are stated above.

One approach could be covering both actions in two rules, the second rule is just postponed 2 minutes in the cron minute time:

Rule "Kaffeemaschine power on"
when
              Time cron 0 45 4 ? * MON,WED *
then
Coffee_PowerOn.sendCommand(On)
end

Rule "Kaffeemaschine rinse"
when
              Time cron 0 47 4 ? * MON,WED *
then
              Coffee_Rinse.sendCommand(On)
end

Is my general understanding of the syntax correct? To have this task combined into one rule, my preferred approach would be the following:

Rule "Kaffeemaschine preparation"
when
              Time cron 0 45 4 ? * MON,WED *
then
              Coffee_PowerOn.sendCommand(On)
              createTimer(now.plusSeconds(120), [ Coffee_Rinse.sendCommand(On) ])
end

Same question here: Is my general understanding of the syntax correct? Right now I am not able to check the openHab logs/events for testing because the logging seems to be broken. I will create another thread for this issue.

Therefore this request to you is just to make sure that I heading into the right direction. Any approvals, advices and improvements are appreciated. Thanks!

Best regards,
Markus

PS: Sorry for the formatting
Edit: Code fencing

You need to use code fences for configuration to avoid the forum stripping out necessary spacing.

Thanks for the hint, text and code passages are updated!

1 Like

Your rules, where spaces matter, need code fences too.

I think I got it now :wink:

1 Like

Thank you.

I may be wrong but I thought rules need 4 spaces for indents. I may be mistaken, though,

Running multiple commands in the same rule is fine. I do it in some of mine.

Great, thanks for looking into this. How about the general syntax for my prefered rule:

Rule "Kaffeemaschine preparation"
when
              Time cron 0 45 4 ? * MON,WED *
then
              Coffee_PowerOn.sendCommand(On)
              createTimer(now.plusSeconds(120), [ Coffee_Rinse.sendCommand(On) ])
end

Is the syntax for the timer correct in terms of brackets?

I have not used createTimer(). Sorry.

Sure, no problem. I added the rule to my openHAB environment with adding TUE for tomorrows test. I will let you know if can directly make coffee or not :slight_smile:

Unfortunately I am not able to check the logs due to the issue with the logging mechanism from my other thread.

Send ON… not On (case sensitive).

2 Likes

Thanks! Directly corrected in my rules file

Another thing… if you want to test this now, add a System started trigger and the rule will trigger when the file is saved. Remove it when you are done testing.

1 Like

Thank you all for your comments. With your help I got it runnung with the System startedcondition.

2020-12-15 12:12:46.171 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'ikea.rules'

2020-12-15 12:12:52.518 [ome.event.ItemCommandEvent] - Item 'Coffee_PowerOn' received command ON
2020-12-15 12:14:52.527 [ome.event.ItemCommandEvent] - Item 'Coffee_Rinse' received command ON

It worked perfectly with System started condition, therefore I exchanged it now with the required cron time expression. Is it correct to put the cron expression into <"">?

rule "Ikea"
when
    Time cron "0 45 4 ? * MON,WED *"
then
    Coffee_PowerOn.sendCommand(ON)
    createTimer(now.plusSeconds(120), [ Coffee_Rinse.sendCommand(ON) ])
end

According to the logs the rule was sucessfully loaded. Lets see if the coffee maker is ready tomorrow morning :slight_smile:

Yes, quotes around Quartz cron expression…

https://www.openhab.org/v2.5/docs/configuration/rules-dsl.html#time-based-triggers