I have a sensor that provides the remaining remaining cook time in seconds; I can convert it to hours and minutes by setting up a sensor like this, but there must be an easier way, right?
Thanks, guys, I like them both - I adjusted @Didgeridrew’s version to this (again: probably NOT the most elegant way to adjust it, but some of us are more limited in their skills than others):
{% set seconds = states('sensor.cook_time_remaining') | float %}
{% set periods = { 3600: 'h', 60: 'min', 1: 'sec' } %}
{% set ns = namespace(seconds=seconds)%}
{%- for p_sec in periods.keys() %}
{%- if seconds >= p_sec -%}
{% set p_name = periods.get(p_sec) -%}
{% set period_value = ns.seconds | round(0) // p_sec -%}
{% set has_s = "" if period_value != 1 %}
{{- period_value ~""~ p_name ~ has_s~" "-}}
{% set dif = period_value * p_sec %}
{%- set ns.seconds = (ns.seconds - dif) | round(0) % p_sec %}
{%- endif%}
{%- endfor %}
Now I need to ask SWMBO which one better meets the WAF
I have a similar issue and I’m not able to get it to work as the OP did here. I’m trying to convert the seconds to minutes for my automation notification:
service: notify.mobile_app_my_phone
data:
message: >-
‼️ 🪫 UPS is {{ states("sensor.ups_status") }} with a load of
{{ states("sensor.ups_load") }}% and runtime of {{
states("sensor.ups_battery_runtime") }} minutes 🪫 ‼️
I’d like to convert the sensor.ups_battery_runtime to minutes