Hi everyone,
I’m struggling with a simple automation that never triggers, even though the condition is clearly met.
The goal is to schedule a reboot if the uptime of my Zyxel router drops below 500 seconds, but only outside the 2:00–6:00 AM window and if a flag (input_boolean.zyxel_reboot_scheduled) is off.
Here’s the automation:
alias: Zyxel - Schedule reboot if uptime <500
description: If uptime <500 and NOT between 02:00 and 06:00, schedule reboot
trigger:
- platform: numeric_state
entity_id: sensor.zyxel_uptime_numeric
below: 500
condition:
- condition: time
after: "06:00:00"
before: "02:00:00"
- condition: state
entity_id: input_boolean.zyxel_reboot_scheduled
state: "off"
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.zyxel_reboot_scheduled
mode: single
I suspected the problem might be with the sensor not having the correct state class, so I created this template sensor:
A trigger is an event, not a condition. Yours will fire when your router uptime changes from 500 to 499. It won’t fire again until the value has increased to above 500 and dropped for a second time.
So it will never trigger because the value doesn’t go from, say, 7,000,000 to 70. When it reboots — for any reason, like a power cut today — the value goes from 7,000,000 to unknown/unavailable, and then to 70.
My internet connection changes its IP address every 24 hours with 15-30 seconds downtime, so I’m checking if the uptime is below, say, 500 — meaning the router rebooted for any reason. If that happens during the day, I turn on a helper.
Then, there’s another automation that runs at 4 a.m. it checks that helper, and if it’s on, it reboots the router and turn off the helper. This way, the IP change will always happen at 4 a.m., without causing any interruptions for people using the internet during the day.
that input_number is 500 and the automation works. So, at 4 a.m. home assistant will reboot my router and from that moment, the IP address will change at the same time without any interruption during the day.
I still don’t get why you need a reboot?
You turn on helper when you detect it was rebooted (does it really reboot if only IP changed? It is pretty standard just to lease an IP when old lease expired).
And at that point - why do you need a reboot later?
As I mentioned, my internet connection changes its IP address every 24 hours. During this process, there is no internet connection for about 15 to 30 seconds. By forcing a reboot at 4 a.m. (if needed), the IP change and the brief downtime will always occur while people are sleeping.
for your reference, this is the complete automation: if uptime is less than 500 (meaning it rebooted/restarted/turned on) or the ip address changes (meaning I changed something in the zyxel, like locking another 5G antenna) → it schedule a reboot so the following ip changes will happen at 4 a.m. or at least in the early morning (between 2 and 6 a.m.).
I hope it makes sense now
alias: Zyxel - Schedula reboot se uptime <500
description: Se uptime <500 o cambio ip e NON tra le 02:00 e le 06:00 programma riavvio
triggers:
- trigger: numeric_state
entity_id:
- sensor.zyxel_device_info_deviceinfo_uptime
below: input_number.zyxel_reboot_uptime
- trigger: state
entity_id: sensor.fritz_box_7530_ax_ip_esterno
conditions:
- condition: time
after: "06:00:00"
before: "02:00:00"
- condition: state
entity_id: input_boolean.zyxel_reboot_scheduled
state: "off"
- condition: template
value_template: >-
{{ not states('sensor.fritz_box_7530_ax_ip_esterno') in ['unavailable', 'unknown'] }}
actions:
- target:
entity_id: input_boolean.zyxel_reboot_scheduled
action: input_boolean.turn_on
data: {}
mode: single