How to display historical values or “presence in minutes” in a widget?

Hi everyone,

I saw a widget in the community that displayed the presence of an item in minutes or hours, but I can’t find it anymore. I’m unsure how it was implemented.

I read that it might be possible to use lastChange, but I’m not certain how to use it correctly in a widget. Could someone clarify:

  1. Is it possible to display the time since the last change directly in a text widget?
  2. How can one evaluate historical values to show presence duration or uptime of an item and show it in a widget?

I’m using OpenHAB 5.1 with the Main UI. Any example or pointer to an existing widget would be very helpful.

Thanks a lot!

That may have been mine.

Only if you put that timestamp into a separate Item using a rule. Once it’s in an Item you just use a n expression.

To convert the timestamp to a nice readable phrase like the above use an expression on the widget’s label and dayjs.fromNow()

=dayjs(items.MotionSensor_LastMotion.state).fromNow()

See Widget Expressions & Variables | openHAB and Time from now · Day.js.

Note: A hardware failure has knocked my dad’s system offline and I’ve not fixed it yet.