I want to have a sensor which passes along the state of my network status with a delay before declaring it normal, but avoid the “unknown” every time it restarts HA. It seems like adding a condition is not valid in templates?
I want a sensor which will:
- Immediately update “Normal” → “anything but unknown”
- Immediately update “anything but unknown” → “Normal”
- Delay update “anything but Normal” → “Anything but Normal”
- Never update to “unknown”
The possible states are a lot of things to describe ways that the network might have a problem. Examples:
- Normal (all ok)
- Cable modem down
- Cellular modem down
- Signals out of spec
- DNS down
- Packet loss
- Router down
- Slow speeds
- …you get the idea.
The purpose of this sensor is an intermediate delayed update so that I don’t get spammed as it passes thru a bunch of states quickly (e.g. in a short span of like 15-20 second having packet loss → signal issue → modem down → signal issue → modem down only generates 1-2 updates of this sensor)
This works if I remove the “condition” part, but I don’t want the sensor to be updated if the state is “unknown” still initializing on restart.
- trigger:
# Immediately update going down
- platform: state
entity_id:
- sensor.network_state
from: 'Normal'
# Immediately update back to normal
- platform: state
entity_id:
- sensor.network_state
to: 'Normal'
# Delay update down state to reduce flapping
- platform: state
entity_id:
- sensor.network_state
not_to: 'Normal'
for: '00:02:30'
- platform: homeassistant
event: start
condition:
condition: not
conditions:
- condition: state
entity_id: sensor.network_state
state: "unknown"
sensor:
- name: 'Network State Debounced'
icon: mdi:check-network
state: >-
{{ states('sensor.network_state') }}
So what I want to avoid, is it then sends me this in an automation every time templates load:
Home Assistant, [10/22/22 9:15 AM]
Previous Status:
Network Status was Normal
-
Network Status:
unknown
at 22-Oct-2022 09:15:47
Home Assistant, [10/22/22 9:15 AM]
Previous Status:
Network Status was
-
Network Status:
Normal
at 22-Oct-2022 09:15:47