Hi!
I’ve tried to make custom sensors to calculate the time till the next sun event (sunset or sunrise).
The first part I have managed to do with custom sensors, but to show it in my lovelace-dashboard I wanted it to be more human-readable.
This is where I had problems. The code I tried writing keeps giving me this error:
TemplateError(‘TypeError: unsupported operand type(s) for /: ‘str’ and ‘int’’) while processing template
The code I’m trying to use is this pasted below.
sensor.next_sun_event_sec is the previously mentioned template sensor.
- platform: template
sensors:
next_sun_event_human:
friendly_name: "Neste solhendelse"
unique_id: "next_sun_event_human"
value_template: >-
{% if states('sensor.next_sun_event_sec') | float > 3600 %}
{{ float(states('sensor.next_sun_event_sec') / 3600) | round(0) }}
{% elif states('sensor.next_sun_event_sec') | float > 60 %}
{{ float(states('sensor.next_sun_event_sec') / 60) | round(0) }}
{% else %}
{{ float(states('sensor.next_sun_event_sec')) | round(1) }}
{% endif %}
I am kinda stuck in my own ways here, so help with this code or suggestions to do it other ways are appreciated.