I don’t think you can show it on Grafana or the sitemap without creating a separate Item. So I think you can do the following:
Longestuptime28daysDate.postUpdate(Systemuptime.maximumSince(now.minusDays(28)).getTimeStamp.toString)
I’m making an assumption that Java’s Date toString is ISO 8601 formatted. If not we need to do a little bit of a conversion.
I can’t find where I posted this before so here it is again.
rule "Keep track of the last time a door was opened or closed"
when
Member of gDoorSensors changed
then
if(previousState == NULL) return;
val name = triggeringItem.name
val state = triggeringItem.state
// Update the time stamp
postUpdate(name+"_LastUpdate", now.toString)
// Set the timer if the door is open, cancel if it is closed
if(state == OPEN) sendCommand(name+"_Timer", "ON")
else postUpdate(name+"_Timer", "OFF")
// Set the message
val msg = new StringBuilder
msg.append(transform("MAP", "en.map", name) + " was ")
msg.append(if(state == OPEN) "opened" else "closed")
var alert = false
if(vTimeOfDay.state.toString == "NIGHT" || vTimeOfDay.state.toString == "BED") {
msg.append(" and it is night")
alert = true
}
if(vPresent.state == OFF) {
msg.append(" and no one is home")
alert = true
}
// Alert if necessary
if(alert){
msg.append("!")
val timer = flappingTimers.get(name)
if(timer !== null) {
logWarn(logName, name + " is flapping!")
timer.cancel
flappingTimers.put(name, null)
}
else {
flappingTimers.put(name, createTimer(now.plusSeconds(3), [ |
aAlert.sendCommand(msg.toString)
flappingTimers.put(name, null)
]))
}
}
// Log the message if we didn't alert
else {
logInfo(logName, msg.toString)
}
end
The above uses Design Pattern: Associated Items, Design Pattern: Human Readable Names in Messages and some other DPs I’m sure.
Theory of operation: When ever a sensor changes state I postUpdate now.toString to the associated LastUpdate Item. So what you are asking about is in the first 11 lines of the Rule including the rule header stuff and spaces. The rest of the Rule sets a flapping timer (my back door timer flaps when it gets below 25 degrees F) and sends an alert when the Timer goes off if an alert is warranted (no one is home, it is night time, etc).
No. Keep MapDB for restoreOnStartup and only use InfluxDB for data you want to chart, analyze or save for some reason. MapDB never grows and is faster than InfluxDB in most circumstances.
That’s a pretty concise guide. Thanks for posting it. I’ve been meaning to install them on my RPis. But this will only work if the RPi itself goes unresponsive. It can’t, for example, reboot if the RPi’s network only goes offline, right? For something like that I’d need to use something like systemd’s watchdog, right? It’d be awesome if it did work for just certain subsystems instead of the whole system.