Take your requirements and break them down and implement them one by one.
- Get the water level. Done via “The Thing and Item with the level is working so far.”
- Trigger a rule when the water level updates. Done via “type: core.ItemStateUpdateTrigger”
- Send an alert when the water is over > 20. Done via “if (level.state > 20)”
- Only send an alert once when the water is > 20 until the water level drops below 20 again.
OK so that’s a little more complicated. Let’s break 4 apart into smaller steps.
4a. Send the alert. Done via “Int_level_max.sendCommand(ON)”
4b. Record when the alert was sent. privateCache.put('alertSent', true)
4c. Only send the alert if one hasn’t already been sent. if(privateCache.get('alertSent', [ | false]))
4d. All an alert to be sent again once the level has dropped to 20 or below.
else {
privateCache.put('alertSent', false)
}
Putting it all together:
if(level.state > 20 && privateCache.get('alertSent', [ | false]) {
Int_level_max.sendCommand(ON)
privateCache.set('alertSent', true)
}
else {
privateCache.set('alertSent', false)
}
Or, because I strongly recommend against new development of rules in Rules DSL, in Blockly:
For a more capable approach that includes hystersis and do not disturb periods see Threshold Alert and Open Reminder [4.0.0.0;4.9.9.9] which can handle this use case. All you’d need to do is code the alert part and configure the rule with your Item, threshold as desired.