Create an automation based on state change of cover that uses MQTT

I’m trying to have Home Assistant notify me when my garage door opens and I’m not at home.
My garage door configuration is a Cover using the MQTT platform. It’s a reed switch that connects to a Shelly relay that controls the garage door opener. Here’s the cover:

# Garage Door
cover:
  - platform: mqtt
    name: "Garage Door"
    position_topic: "shellies/shelly1-garage/input/0"
    command_topic: "shellies/shelly1-garage/relay/0/command"
    availability_topic: "shellies/shelly1-garage/online"
    retain: false
    payload_open: "on"
    payload_close: "on"
    payload_stop: "on"
    position_open: 0
    position_closed: 1
    payload_available: "true"
    payload_not_available: "false"

Everything so far works. I have a Lovelace button that changes colors based on the state of the cover.

This is what I’ve tried in the Automation GUI:

Here’s the raw automation output:

- id: '1636145538565'
  alias: Garage Notification
  description: Notify me when the garage door changes and I'm not home
  trigger:
  - platform: state
    entity_id: cover.garage_door
    from: '0'
    to: '1'
    attribute: current_position
  condition: []
  action:
  - service: notify.mobile_app_pixel_4_xl
    data:
      message: Garage Door Opened
  mode: single

Because the cover is using the MQTT platform, do I need to do this a different way?

A cover’s states are open and closed. You can confirm that by inspecting the state value of cover.garage_door in Developer Tools > States.

To constrain the automation to notify you only when you are not home, you need to include a condition that checks your current status. In the following example, I used a device_tracker but you will need to replace it with whatever entity you are currently using to indicate if you are home or not.

- id: '1636145538565'
  alias: Garage Notification
  description: Notify me when the garage door changes and I'm not home
  trigger:
  - platform: state
    entity_id: cover.garage_door
    from: 'closed'
    to: 'open'
  condition:
  - condition: state
    entity_id: device_tracker.your_device_tracker
    state: 'not_home'
action:
  - service: notify.mobile_app_pixel_4_xl
    data:
      message: Garage Door Opened
  mode: single

Aha! That works!

I omitted the condition because I was trying to rule out anything that could have been preventing this from working. This is my final automation that works:

- id: '1636145538565'
  alias: Garage Notification
  description: Notify me when the garage door changes and I'm not home
  trigger:
  - platform: state
    entity_id: cover.garage_door
    from: closed
    to: open
  condition:
  - condition: not
    conditions:
    - condition: zone
      entity_id: device_tracker.pixel_4_xl
      zone: zone.home
  action:
  - service: notify.mobile_app_pixel_4_xl
    data:
      message: Garage Door Opened
  mode: single

BTW @123 you helped me with another issue with this cover I had 7 months ago. Maybe I should just call you directly next time :slight_smile: