Making sure a switch is on

After a powercut my Wemo devices remain off - which is annoying

Does anyone know a way/automation to makesure it is kept on

- id: Make sure Billion is on
  alias: Make sure Billion is on
  trigger:
    platform: state
    entity_id: switch.billioninternet
    to: 'off'
    for:
      minutes: 5
  action:
    service: homeassistant.turn_on
    entity_id: switch.billioninternet

If you always want it to be on, then why are you using a switch? :stuck_out_tongue_winking_eye:

But seriously, if you always want the switch to be turned on when HA starts, then:

- id: Make sure Billion is on
  alias: Make sure Billion is on
  trigger:
    platform: homeassistant
    event: start
  action:
    service: homeassistant.turn_on
    entity_id: switch.billioninternet

Good question!

But there is a reason. I use the switch to hard reset the router if the internet goes down. So it’s like a local reboot after all other internet repair attempts fail.

Only issue is after a power cut the switch is off.

Is there a way to detect if the switch is off for a period of time and turn it on?

does the switch report its state to home assistant? That is, if you flip the switch on, does the GUI change to show it’s on? If so:

- id: Make sure Billion is on
  alias: Make sure Billion is on
  trigger:
    platform: state
    entity_id: switch.billioninternet
    state: "off"
    for:
      minutes: 5
  action:
    service: homeassistant.turn_on
    entity_id: switch.billioninternet

That will turn the switch on if it has been off for more than 5 min. It looks like you had it right the first place, does it not work?

Yes.

trigger:
  platform: state
  entity_id: switch.your_switch
  to: 'off'
  for: 
    seconds: 30

You are missing the entity_id in the state trigger.

ah yes… corrected

1 Like

Thanks @ha_steve however that results in an error

Configuration invalidCHECK CONFIG

Invalid config for [automation]: [state] is an invalid option for [automation]. Check: automation->trigger->0->state. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/

Thanks @tom_l - but how is that different from what I posted

It’s not. It should work.

Also Steve’s answer has state: 'off' instead of to: 'off' in the trigger, this is incorrect and is causing the error you see.

1 Like

Thanks @tom_l and @pnbruckner

I think a combination of the following should work

- id: Make sure Billion is on
  alias: Make sure Billion is on
  trigger:
    platform: state
    entity_id: switch.billioninternet
    to: 'off'
    for:
      minutes: 5
  action:
    service: homeassistant.turn_on
    entity_id: switch.billioninternet
- id: Make sure Billion is on at HA Startup
  alias: Make sure Billion is on at HA Startup
  trigger:
    platform: homeassistant
    event: start
  action:
    service: homeassistant.turn_on
    entity_id: switch.billioninternet

sorry! Teaches me to respond in a hurry!

1 Like