Hi therre. I found a code snippet i thought i could change a bit, and reuse. But i get state unavailable i HA. Is there anyone who can point me in the right direction?
##Hente dag/kveld/helg strømpris
- platform: template
sensors:
nettleie_akt:
friendly_name: 'Aktuell nettleie'
value_template: >
{% set dag = states('sensor.ke_nettleie_dag') | float %}
{% set kveld = states('sensor.ke_nettleie_kveld_helg') | float %}
{% set hours = [[0,600,kveld],
[601,2200,dag],
[2201,2359,kveld]] %}
{% set t = states('sensor.time').replace(':','')|int %}
{% for h in hours if h[0] <= t <= h[1] %}
{{h[2]}}
{% endfor %}
If you’re getting “unavailable” it may be because you are missing defaults on your float and int filters or one of your referenced sensors could be undefined…
To debug this, use Developer Tools / Template, and paste the template code into there. It appears to just be selecting day and night rate: you might find this easier: