Automations: Binary sensor not always triggers

Hi guys,
I’m new with Hassio and I’m facing some problems to understand why automations not always trigger.
Just looked all over this forum but found no explanation so I hope someone can clarify this.

It’s a simple automation triggered by the state of an Binary_sensor, but not always runs.

- alias: 'abre_portao_garagem'
  initial_state: false
  trigger:
  - platform: state
    entity_id: binary_sensor.hikvision_events_line_crossing_1
    from: 'off'
    to: 'on'
  condition:
  - condition: sun
    after: sunset
  action:
  - service: switch.turn_on
    entity_id: switch.portao_garagem
  mode: single

From the Developer Tools we can see that the Binary_sensor as been tripped today, but the automation didn’t ran.
Yesterday worked correctly and it’s this behaviour that I don’t understand.

Any suggestion?
Thanks

The formatting/indentation is wrong, so it’s hard to tell what’s going on. Can you please repost after hitting the </> in the edit box to retain formatting?

The automation is off (disabled). Turn it on and change initial_state: false in the automation to initial_state: true.

2 Likes

Already corrected the post.
The code must be correct cause sometimes it works.

Hi Tediore.

Thanks for the reply.
The initial_state it’s to enable the automation the startup of the system?
I thought it was to trigger it at the startup. Now I understand.

Correct. Here is the relevant part of the documentation explaining it: Automation - Home Assistant

I completely missed that :slight_smile: . Good catch!