I have a temperature sensor and wanted a rule to sent me a message though a Telegramm binding when the temperature is above 24 °C.
I was able to add the binding and configure a rule, but now I also receive messages when temperature is 24.1 °C, 24.1 °C and so on. So the idea was, that it only should message me when the threshold has been reached. If the temperature falls below the threshold and reaches it again, it should of course alert me again.
Figured this should be an easy task, but I was unsuccessful in configuring such a rule so far.
I thought I could add some filtering for the previous state to the trigger, but I didn’t get it working that way. also it does not seem I can add an operand there, which would surely be needed as the previous state could also be 23.8, not only 23.9 - so I’d like to add something like: only if previous state < 24 to the rule.
Maybe this cannnot be done using the trigger or condition but I would have to add it to the script?
Also found an add-on for “Thresholds” but it was unable to be installed - seems to be for OpenHab version 2 only.
It doesn’t quite exactly match your requirement but Threshold Alert might work for you. What it does is call your script (where you’ll implement the Telegram stuff) when a member of a Group exceeds the threshold, but only every so often (e.g. once every 8 hours, or every five minutes) and you can define a do not disturb time period.
The nice thing about rule templates is you just install and configure them, not coding required.
You’ll have to move on to using Script Conditions and Script Actions. You cannot get to where you want using only the core UI actions and conditions. You’ll need to write some real code. But you can do what you need using Blockly.
Blockly “compiles” to ECMAScript 5.1. You choose Blockly as the langauge.
However, with Blockly, you cannot manually edit the code in the code window or else the graphical part of Blockly can’t keep up.
Under “Run and Process” there is a block called “contextual info” which includes the previous state among other stuff. However, be aware that previous state only exists if the rule was triggered by an Item changed trigger.
Thanks, this looks promissing. I modified inside Blockly my script to use the previous state this way and will now make some test - I guess there can still be some issues related to the format of the state, as mentioned by @rossko57 but I’m sure I can find out the correct option sooner or later.