Blockly Script - Alert for flatlined sensors

I have an alert that emails us if an Item goes offline by setting an expiry metadata for 12 hr. and sending a refresh command to the Items in the group every 11 hrs. It works in some cases but other times it doesn’t.

So I created a test rule that sends an email if an Item does not change over a given time period. That seems to work. Now I want to use the same alert but monitor a group of sensors so I get an email if any of the sensors have not changed over a given period of time. So I replaced the block that had the Item in it with one to check the state of the Items in the group (get members of group > Flatline Group, in the script below) but it’s causing an error. I need to know the right way to have that block work correctly. Here’s the script:

image

Check out this thread on how to handle groups in Blockly.

Well that was pretty far into teh weeds for me. I have simplified this script for testing and out of that other thread, came up with this but it’s giving me an error that it’s failing to execute action 2:

image

I thought maybe it was because I wasn’t actually getting the state of the member first so I tried this but got the same result:

image

You’ll notice in the accepted solution in the linked thread that they assign the state of the member item to a variable first, before testing it.

Yeah I saw that but that’s where I kind of got lost. I’m not familiar with how that is accomplished. Also, it looks like the state of the battery levels in that example is mapped to an ON/OFF state. I assume that above a certain level they are on and then off below that level. That won’t work for me because I’m trying to get notified if an item DOESN’T change over a given period of time.

This should work

Blockly9

With this I get the log entry even if I change the state of an item in the group during the minute:

image
ng)

I checked again and it works, the problem is that persistence takes almost 40 seconds to store the values, see my logfile

2022-03-29 21:51:17.347 [INFO ] [org.openhab.rule.AATest             ] - Testrule Started

2022-03-29 21:51:17.476 [INFO ] [org.openhab.rule.AATest             ] - Reklame not changed

2022-03-29 21:51:17.483 [INFO ] [org.openhab.rule.AATest             ] - Terrasse not changed

2022-03-29 21:51:17.486 [INFO ] [org.openhab.rule.AATest             ] - Garten not changed

2022-03-29 21:51:17.488 [INFO ] [org.openhab.rule.AATest             ] - Grillplatz not changed

2022-03-29 21:51:17.490 [INFO ] [org.openhab.rule.AATest             ] - Parkplatz not changed

2022-03-29 21:51:17.492 [INFO ] [org.openhab.rule.AATest             ] - Gastgarten not changed

2022-03-29 21:51:31.031 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Outdoor_Garten' received command ON

2022-03-29 21:51:31.033 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Outdoor_Garten' predicted to become ON

2022-03-29 21:51:31.036 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Outdoor_Garten' changed from OFF to ON

2022-03-29 21:51:32.129 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Outdoor_Gastgarten' received command ON

2022-03-29 21:51:32.131 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Outdoor_Gastgarten' predicted to become ON

2022-03-29 21:51:32.135 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Outdoor_Gastgarten' changed from OFF to ON

2022-03-29 21:51:33.160 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Outdoor_Grillplatz' received command OFF

2022-03-29 21:51:33.162 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Outdoor_Grillplatz' predicted to become OFF

2022-03-29 21:51:33.165 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Outdoor_Grillplatz' changed from ON to OFF

2022-03-29 21:51:34.193 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Outdoor_Parkplatz' received command ON

2022-03-29 21:51:34.195 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Outdoor_Parkplatz' predicted to become ON

2022-03-29 21:51:34.201 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Outdoor_Parkplatz' changed from OFF to ON

2022-03-29 21:51:35.211 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Outdoor_Reklame' received command OFF

2022-03-29 21:51:35.213 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Outdoor_Reklame' predicted to become OFF

2022-03-29 21:51:35.218 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Outdoor_Reklame' changed from ON to OFF

2022-03-29 21:51:51.466 [INFO ] [openhab.event.RuleUpdatedEvent      ] - Rule 'AATest' has been updated.

==> /var/log/openhab/openhab.log <==

2022-03-29 21:51:52.254 [INFO ] [org.openhab.rule.AATest             ] - Testrule Started

2022-03-29 21:51:52.389 [INFO ] [org.openhab.rule.AATest             ] - Terrasse not changed

2022-03-29 21:51:52.396 [INFO ] [org.openhab.rule.AATest             ] - Garten not changed

2022-03-29 21:51:52.398 [INFO ] [org.openhab.rule.AATest             ] - Grillplatz not changed

2022-03-29 21:51:52.401 [INFO ] [org.openhab.rule.AATest             ] - Parkplatz not changed

2022-03-29 21:51:52.403 [INFO ] [org.openhab.rule.AATest             ] - Gastgarten not changed

==> /var/log/openhab/events.log <==

2022-03-29 21:52:08.197 [INFO ] [openhab.event.RuleUpdatedEvent      ] - Rule 'AATest' has been updated.

==> /var/log/openhab/openhab.log <==

2022-03-29 21:52:09.011 [INFO ] [org.openhab.rule.AATest             ] - Testrule Started

2022-03-29 21:52:09.147 [INFO ] [org.openhab.rule.AATest             ] - Terrasse not changed

first i run the rule to see all 6 items in my group
i switched 5 of them
17 seconds after i changed the first item i run the rule and still 5 items show up
after 34 seconds i run the rule again and only the item which was not changed show up

Roland Mayr, this is working for me. Thanks!