After reading another posts with a response by @tom_l I was thinking that a Hysteresis value was needed, but I’m not sure how that works with an upper and lower limit set, or if it even applies to my need.
On = when sensor value is between and including 71 and 80.
Off = when below 71 (70 or lower) or above 80 (81 or higher).
The problem I think I’m having is:
it seems if the sensor value is already between the Limits, and it falls or rises to the limit value the helper stays on.
However if the value is below or above the Limits and if falls or rises to the limit value is stays Off. This is unwanted in my case.
I have a requirement basically the same as @ServiceXp. Tracking the status of a pool pH reading. 7.2-7.6 is OK, and sensor should be On. Below 7.2 or above 7.6 it should be off. Nothing I’ve tried with upper/lower limits set differently or the same, with and without a hysteresis, has resulted in the state dynamically changing according to the range.
When setting up the helper, it states:
“ Both lower and upper limit configured - Turn on when the input sensor’s value is in the range [lower limit … upper limit].”
But there must be more to it than this, because simply setting upper and lower ranges with no hysteresis doesn’t seem to accomplish this. Maybe it just doesn’t turn off the binary sensor when it goes outside the range, which is what I’m looking for.
Thanks for the reply. I’m pretty sure I’ve tried many values for hysteresis. I made another post at Threshold helper with ranges - is this a bug or my misunderstanding? that hasn’t had any reply. It has more details of the problem as I see it. Basically, when crossing into an exact range boundary, the sensor can be on or off, depending on what “direction” the value is travelling. Just seems wrong to me!
If you just want a binary sensor to be on when within a range use a template binary sensor.
configuration.yaml
template:
- binary_sensor:
- name: "pH in Range"
device_class: problem
state: "{{ 7.2 < states('sensor.your_ph_sensor_here')|float(0) < 7.6 }}"
FYI: one of the reasons you may not have received a reply to your linked topic is that you posted pictures of text rather than the actual text correctly formatted for the forum. Posting the text makes it a lot easier for people to help you using copy/paste/edit.
Thanks for that. I started with a template sensor, which worked fine, but i thought using a built in helper would be easier to maintain. I still think it’s not working as advertised though, although quite happy to admit I might not be reading it right!
The reason I posted pictures was so I could show the actual state, as shown by Developer Tools. It wasn’t really to show the content of the helper, but more to show what happens to the state under various conditions.
With no hysteresis it should work from either direction - from above upper or below lower - into the window. To be clear, you are saying it does not do this?
Yes, that’s my finding. Depending on whether it reaches, say, the lower range on the way up or on the way down, the result is different. In my other post, you can see a value if 4000 (the lower range in this case) sometimes yields a state of on and sometimes a state of off, depending on whether the sensor value is going up or going down. It certainly doesn’t seem right that a single value can yield different results. Thanks for your input!
Thank you very much for taking the time to visualise this. I have a simple requirement. Let’s take the example from my other post. If a sensor has a value between 4000 and 5000, the threshold sensor should be on. This includes the 4000 and 5000 values. This is what happens (with no hysteresis):
Sensor value 4001, threshold sensor is on.
Sensor value 4000, threshold sensor is on.
Sensor value 3999, threshold sensor is off (all good so far).
Sensor value 4000, threshold sensor is still off.
So, with a sensor value of 4000, the threshold sensor is either on or off, depending on whether we’re on the way down or on the way up. This seems a little strange to me, for such a simple requirement. But quite possible I’m missing the use case for this helper.
This is the exact behavior that caused me to start this thread. Adding hysteresis ‘fixed’ it for me, but it seemed overly complicated when my use case was extremely basic.
It seems to me that the quote from the docs probably only applies to a single threshold, not a range. When setting up a helper, it says:
Both lower and upper limit configured - Turn on when the input sensor’s value is in the range [lower limit … upper limit].
I guess it is open to conjecture what “in the range” means, but I would think most people would assume equal to the lower number, equal to the upper number, or anywhere in between. Would you agree?