I have homeassistant monitoring lots of devices, and it is detecting state changes, but i’m getting some false positives. Most of the sensors are binary sensors.
I want to be able to detect that an entity has entered a failed state 3 times in a row before an automation triggers a notification.
All the actions seem to need a state change to trigger an automation , so i can detect the first state change and increment a counter , but as the state does not chnage after that i can’t i cant detect no chnage even if still in a failure state. Any tips on how to accomplish this. I did looking forcing the entity back in to an unknown state but this does not look possible.
So a few examples an ftp connection does not work or a ping test fails or dhcp server fails to respond, whatever the error my sensors are something like this
The response from the test is 0 or 1, 0 means the test worked and 1 means it failed. I need to over 3 test cycles get a 1 (failed eadh time) to ensure false positives are rules out. so when a failure occurs the values started from working will be
0 (working)
1 (failed)
1 (failed)
1 (failed)
with no state changes on the last 2 tests.
Also and this comes latger if say the 1 tests fails, then the 2nd or 3rd works, the counter needs to be reset and the false positive ignored.
If after 3 fails in a row i need a notification (which i can do)
I test that my NAS is running by pinging it. I know the frequency of the pings (30 sec by default) so I have an automation that triggers if the binary sensor remains off for 5 min - ie 10 pings - and sends a notification.
I tried that the issue i’m facing is homeassistant seems need a state change to trigger.
so good to bad is a change (triggers)
bad to bad is no change ( fails to trigger)
bad to bad is no change (fails to trigger)
I think I’ve misunderstood the question… Why do you need a state change, when what you’re trying to detect is a lack of change? The binary sensor will retain it’s value.
This works for me:
trigger:
- platform: state
entity_id:
- binary_sensor.192_168_1_141
to: "off"
for:
hours: 0
minutes: 5
seconds: 0
There’s some help with including code in posts here:
Thanks everyone i think the issue was the scan times on the sensor and the wait for times in the automation i have adjusted them to allow 6 scans and it works now. Sorry simple question i tried to over complicate