Automations triggered if HA starts

Hey,

i have an automation like a master/slave-powerstrip. If i turn my PC on, the monitors turned on automatically and get the state “on”. After restarting HA, the monitors getting the state “off”. But the automation is configured (i think), that they will be turned on if the pc has the state “on”, so the automation should be triggered.
Here is my automation:

alias: "Auto-on Monitor"
trigger:
  platform: state
  entity_id: switch.pc
  state: "on"
action:
  service: homeassistant.turn_on
  entity_id:
    - switch.monitore

Does anyone has a solution for this? Thanks!

Maybe you can look at the state from off to on, instead of just looking for on:

trigger:
  platform: state
  entity_id: switch.pc
  from: 'off'
  to: "on"
action:
  service: homeassistant.turn_on
  entity_id:
    - switch.monitore

Hey,

thanks for the reply. Unfortunately it doesn`t work. I tried the “to”-option before and added now the “from”-option, but still no success

Okay. Another way of dealing with this is making your automation be off by default and making the PC being on enable it:

- alias: "Auto-on Monitor"
  initial_state: 'off'

Next you can use HA to enable the automation when the PC goes on:

- alias "Enable Automation"
  trigger:
    platform: state
    entity_id: switch.pc
    state: "on:
  action:
    service: homeassistant.turn_on
    entity_id: automation.Auto-on_Monitor

Still no success. Even the “Auto-on Monitor” stays off on restart.

If you’re on the latest code, you’ll need to use service: homeassistant and event: start, instead of service: homeassistant_start. See: https://home-assistant.io/docs/automation/trigger/

That said, seems like the new way isn’t working very well either at the moment.

In the developer tools does the switch.pc change state when you turn it off and on?

No, it doesn’t change the state. Thats why i tried the trigger “state: on” instead of the from-to-thing.

I added a new automation:

- alias: "Testautomation"
  trigger:
    platform: homeassistant
    event: start
  condition: 
    condition: state
    entity_id: switch.pc
    state: "on"
  action:
    service: homeassistant.turn_on
    entity_id: switch.monitore

This one turns on the Monitor as it should be. But in this way i have to double the specific automations - one for the startup and one at runtime. I have another, similar automation, which turns on a fan, if the raspberry reaches a specific temperature. Is it possible to combine the two automations? Maybe with two (or)triggers?

Okay, it seems like

- alias: "Testautomation"
  trigger:
    - platform: homeassistant
      event: start
    - platform: state
      entity_id: switch.pc
      state: "on"
  condition: 
    condition: state
    entity_id: switch.pc
    state: "on"
  action:
    service: homeassistant.turn_on
    entity_id: switch.monitore

is working for me. I’ll have to redesign my other automations in this way. Thank you for your tipps :slight_smile: