I have a water leak sensor whose details I want to display in a label in a Sitemap for the openHAB mobile app. It is essentially an on/off switch for the water detection alarm.
Currently the label is linked to the item and defined with the label:
Water leak sensor: [%s]
The values are mapped as OFF=Normal operation and ON=Flood alarm
All good so far, but I’d like to also display the timestamp when that value was last changed, like “Flood alarm since 16:29 on 8.11.2025”. It would be more informative this way.
The problem is that I have no clue how this can be done. From my own searches, it seems that the timestamp should be part of an item’s possible attributes. But how exactly do I reference them and format the output nicely? Also, does this require a functioning persistence mechanism?
openHAB 5.0.2 from official Docker container, includes Java and all that, the host OS is Ubuntu on a mini PC but that should be irrelevant for the container.
Put this item underneath your current Water leak sensor: [%s] and only make it visible when Water leak sensor is ON, and keep it invisible when it’s OFF.
Interesting approach, thanks for the idea. It’s not very elegant though - I’d need to have either two triggers with two scripts or one trigger with a conditional branch to define the text for ON and OFF values. And that’s only for this one sensor; it becomes tedious when this concept needs to be scalable over 6+ water leak sensors, and then on any other switch for which a timestamp makes sense - smoke sensors, garden watering, heatpump operating status, and so on. There has to be a smarter way than creating second items/variables/scripts for each and every item to be monitored.
Sitemaps do not have access to anything more than the state of the item. If you want to display a timestamp, that timestamp must be in a separate DateTime Item.
But there are lots of options available to populate that DateTime Item. A rule is just one option. Though you can handle all your sensors with one simple rule, no conditionals required.
For example:
put all the sensor items into a Group
trigger the rule when any member of the Group changes to ON
name the corresponding DateTime Item the same as the sensor Item. With “_LastOn” or whatever you prefer.
The body of the rule in JS would be something like this:
In any other language, including Blockly, the code would also just be a one liner.
But you can also use the timestamp profile. See Items | openHAB. But the timestamp profiles will update the timestamp for any change, not just changes to ON.
To define the text for the ON/OFF baked you should use a Map transformation on the label. You don’t need a time fir that. See Items | openHAB