Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Home Assistant Apple Watch Buienradar + Buienalarm Complication
{%- if state_attr("sensor.neerslag_buienradar_regen_data","data") != "" %}
{%- set buienradarraw = state_attr("sensor.neerslag_buienradar_regen_data","data").split(' ') %}
{%- set raindata = namespace(list=[]) -%}
{%- for n in buienradarraw -%}
{%- set raindata.list = raindata.list + [n[0:3]] %}
{%- endfor -%}
{%- for fifteenminutes in raindata.list|batch(3) %}
{%- if loop.index > 8 %}{{""}}
{%- else %}
{%- set rainvalue = fifteenminutes|max|int %}
{%- set rainintensity = 10**((rainvalue-109)/32) %}
{%- if rainintensity < 0.1 %}{{"▁"}}
{%- elif 0.1 <= rainintensity < 0.5 %}{{"▂"}}
{%- elif 0.5 <= rainintensity < 1 %}{{"▃"}}
{%- elif 1 <= rainintensity < 1.5 %}{{"▄"}}
{%- elif 1.5 <= rainintensity < 2 %}{{"▅"}}
{%- elif 2 <= rainintensity < 3.5 %}{{"▆"}}
{%- elif 3.5 <= rainintensity < 5 %}{{"▇"}}
{%- elif 5 <= rainintensity < 10 %}{{"█"}}
{%- else %}{{"▓"}}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- else %}
{%- set raindata = state_attr("sensor.neerslag_buienalarm_regen_data","data")["precip"] %}
{%- for fifteenminutes in raindata|batch(3) %}
{%- if loop.index > 8 %}{{""}}
{%- else %}
{%- set rainintensity = fifteenminutes|max %}
{%- if rainintensity < 0.1 %}{{"▁"}}
{%- elif 0.1 <= rainintensity < 0.5 %}{{"▂"}}
{%- elif 0.5 <= rainintensity < 1 %}{{"▃"}}
{%- elif 1 <= rainintensity < 1.5 %}{{"▄"}}
{%- elif 1.5 <= rainintensity < 2 %}{{"▅"}}
{%- elif 2 <= rainintensity < 3.5 %}{{"▆"}}
{%- elif 3.5 <= rainintensity < 5 %}{{"▇"}}
{%- elif 5 <= rainintensity < 10 %}{{"█"}}
{%- else %}{{"▓"}}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endif %}
@MrTeal
Copy link

MrTeal commented Jul 28, 2021

Thanks for the quick response, after closing the HA app and opening again and then copy pasting again it didn't give the error anymore. The chart works now 😊 Now we just have to wait for some rain. And maybe see if I can have HA generate a message for me when there is rain coming 🤔
Sensor does have data:
data: >-
000|11:05 000|11:10 000|11:15 000|11:20 000|11:25 000|11:30 000|11:35
000|11:40 000|11:45 000|11:50 000|11:55 000|12:00 000|12:05 000|12:10
000|12:15 000|12:20 000|12:25 000|12:30 000|12:35 000|12:40 000|12:45
000|12:50 000|12:55 000|13:00
friendly_name: neerslag_buienradar_regen_data
icon: mdi:weather-cloudy

Thanks for the help anyway!

@GuySie
Copy link
Author

GuySie commented Jul 28, 2021

Happy to hear it works now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment