Echo a current state every 20 minutes

Hello, i would like to know how to refer to an item to echo it every 20 mins… For example, i have a recipie from IFTTT that sets the state of an item to ON or OFF (it’s a heating control) a few times a day. This sends an mqtt update to a rf node and turns on or off the heating. but occasionally this doesn’t happen, so i would like to maybe use a cron function to run every 20 minutes and echo whatever the current status is (on or off).

Any suggestions how i should tackle this? Do i need to set up a new variable to store the current value? or would the item state be sufficient for this? i am sure i’m overthinking this but i just cant seem to get out of the starting blocks…

That is a good question. I did a quick test and it does appear that the MQTT out item does store the last value published to MQTT over it so you could use the MQTT item. However, if you are using rrd4j keep in mind that your String MQTT item will not be stored in persistence (rrd4j can only store numerical data) so you will want to handle the case of the item being Undefined in your rule.

So with all that, setting up a cron triggered rule with a call to postUpdate(MyMqttItem, MyMqttItem.state) should work.

@bob_dickenson would probably suggest using a Proxy item, which I would agree seems a good choice in this case. You will create a proxy Item that IFTTT sends its value to. You create a rule that is triggered when the that item is updated. In the rule you send the updated value to your MQTT item. In your cron triggered rule get the value from the proxy item. If you do it this way you can then expand your rule’s logic or add additional rules that may need to react to updates or change the way you communicate to your heater and the proxy will isolate those changes so it doesn’t ripple through everything.

Thanks for the reply @rlkoshak you made me think about it differently, in fact my actual mqtt message is 1 and 0 and it is just mapped to on and off, I am using rrd4j so it shouldn’t be so much of an issue. i will probably try to start with your first method and if there are any problems i will try method 2.

Thanks, i will report back


The 2. method suggested by @rlkoshak is quite good, at least for the reason to have a clear interface (facade) between OH and IFTTT.

But I can’t see your problem: Whiy would you poll the state of an item? As long as it is not changed inbetween it should still hold the same state as when your last poll took place. I personally would just check the the changes for that reason, makes it a lot easier…
If you just want to check the OH internal changes and why your heating doesn’t work correctly you could use the event log where every change is listed (at least in my (standard) installation). The other possibility which will check events on MQTT, I would suggest the tool MQTTWarn (see This will listen for any kind of messages on the bus and do (nearly) any kind of action, including send e-mail, notification, etc. Quite an interesting tool which also can be used to send OH notifications for certain events (e.g. open windows when leaving home…)


Discalimer: No I’m not connected with the developer nor get any money for promoting this tool :wink:

Hi @DieterL the problem isn’t with openhab or mqtt, the problem is with the last part of the journey is sometimes not received correctly

[IFTTT] —> [Openhab] ----> [RF] —> [Heating node] sometimes there must be collisions in the rf part, or just not received correctly for another reason.

So i am trying to use openhab to just echo the current status so that if for instance the trigger is missed at 19:00 it will hopefully be seen at 19:20 or 19:40 etc… ok i might have a room a few degrees cooler, but for now it would be “good enough”
Next Year i am moving to a new house with another system, so i don’t want to work on the RF side of things which will be retired.

most of the time it works, it’s just for that 19th day out of 20 when it doesn’t work as expected.

Thanks and regards

@rlkoshak (or anyone!!) I seem to have confused myself somewhere, my rule i tried

rule “ECHO ecoswitch” //Echo status to ensure switching
Time cron “0 0/20 * 1/1 * ? *”
postUpdate(node2_sw1, node2_sw1.state)
//sendTweet("switch= " +node2_sw1.state) <- i used this to see output

So the output i am seeing when i send using a tweet as an output is ON and OFF, so i remembered that this must be like this because it is a switch item

Switch node2_sw1 “Living Room” (Heating,node2,all) { mqtt=">[mysensor:MyMQTT/25/4/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/25/4/V_LIGHT:command:OFF:0]" }

which only gives on/off…

But my problem is i don’t see the mqtt message repeated after 20 minutes… Does openhab only activate when the new value is different from the old one? or am i missing something a lot more simple…

Try sendCommand instead of postUpdate. Since your MQTT item is a switch it may need a command to send the update. I usually use String Items for my MQTT publishing so I can’t say for sure this is the reason, but sendCommand is the first thing I would try.

Hi Again, i guess i might be doing this wrong… i swapped the above postUpdate for sendCommand like this:

Time cron “0 0/20 * 1/1 * ? *”
logInfo(“Nodestate=”, “#” +node2_sw1.state + “#”)
sendCommand(node2_sw1, node2_sw1.state)

And all i got was errors about null, which i don’t understand. i thought null was when there was no value to work with. whereas i know there is a value for state because i saw it when i sent to twitter, and also no with using loginfo above i have the logfile result of:

2015-11-19 17:20:00.445 [INFO ] [penhab.model.script.Nodestate=] - #ON#

I’m sorry to keep dragging this out, i’m sure this seems more than obvious to some but i just don’t seem to get it for this.

One of the frustrating things about how the rules engine works is that it throws a null exception for just about everything including when it can’t cast from one type of object to another.

In this case it is possible (I’m not positive though) that it can’t cast the node2_sw1 to a String or it can’t cast node2_sw1.state to a String.

Try this and see if it works:

sendCommand(, node2_sw1.state.toString)

Alternatively try one of these two:




Personally where ever possible I prefer to call sendCommand on the Item as opposed to through the sendCommand action as it seems to be a bit more forgiving (i.e. can handle the casting better).

Don’t worry about it. And just so you know, This is one of the trickier parts of rules development because the exception doesn’t really reflect the cause of the error.

Thanks yet again… The first one sendCommand(, node2_sw1.state.toString) worked. at first it didn’t seem to be working but i wasn’t seeing errors or my logfile entry, almost gave up and moved on to try second suggestion, but instead i restarted openhab and it worked. normally just saving the rules file is enough, but either way i’m a happy man.

I think this is the third issue youve helped me resolve @rlkoshak , much appreciated.