I just set up a HC-SR04 ultrasonic distance sensor to determine the water level in my sump pump pit. I want to create an alert if the water level rises above 40 cm.
I want it to notify me when the water first goes above 40 cm, then if I don’t turn off the alerts, notify me again after 5 min.
Right now I’m using a trigger-state
note and then a current-state
node to check a helper boolean in Home Assistant to see if I have the alarms turned on, and then a call-service
node to push out the notification.
The problem with this setup is I get a notification every 2 seconds, as that is how frequently the distance measurement is made. Any clever way to add a “cool down” period or something?
Some ideas I have so far:
-
The
trigger-state
is going to keep pushing those messages, so maybe have the first one start a timer, and then somehow not let any more through until the timer stops? I’m not too familiar with all the different nodes, or what to even call/name what I’m trying to do, so if someone has some ideas and could point me in the right direction that would be appreciated. -
Use a ?template sensor? or something to make it so every time the water level is greater than 40 cm, switch a helper boolean toggle thing. Then use the
events-state
node to push the notification and then tell it to ignore if the current state is the same as the next state? But then somehow I want it to send another notification after 5 min or something. Maybe that’s a separate loop and it just checks to see if that helper boolean thing is still on?
Edit: There is athreshold sensor
in Home Assistant that might work perfectly for this. I may have rubber ducked my way out of this…
Edit 2:
Here is my solution.
The Water Level Alarm
is the threshold helper from Home Assistant. The next node checks the actual height of the water. The next node checks to see if I have alarms turned on or off via a helper. The last node is the notification. Then below that I’m using the stop-timer
node (which is no longer included with node-red so you have to add it yourself. After 3 minutes it checks the Water Level Alarm again and if it’s still high, it sends me another notification. When the Water Level Alarm threshold helper is turned off by Home Assistant, this timer is then stopped.