xlcnd / meteoalarmeu

A 'custom component' for Home-Assistant for Weather Warnings from meteoalarm.eu
GNU General Public License v3.0
20 stars 3 forks source link

Automation to create Persistent Notifications (PN) based on the alerts #13

Closed xlcnd closed 3 years ago

xlcnd commented 3 years ago
- alias: Alert me about weather warnings
  trigger:
  - platform: state
    entity_id: binary_sensor.meteoalarmeu
    attribute: message_id
  condition:
  - condition: state
    entity_id: binary_sensor.meteoalarmeu
    state: 'on'
  action:
  - repeat:
      count: "{{ state_attr('binary_sensor.meteoalarmeu', 'alerts') | int }}"
      sequence:
      - service: persistent_notification.create
        data:
          title: >
            {% set ext = "" if repeat.first else "_" + (repeat.index-1)|string %}
            {{ state_attr('binary_sensor.meteoalarmeu', 'awareness_type' + ext) }} ({{ state_attr('binary_sensor.meteoalarmeu', 'awareness_level' + ext) }})
          message: >
            {% set ext = "" if repeat.first else "_" + (repeat.index-1)|string %}
            {{ state_attr('binary_sensor.meteoalarmeu', 'message' + ext) }}

            Effective from **{{ state_attr('binary_sensor.meteoalarmeu', 'from' + ext) }}** until **{{ state_attr('binary_sensor.meteoalarmeu', 'until' + ext) }}**
          notification_id: >
            {% set ext = "" if repeat.first else "_" + (repeat.index-1)|string %}
            meteoalarm_{{ state_attr('binary_sensor.meteoalarmeu', 'alert_id' + ext) }}

- alias: Update weather warnings (special cases)
  trigger:
  - platform: homeassistant
    event: start
  - platform: state
    entity_id: binary_sensor.meteoalarmeu
    to: unavailable
    for: 00:10:00
  action:
  - service: homeassistant.update_entity
    entity_id: binary_sensor.meteoalarmeu