HA startup trigger, a novel approach

I have had difficulty using

  trigger:
    platform: homeassistant
    event: start

for triggering automation. I found this works with the sun.sun entity.

  trigger:
    - platform: state
      entity_id: sun.sun
      to: 'above_horizon'
    - platform: state
      entity_id: sun.sun
      to: 'below_horizon'

is this some kind of workaround for HA startup Automation issue? won’t it trigger again when HA is running and state of sun.sun change to above_horizon?

Of course, I wasn’t thinking, this won’t work for restart trigger alternative. I will experiment with from ‘unknown’ perhaps with another sensor. Thanks

I corrected my restart trigger replacement by turning off the automation at the end of the action so not to be triggered again until next restart. In fact, you can use anything to trigger like time as long as you shut off the automation in the action.

automation restart:
  alias: restart
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: sun.sun
      to: 'above_horizon'
    - platform: state
      entity_id: sun.sun
      to: 'below_horizon'
  action:
    - delay: 00:00:05
    - service: logbook.log
      data_template:
        name: Restart
        message: Restart replacement has been triggered
    - service: automation.turn_off
      entity_id: automation.restart
1 Like

it works. thanks we can use this… until there is a fix for it.

Good workaround, thanks.

Btw, you can turn off the automation as the first action too. Putting it first doesn’t stop the rest of the actions from running, it just disables the triggers.

Doesn’t matter in this case (unless the sun changes state again within five seconds) but for other triggers it might.

I changed the trigger to the initial state of the automation for simplicity.