DPC alerts - Italian Civil Protection Department Weather Alerts
Home Assistant

DPC alerts - Italian Civil Protection Department Weather Alerts

An awtrix light automation to display weather alerts provided by the Italian Civil Protection Department (Dipartimento Protezione Civile)
A flow by Icchan

Go to automations Download flow Download assets

Flow Details

Prerequisites:

Please make sure you have this integration installed and configured: Home Assistant - Custom Components DPC Alert. Remember to change the topic in mqtt.publish service according to your topic on the flow.

Icons:

Idraulico: 63
Idrogeologico: 2661
Temporali: 11428

How it works:

The text color will change according to the alert color (yellow, orange, red). It will display alerts for the current day and the day after as soon as they are available. Alerts are shown on Awtrix light only if there is an active alert.

More info:

To get more detailed information about parameters of warnings visit Civil Protection Department or Dipartimento Protezione Civile (in Italian)

Updates:

  • 29/02/2024: Fixed events not being deleted after new event took place.
  • 14/02/2024: Fixed loop not working as expected. It was hard, but I won. 😎
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
alias: Awtrix App - DPC Alert
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.dpc_idrogeologico_oggi
      - binary_sensor.dpc_idraulico_oggi
      - binary_sensor.dpc_temporali_oggi
      - binary_sensor.dpc_idrogeologico_domani
      - binary_sensor.dpc_idraulico_domani
      - binary_sensor.dpc_temporali_domani
condition:
  - condition: template
    value_template: >-
      {{ trigger.to_state.state == 'on' and (trigger.from_state.state == 'off'
      or (trigger.to_state.attributes != trigger.from_state.attributes))}}
action:
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: awtrix_xxx/custom/dpc_alert
  - variables:
      payload_apps: >
        {%- set entity = 'sensor.dpc_alert' -%}   {%- set days_map =
        {'today':'Oggi','tomorrow':'Domani'} -%}  {%- set alert_color =
        {0:"#FFFFFF", 1:'#00FF00', 2:'#ffff00', 3:'#ffa500', 4:'#ff0000'}
        -%}        {%- set risk_icon =
        {'Temporali':'11428','Idraulico':'63','Idrogeologico':'2661'} -%}
        {%- set ns = namespace(data=false) -%}{%- set events_today =
        state_attr(entity, 'events_today') -%} 
          {%- if events_today -%} 
            {%- for ev in events_today if events_today is defined -%}
            {%- set evloop = loop -%}
            {%- if ev -%}
            {%- set ns.data = true -%}
            {
                "icon": "{{ risk_icon.get(ev['risk']) }}",
                "text": 
                  [
                    {
                      "t": "Oggi {{ ev['alert']}} ({{ ev['risk'] }})",
                      "c": "{{ alert_color.get(ev['level']) }}"
                    }
                  ]
              }
            {%- endif  -%}
            {%- if not evloop.last -%},{%- endif -%}
            {%- endfor -%}
          {%- endif -%}
        {%- set events_tomorrow = state_attr(entity, 'events_tomorrow') -%} 
          {%- if events_tomorrow -%} 
            {%- for ev in events_tomorrow if events_tomorrow is defined -%}
            {%- set evloop = loop -%}
            {%- if ev -%}
            {%- if ns.data == true -%},{%- endif %}
            {%- set ns.data = true -%}
              {
                "icon": "{{ risk_icon.get(ev['risk']) }}",
                "text": 
                  [
                    {
                      "t": "Domani {{ ev['alert']}} ({{ ev['risk'] }})",
                      "c": "{{ alert_color.get(ev['level']) }}"
                    }
                  ]
              }
            {%- endif -%}
            {%- endfor -%}
          {%- endif -%}
      payload: |
        {%- if payload_apps -%}
          [
            {{ payload_apps }}
          ]
        {%- else -%}
         {}
        {%- endif -%}
  - service: mqtt.publish
    data:
      qos: 0
      retain: false
      topic: awtrix_xxx/custom/dpc_alert
      payload: |
        {{ payload | tojson }}
mode: queued
max_exceeded: silent
max: 10
/flows/PegMAVG8ov3p/ezgif-6-7f66697f0f.gif
-- Flow first published on February 10, 2024, last updated on March 3, 2024 at 15:52.