Hi, I have OH5 on RPi and I’m using Satel binding to read statuses from PIR sensors. One thing I do is storing the latest date and time each PIR was triggered. I have added this item into semantic model and I can see the date and time - it’s all great.
Now I would love to do two things:
modify the Main UI item entry script (it’s oh-list-item I guess?) so that the font or background color turns to red it the displayed time is within last 5 minutes, blue if last hour and no color if older,
second thing is adding another item that would simply display the number of minutes betwen “now” and the date+time stored in the item above.
What script and where to put it to achieve the two goals?
Choose and configure the widget as you wish. Siick to the widgets with “item” in the name (e.g. oh-label-item)
It’s not super easy to set the background color nor the text color (you have to dig into the lower level CSS properties to do that) so often the easiest is to use a badge or color the icon. You can add a badge and badgeColor and if you choose any icon except for the OH icons (e.g. f7, material, iconofy) you can have the icon and the color change.
Custom list item widget could look like this:
(Developer tools > Widgets > Create new widget and paste the code from here)
uid: list-colored-time-item
tags: []
props:
parameters:
- description: A label
label: Label
name: label
required: false
type: TEXT
- context: item
description: An item to display
label: Item
name: item
required: false
type: TEXT
filterCriteria:
- value: DateTime
name: type
- value: "true"
name: filterToggle
- default: "false"
description: Show difference instead of state
label: Show diff
name: showDiff
required: false
type: BOOLEAN
parameterGroups: []
timestamp: Feb 11, 2026, 9:03:05 PM
component: oh-label-item
config:
icon: f7:clock
title: =props.label
after: "=props.showDiff?dayjs(items[props.item].state).fromNow(true):
dayjs(items[props.item].state).format('ddd h:mm:ss')"
style:
background: "=dayjs().diff(dayjs(items[props.item].state),'minutes') < 5
?'red':dayjs().diff(dayjs(items[props.item].state),'minutes') < 60
?'blue': ''"
You can then use the same widget and same Item for displaying “last motion time” or “time since last motion” just by enabling “showDiff” property in widget configuration.
If you want to have colored text instead of background then change style background property to color