How to alert about high temperature only when threshold has passed?

OpenHab Version 3.2

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.

configuration: {}
  - id: "1"
      itemName: TempsensorWZ_ActualTemperature
      previousState: "24"
    type: core.ItemStateChangeTrigger
  - inputs: {}
    id: "2"
      itemName: TempsensorWZ_ActualTemperature
      state: "24"
      operator: ">"
    type: core.ItemStateCondition
  - inputs: {}
    id: "3"

Maybe this cannnot be done using the trigger or condition but I would have to add it to the script?

For the moment (as a beginner) I am a bit confused of how to get the previous state in the script. Apparently I set the script to use ECMA (JavaScript) and added the Telegramm part successfully using Blockly. I was unable to find something for “previousState” inside Blockly and using “previousState” in the (manual) code window resulted in error messages and the Blockly script being out-of-sync with was is in the code window…

Also found an add-on for “Thresholds” but it was unable to be installed - seems to be for OpenHab version 2 only.

Any tipps of how this can be achieved?

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.

So … it would never ever be 24 (or 24.0)
The unit is part of the state, and you will have to take that into account in your comparison as well, comparing with 24 °C

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.

Comment: the Quantity stuff (values with units) is not handled well within Blockly yet, I think.

The rule triggering and conditions syntax is separate business, I believe it works with units at OH3.2