i am just starting with OH3 and i am completely lost with a simple task and although i have been trying to find a solution on my own, i failed.
My current setup is pretty simple:
I have two magnetic valves that are connected to a relay and MQTT server running on a NodeMCU / RaspberryPi. In OH3 (running in a docker container on a separate home server) i have added the binding, things, items and added a switch to Pages through the PaperUI. This is working and i can turn on / off the valves by tapping on the switch.
What i was unable to figure out is how i can say that if the magnetic valve receives the mqtt command “on” a timer is started that turns the valve off after e.g. 30 minutes, meaning the mqtt command “off” is sent. I tried to add meta data / expiration timer on the item itself, but as i learned this is not working as the status is updated periodically and therefore the expiration timer is always restarted.
My next idea would have been to create a rule, but there i no dedicated action for such things. So i thought of adding a script as a rule action but also failed to define something with the Blockly editor.
Then i started to search and i have found some rules for OH2.x but i am not sure how to transform such manually created rules to the OH3 code syntax.
Eventually somebody could point me to the right direction i that i should investigate further… is my usecase even configurable over the PaperUI?
i meant MainUI … i just messed it up due to too much information, sorry. The nodemcu is sending its status to the topic every other minute, so expire timer is not triggered. As said i already tried that. Thanks for the conversion link, i will check it out.
I am note sure with what firmware the NodeMCU was shipped, but i definitely haven’t thought of flashing Tasmota to it. Another thing i can check out, thanks
As should be clear by now from T’s suggestion, something like this is often best implemented on the device itself. It’s a NodeMCU so you should have full control over its behavior. For example, why is it sending its status every two minutes? If the status isn’t changing why is it publishing these updates. That’s somewhat of an anti-pattern for MQTT. It should be using a retained message and only publishing when the status changes.
Everything text based that applied to openHAB 2.x also applies to OH 3. There are a few minor changes to certain function calls and the like but beyond that nothing’s changed. So if you see a Rule example you should be able top put that into a .rules file in /etc/openhab/rules, as documented at Rules | openHAB.
If you want to stick with defining the rules in MainUI then often the only thing needed is to copy the contents between the then and end into a Script Action.
Ultimately what you need is a Timer. When the Item receives an ON command the script will create a Timer for 30 minutes to turn it off. But timers get complicated. Should the timer ever be cancelled? 30 minutes is a long time, what should happen if OH is restarted before the OFF command is sent? Dealing with valves where flooding and lots of money could be the result if OH crashed is one reason why something like this is better implemented at the device and not external to the device.
thank you for your thoughts and information. Indeed it is best if the NodeMCU itself is closing the valves. I have now flashed Tasmota and am controlling the timer with pulseaudio directly on the node.
And again a thank you for the rules explanation, lot of usefull information that will help me when i extend my installation.