May 2, 2019, 10:18pm
I’ve got a bunch of battery based sensors (xiaomi temperature) that I don’t trust their battery monitoring. So was to implement some sort if check that if no temp posted in greater than 12 hours, to alert me it probable needs a new battery.
Now I know for each item I can create a date time item with it and a rule that on every change update date time item…I do this already on a couple of dht12 sensors…but this strikes me as inelegant.
With persistence I know that can be set up on a group…they already go off to influxdb, so it would make sense to try and pull it from there. If I have to and can use mapdb I will for these items as well.
Does this mean I could grab the group of temperature sensors, and iterate over it and get the
<item>.lastUpdate and check it against a predetermined time and alert off that?
May 2, 2019, 10:39pm
Do you use Grafana? I found using their alerting mechanism much easier, just make sure your persistence is set to everyUpdate else if there is no temp change then it doesn’t get stored into influx and the grafana email alert will fire incorrectly.
May 2, 2019, 10:41pm
Hmm I did not know that (and yes I do)…can grafana do anything cooler than email? mqtt/rest call?
That would be a good logical place to handle this functionality
May 2, 2019, 10:49pm
Possibly, never looked beyond email as this was enough to alert me that one of my zwave devices had not reported for 2 hours.
May 2, 2019, 11:21pm
Make a one-ruleto-to-timestamp-them-all, using Group. Add any Item to a Group, create a DateTime Item for each with an associated name, like someSensor_timestamp.
So here are the two working Solutions:
Option 1: Using ScriptServiceUtil
Member of fg_gStatus_gSensor_gWindow changed from OPEN to CLOSED
val myItem = ScriptServiceUtil.getItemRegistry.getItem(triggeringItem.name+"Timestamp")
//logInfo("Window", "Item " + myItem)
val duration = (now.millis - (myItem.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli) / 1000
//logInfo("Window", triggeringItem.name+" was Open f…
You probably want to persist the timestamps, and restore on startup. But this method does not otherwise persistence.
May 3, 2019, 2:35am
I think I like the grafana method…So I’ve added an alert for that…and I’ve just shut down one of my temperature sensors to see what happens…hopefully it picks it up.
I’ve also asked grafana for a feature request to add mqtt as a notification option.
May 3, 2019, 9:29am
How have you got this set up?
Are you running a query for each, it a manual query for each access? Or using a regex to select all the series?
And how is the alert set up?
May 3, 2019, 9:53am
One for the temperature item for each of my sensors, checks (every 30 min to reduce load) if no data for 2 hours
May 3, 2019, 9:55am
Ahh right, and your metrics are set up like this?
May 3, 2019, 10:36am
Slightly different, as you get some smoother looking graphs with fill(linear)
You also need to add your smtp stuff to /etc/grafana/grafana.ini and setup your default notification channel
May 4, 2019, 4:22am
Not sure if you got this working but I found this while researching tidying up my persistence, examples at the bottom and seems simple enough and can send to mqtt.
May 4, 2019, 6:52am
Yeah I did get it working, but I might look at the rule option as well. Only because grafana does pushover and slack.
Also its not very flexible on that you have to query each thing individually. And while it works, something that just iterates over a group would be preferred