Help Requested - Automation not triggering

I’ve made an alarm automation to notify myself if motion is detected or a door is opened at certain times, however it is not triggering. This is the config:

- id: '1558813254853'
  alias: Home Alarm
  trigger:
  - entity_id: binary_sensor.0x00158d00028ab3b7_occupancy
    platform: state
    to: 'on'
  - entity_id: binary_sensor.0x00158d0002c6698c_contact
    platform: state
    to: 'on'
  condition:
  - condition: time
    after: '00:00:00'
    before: '06:00:00'
  - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
    after: '08:00:00'
    before: '12:00:00'
  - condition: time
    weekday:
    - mon
    - tue
    - thu
    after: '12:00:00'
    before: '15:00:00'
  action:
  - data:
      message: Home alarm triggered!
    service: notify.mobile_app_phone'''

Any ideas what is wrong? I believe it must be something with the time condition as when I have an automation that removes the time condition it works fine.

first of all please enclose your code inside triple single quotes to preserve formatting as it’s crucial here.
I believe you can edit your post, no need to re-post.

I’ve edited the post for readability. I don’t get any HA errors when checking the log in the webUI, so the indentation should be OK I believe.

try do add

initial_state: true

to your automation as per docs.
also, I’m not quite sure about the action section, would prefer it like that:

action:
  service: notify.mobile_app_phone
  data:
    message: Home alarm triggered!

When you correct your code, also try to trigger it manually, i.e find in developers page and click on the Trigger switch to see it runs at all.
Also, it might be easier to start with no/less conditions and then gradually add them checking if it still works.

Try drawing your timings on top of a clock on paper. Your conditions will never evaluate true.

Those are checked with AND in mind. If you wanted it to be OR check here: https://www.home-assistant.io/docs/scripts/conditions/#or-condition

1 Like

Thanks for bringing that up, I didn’t realize they were && and not ||

1 Like

well, “Unlike a trigger, which is always or , conditions are and by default - all conditions have to be true.”