Why wont my automation notify on door closed?

I cant figure out why my automation will not notify when door closed. Can anyone offer any suggestions?

- id: '1683001364190'
  alias: Broadcast Door open close
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.family_room_slider
    - binary_sensor.garage_backdoor
    - binary_sensor.garage_door
    - binary_sensor.garage_side_door
    to: 'on'
    from: 'off'
  condition: []
  action:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.broadcast_speakers
      volume_level: 1
  - service: tts.cloud_say
    entity_id: media_player.broadcast_speakers
    data_template:
      message: '{{ trigger.to_state.attributes.friendly_name }} {% if trigger.to_state.state
        == ''on'' %} Open {% else %} Closed {% endif %}'
  - service: notify.mobile_app_iphone
    data:
      title: Door Change
      message: '{{ trigger.to_state.attributes.friendly_name }} {% if trigger.to_state.state
        == ''on'' %} Open {% else %} Closed {% endif %}'
      data:
        push:
          interruption-level: time-sensitive
  mode: single

Your automation’s State Trigger is configured to trigger only when any of the listed binary_sensors change state from off to on which means when the door opens. When a door closes (state-change from on to off) the State Trigger ignores it.

Change the State Trigger to this:

  - platform: state
    entity_id:
    - binary_sensor.family_room_slider
    - binary_sensor.garage_backdoor
    - binary_sensor.garage_door
    - binary_sensor.garage_side_door
    to:
    - 'on'
    - 'off'
    from:
    - 'off'
    - 'on'

Or just:

  - platform: state
    entity_id:
    - binary_sensor.family_room_slider
    - binary_sensor.garage_backdoor
    - binary_sensor.garage_door
    - binary_sensor.garage_side_door
    to:

For any state change.

I believe that will trigger for state-changes to/from unavailable. Given the automation’s current design, it’ll erroneously report “Closed” when there’s a state-change from on to unavailable.

Easy fix

  - service: tts.cloud_say
    entity_id: media_player.broadcast_speakers
    data_template:
      message: '{{ trigger.to_state.name }} is {{ trigger.to_state.state|title }}'

If imv8n wants the automation to announce all of the door’s possible states, including if it becomes unavailable, that’s the recommended way to do it.

There may also be a seemingly odd announcement if the state-change is from unavailable to on or off. The announcement will report the door’s new state even if the door never physically moved to get to that state.

This is how I had it originally however the zigbee door sensors, I assume would briefly lose connectivtiy at some point and in the middle of the night I would get announcements that a door was closed. My assumpition is that the sensor went from unavailabale to closed.

@123 Works great. Thanks very much!

1 Like