A timer/sensor with the state of hours & minutes, but ONLY show hours if there are hours

I feel the answer is in here, I’m just not able to find it and be able to use it in my use case, or my head is just fried from looking. I’m struggling with templates, but I’ve been able to get about 90% of what I’m trying to accomplish. The last puzzle piece involves a sensor that gets a MQTT topic from Octoprint with a payload of ‘seconds.’ I’ve been able to convert this into a new sensor that shows hours & minutes with the following:

{{ states('sensor.octoprint_print_time_left') | int | timestamp_custom('%-H hours and %-M minutes', false)}}

I use this sensor for Alexa to read the state of and tell me how much time is left on a 3D print. The final piece I’m trying to do is to have the state of the sensor show ‘hours’ ONLY IF there are hours calculated from the MQTT/Octoprint ‘seconds’ sensor. For example: have it show ‘30 minutes’ instead of ‘0 hours and 30 minutes.’ when the sensor is at 1800 seconds. But still show ‘2 hours and 30 minutes’ if the sensor is at 9000 seconds.

It’s a small detail, but will help my brain quickly comprehend the time remaining. Thank you taking the time to look at this topic.

Mike

@pedolsky Whoa! Yeah, that was way over my head! But it got me where I wanted to go. It originally was giving the wrong hour times but I figured out how to fix it. Thank You VERY much!

I don’t know if you noticed but the title of the linked post explains how to make Hunan-style History Stats. :wink:

Hunanizing History Stats
1 Like

FYI

The author of that macro, petro, has also created a library of useful macros called Easy Time Macros.

@123 That could be why i missed it, I’m not a hunan (i think). But even if i did look at that post, I’m not sure i would have been able to digest it at my level.

Thanks for alerting me to those time macros. This looks very interesting.