Automation triggers when rebooting Hass.io

I have the following simple automation:

- alias: 'Auto: Living room - Table - Lightswitch 2'
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: binary_sensor.xiaomidoorcontact5_contact
      to: 'on'
  condition:
    - condition: state
      entity_id: light.eettafel_lamp_1
      state: 'off'
  action:
    - service: light.turn_on
      entity_id: light.eettafel_lamp_1

This works as expected; the light turns on when some binary sensor turns On.
However, this automation also triggers when i reboot Hass.io while this sensor is True. This is not very nice.

Is this a known problem?
Has this to do with the integration this sensor is coming from (zigbee2mqtt)?
It seems like this sensor is initialized internally as False, and then gets its value from the physical sensor and triggers the automation.

I see the following information in my logbook:
8:07 PM Eettafel lamp 1 turned on
8:07 PM Auto: Living room - Table - Lightswitch 2 has been triggered
8:06 PM Auto: Living room - Table - Lightswitch 2 turned on
8:06 PM Home Assistant restarted

Help is appreciated. Thanks.

You can make your automation initial_state ‘off’ and create another automation on ha start with delayed action to turn the automation on.

That’s quite clever. Thank you.

I will try it tonight with the following automation:

- alias: "Automation: Delayed start of all automations"
  initial_state: 'on'
  trigger:
    platform: homeassistant
    # Event can also be 'shutdown'
    event: start
  action:
    - delay: '00:00:20'    # 20 seconds
    - service: automation.turn_on
      entity_id: all

I haven’t specified entity_ids for my automations, so I’ll try first with entity_id: all
If this doesn’t work I have to add ids for all automations that have to start delayed.

2 Likes
sensor:
  - platform: uptime
    name: "HA runtime in minutes"
    unit_of_measurement: minutes

automation:
  - alias: 'Auto: Living room - Table - Lightswitch 2'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: binary_sensor.xiaomidoorcontact5_contact
        to: 'on'
    condition:
      - condition: numeric_state
        entity_id: sensor.ha_runtime_in_minutes
        above: 1
      - condition: state
        entity_id: light.eettafel_lamp_1
        state: 'off'
    action:
      - service: light.turn_on
        entity_id: light.eettafel_lamp_1
2 Likes

Different solution for the same result. I will try this, thanks!

by the way, according to the docs, initial_state should be true or false :wink:

Hi everyone. How do I convert the uptime time stamp to minutes now? Looks like that does not work anymore