I’ve got a doorbell running on an ESP8266 playing a MP3 when someone rings. It also sends a message to openhab by changing an item (date-time last pressed). Of course I want it on my wall mounted tablet showing this time with an icon. And to grab attention I want a green icon when it was pressed today, else gray. I’m using dayjs for that. So far so good.
Problem was updating, since the item actually doesn’t change (until someone presses the doorbell again) my widget wasn’t updated and stays green forever. I solved this by using a trick I found for updating graphs. This required a changing item that you use in the key of a f7-card config. I’ve also added this to the formula of the color of the icon. Completely useless condition because its always true but it forces the widget formula to update and now the icon will turn grey.
My question is … it seems a strange workaround. Maybe there is a more logic/easy solution to this problem?
Below the code. The “LaatstGebeld” item contains the date-time the button was last pressed. Using dayjs I check if this is after the start of the current day. If so, color is green else gray. Works perfect but isn’t updated. So I included a fake condition on the “timertick” item (a rule changes it value every 15 minutes for updating graphs in my other widgets). And this makes it work, now (I presume) every 15 minutes it checks the condition and changes the color of the icon accordingly.
- component: oh-icon config: color: '= items.timertick.state>=0 && dayjs(items.LaatstGebeld.state).isAfter(dayjs().startOf("d")) ? (props.iconColor ? props.iconColor : "green") : "gray"' icon: '=props.mainIcon ? props.mainIcon : "f7:bell_fill"'