Automation Condition Not Working (Ignored)

Hi Everyone,

I have a very simple automation that is designed to notify me via SMS notification if my garage door is open at 11:00pm. For some reason, no matter what I do, the condition is ignored and I always get the notification. And, no I am NOT manually triggering this, so I am expecting the condition to be evaluated. I have tried using a separate condition, or embedding the condition directly into the action, as the below show. No matter what I do, the problem persists. I have checked the state of the object and it seems fine and the correct value is in the condition for evaluation. Nothing is in the logs, so those are not much help. I am assuming that when HA goes to evaluate the condition, it is returning true, which doesn’t make sense. Please help, this has been going on for months and now I have finally had a chance to investigate and experiment.

- id: '1577286579874'
  alias: Notify - Garage Open at Night
  description: ''
  trigger:
  - at: '23:00'
    platform: time
  condition: []
  action:
  - condition: state
    entity_id: binary_sensor.vision_zg8101_garage_door_detector_sensor
    state: 'on'
  - data:
      message: 'Home: Garage Door is Open at Night'
      target: '+16471234567'
    service: notify.home_notifier

The above code is from my automations.yaml file, but it was configured through the UI.

Any help would be appreciated. Thanks.

The way your automation is currently set up the action will be triggered every time at 11pm because there is no condition, it’s blank [ ]. Whereas the condition in your automation’s action would stop execution if it were in a script it may just be ignored in an automation action. Put the condition where it should be up in the blank condition area.

the condition in an automation action works perfectly fine.

It’s unconventional but it should work.

the actions in an automation are the same as the steps in a script. The difference between an automation & script is the automation has a trigger and a separate condition section.

That said, I’m not sure why the condition isn’t being respected (no matter where you put it). It looks OK to me. The only thing that it could possibly be is the state of the binary_sensor isn’t what you expect but you said you verified it so I don’t have any idea why it isn’t working as expected.

Take the blank condition out.

An added thought. Since you said you verified the binary_sensor state, make sure you have spelled the object_id correctly. I have seen times where a misspelled entity_id resulted in incorrect behavior.

First, the “blank” condition isn’t a problem. It’s just an empty list, so there’s nothing for it to check.

Next, as mentioned already, it’s perfectly fine to use a condition step in the action section. Scripts, and the action section of an automation, are executed by the exact same code, so they work identically.

Next, you said you’re not “manually” triggering it, so I assume you’re not hitting the TRIGGER button in the “more info” window for the automation, correct? Does this also mean you’re not calling the automation.trigger service?

Havind said that, it probably shouldn’t matter since your condition is in the action section. In fact, you should be able to test this automation using either of those techniques. It should run the actions, including checking your condition step, no matter how the automation is “triggered.”

As far as the log being no help, that’s not true. If you look in home-assistant.log, there should be entries there stating the automation was triggered, as it’s executing each step, including stating whether or not the condition evaluated to true. Depending on how you have logger configured you may want to at least temporarily change that to something like:

logger:
  default: info
  logs:
    homeassistant.core: debug
    homeassistant.components.automation: debug

Then restart HA and manually trigger the automation. Then look in home-assistant.log. There will be entries indicating the state of the binary sensor (i.e., when it changes – look for state_changed events – and what its new value is), as well as details about how the automation ran. If you need help interpretting the log, let me know.

Thank you very much for your reply. It’s weird, but when I enabled logging I got the desired result whether I invoked the trigger manually, or setup a trigger and waited for the execution. The log file showed the following:

2020-06-02 23:52:00 INFO (MainThread) [homeassistant.components.automation] Executing Notify - Garage Open at Night
2020-06-02 23:52:00 INFO (MainThread) [homeassistant.components.automation] Notify - Garage Open at Night: Running script
2020-06-02 23:52:00 INFO (MainThread) [homeassistant.components.automation] Notify - Garage Open at Night: Test condition state: False

Tomorrow I will remove the logger configuration and see if the problem returns.

THANKS FOR YOUR RESPONSES AND ASSISTANCE. Much appreciated.