Skip to content

Home Assistant Automation

Example Home Assistant automation to send notifications when an MQTT update is received.

This uses Supernotify to respect priorities and make multiple notifications for the same event - in the live example this includes Mobile Push alerts, email (with the snapshot ANPR image as an attachment), chimes ( hunting horn for known vehicles, doorbell chimes for unknown ) and Alexa spoken announcements.

It can be adapted to a plain notification by removing the data section and changing the action. Modern Home Assistant UI allows pasting in yaml to create automations.

alias: Driveway ANPR Alert
description: ""
triggers:
  - trigger: state
    entity_id:
      - sensor.anpr_driveway
conditions: []
actions:
  - action: notify.supernotify
    metadata: {}
    data:
      message: >-
        {{ trigger.to_state.attributes.description }} with {{
        trigger.to_state.attributes.plate }} spotted at {{
        trigger.to_state.attributes.camera }} camera, moving {{
        trigger.to_state.attributes.vehicle_direction }}

        {% if trigger.to_state.attributes.previous_sightings == 0 %} Not
        previously sighted  {% else %}  with {{
        trigger.to_state.attributes.previous_sightings }} previous sightings. {%
        endif %} {% if trigger.to_state.attributes.last_sighting is defined %}
        last seen on {{ trigger.to_state.attributes.last_sighting[:10] }} at {{
        trigger.to_state.attributes.last_sighting[11:16] }}   {% endif %}

        {% if trigger.to_state.attributes.reginfo is defined %}  DVLA info: {{
        trigger.to_state.attributes.reginfo }}   {% endif %}
      title: >-
        {{ trigger.to_state.attributes.description }} spotted on {{
        trigger.to_state.attributes.camera }} camera
      data:
        priority: "{{ trigger.to_state.attributes.priority }}"
        apply_scenarios: >-
          {% if trigger.to_state.attributes.known %}known_vehicle{% else
          %}unknown_vehicle{% endif %}
        constrain_scenarios:
          - known_vehicle
          - unknown_vehicle
        media:
          camera_entity_id: image.anpr_{{trigger.to_state.attributes.camera}}
          snapshot_url: "{{ trigger.to_state.attributes.event_image_url }}"
mode: single