Automation not triggering even if condition is met – Numeric State issue?

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:

- sensor:
    - name: Zyxel Uptime (numeric)
      unique_id: zyxel_uptime_numeric
      state: "{{ states('sensor.zyxel_device_info_deviceinfo_uptime') | int(0) }}"
      unit_of_measurement: "s"
      state_class: measurement
      device_class: duration

Unfortunately, the automation still doesn’t fire when the uptime drops below 500.
Questions:

  • Am I misunderstanding how the numeric_state trigger works?

  • Is the template sensor set up correctly?

Any help or advice is very welcome. Thanks!

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.

Unit of measurement have no influence on the triggering.

Check the values of your sensors and input variables in the developer tools and check the travel of the automation.

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.

The uptime updates every 30 seconds.

How should I write the automation then?

Hello Felice Marra,

Add a trigger for 6am.
Add a condition that the value be below 500.
Add a trigger for 1:59:59am with a trigger_id to use to shut it off.

Nope, that’s not what I’m looking for :slightly_smiling_face:

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.

Well I gave you advice on how to trigger that not between 2am and 6 am.
My suggestions are valid.
If you want something else then do that.

yes, it is ok, but it doesn’t work for my scenario. Anyway, thank you!

I found a way to achive it: I created an input_number and I checked the uptime against that input_number

triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.zyxel_device_info_deviceinfo_uptime
    below: input_number.zyxel_reboot_uptime

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.

1 Like

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

and you need a second automation running at 4 a.m.

alias: Zyxel - Esegui reboot se schedulato
description: Esegue il reboot alle 4 se è stato schedulato
triggers:
  - at: "04:00:00"
    trigger: time
conditions:
  - condition: state
    entity_id: input_boolean.zyxel_reboot_scheduled
    state: "on"
actions:
  - target:
      entity_id: input_boolean.zyxel_reboot_scheduled
    action: input_boolean.turn_off
    data: {}
  - target:
      entity_id: button.zyxel_reboot_device
    action: button.press
    data: {}
mode: single

Why don’t you just reboot at 4AM every day, no matter what? That way you know you won’t get new IP for next 24 hours?

1 Like