Need help with simple automation

Hi, I have a z-wave plug connected to my router.
If my internet connection fails I want this plug to be turned off, and turned on again after 30 seconds.

I set up the automation using the buit-in wizard. Here’s the code from automation.yaml

- action:
- alias: ''
  data:
    entity_id: switch.get_router_plug_switch
service: switch.turn_off
alias: Reboot router step 1
condition: []
id: '1515580090349'
trigger:
- entity_id: binary_sensor.google
  from: 'On'
  platform: state
  to: 'Off'
- action:
- delay: 00:00:30
- data:
    entity_id: switch.get_router_plug_switch
  service: switch.turn_on
- data:
    message: Get ruter ble restartet pga manglende internettilgang.
  service: notify.tbt_telegram
alias: Reboot router step 2
condition: []
id: '1515582068511'
trigger:
- entity_id: switch.get_router_plug_switch
  from: 'On'
  platform: state
  to: 'Off'

The binary_sensor.google is a ping sensor that pings 8.8.8.8 every 10 seconds. If this fails, I want the switch

switch.get_router_plug_switch

to be turned off.
When this switch is off, I want it to be turned back on again after 30 seconds.
However nothing happens when the ping fails (I’ve testet this using a local client as target for the ping.)
What’s wrong in this code?

Thanks

I would reduce it to one automation -

is google available
no -
turn off router
delay 30s
turn on router
yes-
do nothing
It’s almost impossible to debug the builtin editor code as it’s such a mess (not your fault)
but I would assume it’s the trigger that’s not working one or the other or both.

Thanks, would it be better to script it manually in automation.yaml?

Yep that’s what I would do, I can’t get my head around the automation editor :stuck_out_tongue:

1 Like

Thanks, I’m trying to get my head around this.
In the script I’m making for this automation want to check if internet is back online after reboot, if not stop the automation, else if OK notify.
Apparantly I can’t have service inside a condition block. How could I accomplish what I want to?

# Automation for router restart
- alias: Restart ruter ved utilgjengelig nett
  trigger:
    platform: state
    entity_id: binary_sensor.google
    from: 'on'
    to: 'off'
    for:
      hours: 00
      minutes: 01
      seconds: 00
  action:
    - service: switch.turn_off
      data:
        entity_id: switch.get_router_plug_switch
    - delay: 00.00.30
    - service: switch.turn_on
      data:
        entity_id: switch.get_router_plug_switch
    - delay: 00.05.00
    - condition: or
      conditions:
        - condition: state
          entity_id: binary_sensor.google
          stats: 'off'
          service: automation.turn_off
          entity_id: automation.restart_ruter_ved_utilgjengelig_nett
        - condition: state
          entity_id: binary_sensor.google
          state: 'on'
    - service: notify.tb_telegram
      data:
        message: "Router restarted"

It looks like the condition is inside the action and spacing is off.

Thanks for the reply :slight_smile:
conditions is supposed to work within actions, or am I wrong?

However I’m not sure what to do about the service within the condition. I figure I can’t have a service statement within a condition, so how can I do this the right way?

After the switch is turned back on I want to check if internet is available again, then send a notify, if it’s not available it should turn off the automation so that it don’t run in an “eternal” loop.

No you’re right, you can have a condition inside an action, sorry 'bout that. About the service inside the condition, I have no idea.