Automation for binary_sensor not working

Hi
I have an automation for a binary sensor to monitor the open/closed state of a door.
I want to send an alert when the door is opened.

I have the following automation:

- id: '1574713378816'
  alias: Alert Garage Door Open
  description: ''
  trigger:
  - entity_id: binary_sensor.garage_door
    from: Closed
    platform: state
    to: Open
  condition: []
  action:
  - data: {}
    service: notify.notify
- id: '1574713454665'
  alias: Alert Dining Room Door
  description: alert when door opened
  trigger:
  - entity_id: binary_sensor.dining_room_door
    from: Open
    platform: state
    to: Closed
  condition: []
  action:
  - data:
      message: The dining room door is open
      title: Your dining Door Friend 1
    service: notify.notify
  - data:
      message: The dining room door is open
      title: Your dining Door Friend
    service: persistent_notification.create

When I trigger the automation manually I receive the alert
When I open the door nothing happens.

When I monitor the state using Dev Tools I see the following:


    "event_type": "state_changed",
    "data": {
        "entity_id": "binary_sensor.dining_room_door",
        "old_state": {
            "entity_id": "binary_sensor.dining_room_door",
            "state": "off",
            "attributes": {
                "on": true,
                "temperature": 0,
                "friendly_name": "Dining Room Door",
                "device_class": "opening"
            },
            "last_changed": "2019-11-25T21:44:19.476163+00:00",
            "last_updated": "2019-11-25T21:44:19.476163+00:00",
            "context": {
                "id": "23fe996f0bb340f2a961b32458f41f7e",
                "parent_id": null,
                "user_id": null
            }
        },
        "new_state": {
            "entity_id": "binary_sensor.dining_room_door",
            "state": "on",
            "attributes": {
                "on": true,
                "temperature": 0,
                "friendly_name": "Dining Room Door",
                "device_class": "opening"
            },
            "last_changed": "2019-11-25T21:45:09.410702+00:00",
            "last_updated": "2019-11-25T21:45:09.410702+00:00",
            "context": {
                "id": "c3c611af9e4946cdb16b278f9484e356",
                "parent_id": null,
                "user_id": null
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2019-11-25T21:45:09.410829+00:00",
    "context": {
        "id": "c3c611af9e4946cdb16b278f9484e356",
        "parent_id": null,
        "user_id": null
    }

The state listener shows the state changing from “off” to “on” not “closed” to “open”
I’ve tried using off/on as well as closed/open in my automation - neither work.

Any suggestions please as to what is going on?

Also, when I view the sensor in deconz it shows it opening and closing. the state icon on the dashboard also changes from a black square to an open square when the door is open.

Look in Dev Tools/states for the state off binary_sensor.garage_door.
A binary_sensor can only be ‘on’ or ‘off’.

Along with what VDRainer said, you also have no service data for the first automation.

Also out state in single quotes like this 'on'

thanks, is then when using the hassio gui based automation editor, or when editting automations.yaml?

thanks, not sure where it went! :slight_smile:

Hi, thank.
I did try on and off but that does not work either

No they specifically said ‘off’ and ‘on’ not off and on

See the quotes ?

Here are the two automations combined into one:

- id: '8675309'
  alias: Alert Door
  description: alert when door opened
  trigger:
  - platform: state
    entity_id:
      - binary_sensor.dining_room_door
      - binary_sensor.garage_door
    from: 'off'
    to: 'on'
  action:
  - service: notify.notify
    data_template:
      message: The {{ trigger.to_state.name }} door is open.
      title: Your {{ trigger.to_state.name }} door
  - service: persistent_notification.create
    data_template:
      message: The {{ trigger.to_state.name }} door is open.
      title: Your {{ trigger.to_state.name }} door
1 Like

Thanks that fixed it - doing them individually did not seem to work but your script did :slight_smile:

1 Like

Then you need to figure out what you were doing wrong in your original automations. If you don’t it will come back to bite you later.

There is no reason that combining them into one automation performed any magic to cause them to work.