when
Item Sensor01 changed to OPEN or
Item Sensor02 changed to OPEN or
Item Sensor04 changed to OPEN or
Item Sensor09 chan...
then
pushover ( "A sensor is triggerd" )
Is there a way that I can use in my pushover message for a more human readable value? That my result would be something like “Frontdoor is changed to open” if sensor04 change, “Window bedroom is changed to open” if sensor9 change… ?
when
...
then
if (Sensor01.state == OPEN)
pushover ("Sensor01 triggered")
else if (Sensor02.state == OPEN)
pushover ("Sensor02 triggered")
...
end
The “better” way:
setup all items to meaningful names, so maybe instead of Sensor01Window_Bedroom
put all sensors to a group, maybe g_sensors
do a persistence of all group items
use a rule like this:
var string last_pushover=""
rule "send pushover"
when
Item g_sensors received update
then
val string act_pushover=g_sensors.members.filter[time|time.lastUpdate > now.minusSeconds(1)].last.name
if (act_pushover != last_pushover) {
last_pushover = act_pushover
pushover ("Sensor " + act_pushover + " triggered")
}
end
I’m pretty sure the code is not correct, but I’m at work, so no chance to test it, but I think, you got the idea anyway.
To elaborate on Udo’s solution, if you give your Items meaningful names and use underscores for spaces (e.g. Bedroom_Window) you can build a nicely human readable message from the Item’s name with some very simple string manipulation.
You also might need a sleep to give persistence a chance to catch up.
Finally, you probably don’t want to trigger the rule on updates the Group or else you will get multiple pushovers per event.
I use sortBy instead of filter by which will return only the most recently updated Item.
rule "send pushover"
when
Item Bedroom_Window changed to OPEN or
...
then
Thread::sleep(100)
val String act_pushover = g_sensors.members.sortBy[lastUpdate].last.name.replace('_', ' ')
if (act_pushover != last_pushover) {
last_pushover = act_pushover
pushover ("Sensor " + act_pushover + " triggered")
}
end
Yes but as implemented it will also suppress legitimate repeated of the alert. Fit example if you open the window, close it, then open it again you should receive two alerts. But this check will only send one.
Not that it is working, I’ll leave this here to give you some ideas on how you can make this generic so you don’t have to litter your rules with pushover calls and later decide to use something else.