Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuySie/f1473eb20048b0c9b9da50c30a7a5f47 to your computer and use it in GitHub Desktop.
Save GuySie/f1473eb20048b0c9b9da50c30a7a5f47 to your computer and use it in GitHub Desktop.
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

Hi, I noticed your article on the HA Complication and tried to add this one. Not really a coder myself so I thought I just try asking you.
When copying this one in the Apple Watch complication part in the HA app it gives an error:
UndefinedError: 'None' has no attribute 'split'

Any idea what that could be?

The BuienAlarm Only doesn't give this error.

Thanks in advance.

Edit: never mind.. after restarting the HA app and copying again it doesn't give the error anymore ¯_(ツ)_/¯

@GuySie
Copy link
Author

GuySie commented Jul 28, 2021

Huh, that's strange! I haven't seen the sensor data result in None before. Could you replace the first line with this:
{%- if state_attr("sensor.neerslag_buienradar_regen_data","data") %}
And see if that helps? Not sure if it catches everything but it might help.

Also, can you check in the Developer Tools if your sensor sensor.neerslag_buienradar_regen_data gets data?

@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