Human Readable pushover messages

I’ve got a small script with following:

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… ?

Quick ‘n’ dirty:

when
...
then
    if (Sensor01.state == OPEN)
        pushover ("Sensor01 triggered")
    else if (Sensor02.state == OPEN)
        pushover ("Sensor02 triggered")
...
end

The “better” way:

  1. setup all items to meaningful names, so maybe instead of Sensor01 Window_Bedroom
  2. put all sensors to a group, maybe g_sensors
  3. do a persistence of all group items
  4. 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

The if (act_pushover != last_pushover) should prevent multiple identical mesages :wink:

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.

When I’m using following script, it’s working great:

val String act_pushover = ALL_con.members.sortBy[lastUpdate].last.name.replace(‘_’, ’ ')
pushover (“De " + act_pushover + " werd geopend in alarmmodus”)

When I use this:

val String act_pushover = ALL_con.members.sortBy[lastUpdate].last.name.replace(‘_’, ’ ')
if (act_pushover != last_pushover) {
last_pushover = act_pushover
pushover (“De " + act_pushover + " werd geopend in alarmmodus”)
}

I’m getting following error:

Error during the execution of rule ‘Activate alarm…’: The name ‘last_pushover’ cannot be resolved to an item or type.

Somewhere, the ‘last_pushover’ isn’t been threated properly.

You are likely missing the var string last_pushover="" at the top of your rules file.

Indeed, is working great now!

I’ve also added a ‘loginfo’ rule after the pushover. This way, a message is being send, and the event is being logged.

Thanks a lot!!!

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.