Variable within Alert

Hi,

I made a simple alert to tell me if I left the garage door open - however as soon as I add the variable, it fails to work at all - is there a way to add in here to say how long it was open in the alert?

  garage_door:
    name: Garage is open
    message: "The garage door is still open {{ trigger.for }}"
    done_message: Garage is closed
    entity_id: binary_sensor.garage_door_sensor_contact
    state: "on"
    repeat: 1
    can_acknowledge: true
    skip_first: false
    notifiers:
      - all_mobile_devices

Alert messages do support templates, however as alerts are not automations so they dont support trigger variables. You will have to get the time open another way. Try this:

message: "The garage door has been open for {{ ( ( as_timestamp( now() ) - as_timestamp( states.binary_sensor.garage_door_sensor_contact.last_changed ) ) /60 )|round(1) }} minutes."

Thank you so much Tom, that works perfectly!

1 Like