This is a quick and dirty cut/paste from an old ESPHome project that I never got around to writing up. It monitored several sensors and controlled a hydroponics system.
The specific snip above creates a text string that is published back to Home Assistant.
Hopefully it should be pretty easy to figure out what's going on.
The time remaining depended on several factors and could change arbitrarily.
For this reason, I found it much simpler to update the time remaining sensor from other entities/components which is why the update_inteerval
is never.