Simple Rule to send MQTT CMD or HTTP hook based on RTC Schedule?

  • Platform information: RPi3 B+
    • openHAB version: 2.4
  • Issue of the topic:
    I know this or something like it has to be documented somewhere but I can’t find it.

I’m trying to use a ESP12e to control a SSR(solid state relay) and I want to have a rule/schedule that turns the SSR/hot water heater on and off at different times of day.

The ESP is running ESP Easy so I can control it using MQTT or HTTP calls.

The openhab documentation doesn’t seem to provide much about time triggers.
Can anyone provide me some examples for sending a command based on the time of day.

For example when the clock strikes 12:30PM send http cmd,12,1
and when the clock strikes 12:40PM send cmd,12,0

Thanks in advance for any help or advice you can provide.

For the curious, here are the docs:

They state

You can either use some pre-defined expressions for timers or use a cron expression instead:

There is a link there that takes you to a tutorial for how to build a cron expression. A little later there is a link to the Quartz documentation that provides even more information about how to build a cron expression.

Finally, there are two links to web based tools that will help you build your own cron based expressions.

We have neither the manpower nor would it be a good use of our time to reproduce documentation that exists elsewhere. You should always click on the links that are included in the openHAB docs for more information.

  1. Create a Rule with a Time based trigger with a cron expression that triggers the Rule at 12:30 PM.
  2. Use the sendHttpGetRequest to issue the command or use the HTTP Binding to set up a Switch Item that sends that command when you send an ON or OFF command to the Item, in which case just use `MyItem.sendCommand(ON).
  3. Create another Rule with a Time based trigger with a cron expression that triggers the Rule at 12:40 PM.
  4. As with 2, issue the HTTP command.
1 Like

Hi @rlkoshak
Sorry I should have mentioned I did click the links and was able to create a cron expression.
But my rule didn’t work for me. I figured someone had done something similar and could provide some example rules of how they created a outdoor timer using a relay switch and openhab rules.
I’m not a programmer but I can usually modify code to work for me as long as it’s somewhat close to what I’m attempting to do. Again I apologize for the redundant questioning as I realize I should be able to use the documentation to answer this but even after reading everything about time triggers and following the links I still felt lost. I was hoping to save face and not show my attempt at creating a rule file, from scratch but I guess I can’t hide it. Can you tell me if this should be working because the logs don’t have a problem with it.

// Water Heater Time Schedule
rule "Turn On Heater"
   Time cron "0 30 19 1/1 * ? *"
Switch  WaterHeater "Water Heater" <faucet> (SmartLights) {http=">[ON:POST:,5,1:on] >[OFF:POST:,5,0:off]"}

Thanks again for all the time and support on this.

Don’t be shy! I’ve found people are more likely to help when you show them you’ve put time and effort in, than when you appear to be just asking for an easy answer.

It looks reasonable. Did you look in both openhab.log and events.log for the time you expect the rule to run? It helps to give a view of what is and is not happening.

For your Item, you can of course put it into your UI as a switch and operate it by clicking to test. If that doesn’t work, your rule won’t be able to operate it either, and you might then look at your binding configuration.
Is the appropriate binding installed?

I will save some pain and point out that the colon character : is used by the HTTP binding as delimiter between parameters like ON and POST and the URL.
It looks like you are trying to send a URL that includes a : ? You’ll need to hide it from the binding by encoding it.

Add a logging statement to the Rule.

Look in openhab.log when you make a change to this file to see if there are errors. Do the same for the .items file.

The cron expression looks OK (every day at 19:30:00) so either the Item is wrong or there is some other error somewhere else in the file there is an error.

Thanks guys I got it working now I think it might have just been a problem with item names not matching.
Here is my working Example
Items File

 Switch  WaterHeater "WaterHeater" <faucet> (SmartItems)  {http=">[ON:POST:,5,1:on] >[OFF:POST:,5,0:off]"}

Here is my on and off working rule.

// Water Heater Time Schedule
rule "Turn On Heater"
   Time cron "0 37 15 1/1 * ? *"

rule "Turn Off Heater"
   Time cron "0 38 15 1/1 * ? *"

After setting up the item in the sitemap and successfully controlling it from there I was able to get it working with the rules.
Thanks again for all your help and advise.