Threshold Sensor Question

I have three Threshold Sensors based on Inside RH. (My logic requires only One sensor being True (on) at any given time)

Low Limit = 10-30
Normal = 31-70
High Limit = 71-80

If I’m understanding how this should work, why is this Threshold Sensor Position below (off) and not In_range (on)?

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.

binary_sensor:
  - platform: threshold
    name: Your Name Here
    entity_id: sensor.your_sensor_here
    lower: 75
    upper: 75
    hysteresis: 5

Thank You Tom, How did you calculate a hysteresis of 5?

Are these examples correct?

10 - 30 Limits

10+30/2 = 20 - 10
hysteresis = 10??

30 - 70 Limits

30+70/2 = 50 - 30
hysteresis = 20??

Yep both correct.

1 Like

I think I’m faced with a similar issue, hence why I post here and not in a new topic (will do if needed).

One of my threshold sensors does not behave as expected as well, it stays on when it should not.

I’m tracking the numbers of run my vacuum do each day, with a history stat sensor :

  - platform: history_stats
    name: dusty2_daily_runs
    entity_id: vacuum.dusty2
    state: cleaning
    type: count
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

This works well. Now, I have defined a binary sensor that turns on when the vac has been run at least one time :

  - platform: threshold
    name: dusty2_daily_run_done
    entity_id: sensor.dusty2_daily_runs
    upper: 0

This kinda works : binary sensor turns on when the history sensor goes above 0, but don’t turn off when it’s reset :

image

Am I doing something wrong ? It’s been so long, I think I’m missing something obvious. Thanks for any help you can provide.

1 Like

Try upper: 0.5

And yes a new topic would have been better.

1 Like

Thanks for your feedback. I’ll create a new topic next time.

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 in advance for any clarity…

@Sddawson
Is this what you are looking for?

binary_sensor:
  - platform: threshold
    name: pH Pool ideal
    entity_id: sensor.intex_ultra_frame_ph
    lower: 7.2
    upper: 7.6
    hysteresis: 0.2

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!

The switching levels should only change if you have defined a hysteresis (click to enlarge):

5 Likes

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.

Thanks again.

Second paragraph in the docs says this:

So according to that (rather cryptic) explanation the second step in your sequence (4000) should be off.

If you can cause this to happen repeatedly you should open a new issue here: Issues · home-assistant/core · GitHub

Please include as much information as you can, including your sensor configuration, the sequence you posted above and the quote from the docs.

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?