Binary Sensor not triggering automation

Hello All!

I have a reed sensor that I’m using to detect when my doorbell gets pressed. This shows up as a binary sensor in HA and is normally open.
When watching in the states ui and the developer states page, I can see the sensor changing states from ‘open’ to ‘closed’ and quickly back again (when the doorbell button is pressed).
This is merely to explain that this part is working.

I have an automation setup to trigger a notification when the state changes from open to closed.
below is my config:

#################
#Doorbell Notify#
#################
- id: doorbell_notify
  alias: Doorbell Notify
  initial_state: true
  trigger:
  - platform: state
    entity_id: binary_sensor.doorbell
    from: Open
    to: Closed
  - platform: state
    entity_id: binary_sensor.doorbell
    from: Closed
    to: Open
  condition:
  - condition: time
    after: '06:30:00'
    before: '22:00:00'
  action:
  - service: notify.husband
    data:
      title: doorbell rang
      message: someone is at the door
  - data:
      entity_id: switch.doorbell_notify
    service: switch.turn_on
  - delay:
      seconds: '5'
  - data:
      entity_id: switch.doorbell_notifiy
    service: switch.turn_off

A couple things to note regarding the above yaml

  1. the two triggers were to try and capture either of the state changes since they happen so quickly (might not matter, but I’ve tried).
    I’ve tried just from open to closed and from closed to open separately. Neither triggers work.

  2. the capital letters Open and Closed are how it shows up in my states UI. I’ve tried them as lowercase as well and this also didn’t trigger the automation. I’ve also tried them inside single quotation marks ie ‘open’ and ‘closed’ and ‘Open’ and ‘Closed’
    Also note that I’ve tried “to: Closed” without the “from”

to: Closed

  1. in case you are wondering about the switch that turns on, delays and then turns off. This is a virtual switch through my isy994i changes an isy variable that in turn triggers an Alexa routine. This is my Alexa workaround since I paid for the network portal for the isy before I began using Home Assistant. This works fine when manually triggering the virtual switch in Lovelace.

I’ve searched some other topics regarding this and it usually seems to be a yaml error. As you can see I’ve tried numerous permutations of the trigger and none seem to work.

The state change from open to closed and back to open happens super quickly, but I would think that HA would still register the change and trigger the automation.

Anyone see an error that I’m missing? or something else entirely?

edit: for clarity

A binary_sensor’s two states are on and off. Go to Home Assistant’s States page, locate binary_sensor.doorbell and you’ll see its current state is either on or off.

Your automation is using Open and Closed and will never be triggered by the binary_sensor.

Screenshot%20from%202019-05-24%2016-22-16

Also, I think your Before and After time Conditions may need tweaking, I seem to remember that they need to be split into two separate OR conditions. Try removing them for now for testing purposes.

This worked! Man I feel silly. When you click the entity to get the more info dialog it uses the open and closed terminology. Ugh.
I did have to put them in single quotes for the configuration to be correct… In case anyone else has this issue

Well it’s working now. Thank you so much.

1 Like

When commented out, the automation is working. I have other conditions with before and after exactly like this so I’m hoping it will work but if not, you’ve given me a great place to start troubleshooting.

Going outside to enjoy the sun with my kids. Can’t sit in front of the screen all afternoon.
Thanks for responding!

That’s a given for non-numeric values that have a special meaning within Home Assistant.

For when it starts raining and you’re back in front of the computer, this is a sample of one of my conditions with the time range:

  condition: 
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.smart_lights
        state: 'on'
      - condition: state
        entity_id: group.all_devices
        state: 'home'
      - condition: or
        conditions:
          - condition: time
            before: '02:00:00'
          - condition: time
            after: '18:00:00'

The time conditions here mean from 6pm to midnight, and then midnight to 2am. Awkward, but this works. You can’t use AND for a time condition like this because the two conditions will never both be before midnight and after midnight, if you get me.

Overall, this condition block means “only if the smartlights setting is turned on, and only if someone is home, and only between 6pm and 2am”

That’s a given for non-numeric values that have [a special meaning within Home Assistant]

Thank you… That’s a great link. I always just experiment with and without quotes with any values. Still trying to figure out all the hard and fast rules.

Thanks I’ll try this!