Dynamic Binary Sensor - Variable State Value

All, I would like to have my low level alarm on my hottub dynamic (set via slider entry). The statement (hopefully that’s the correct terminology) is static at 30 as per below…

  - binary_sensor:     
      - name: "Hot Tub Temp Low"
        state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= 30.0 }}"

how would I integrate my helper slider into this statment, slider is…

input_number.hot_tub_low_temp_alarm_setpoint

TIA

  - binary_sensor:     
      - name: "Hot Tub Temp Low"
        state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= states('input_number.hot_tub_low_temp_alarm_setpoint') | float(0) }}"
1 Like

Gave this a try and for some reason it alarms at a slider values above 35 not less than 30?

  - binary_sensor:     
      - name: "Hot Tub Temp Low"
        #state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= 30.0 }}"
        state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= states('input_number.hot_tub_low_temp_alarm_setpoint') | float(0) }}"
 

The binary_sensor reports on when the template evaluates to true.

Therefore it will be on when the water temperature is less than the Input Number’s value. Otherwise it’ll be off.

Copy-paste the following into the Template Editor and let me know the results (it will report three values):

{{ states('sensor.hottub_water_temp_sensor') }}
{{ states('input_number.hot_tub_low_temp_alarm_setpoint') }}
{{ states('sensor.hottub_water_temp_sensor') | float(0) <= states('input_number.hot_tub_low_temp_alarm_setpoint') | float(0) }}

Sorry were does your example code go?, below is everything in my template.

########################### TEMPLATES #########################################

template:

      
  - binary_sensor:
      - name: "Garage Temp Low"
        state: "{{ states('sensor.garage_temp_sensor') | float(0) <= 10.0 and is_state('input_boolean.pause_alerts', 'off') }}"

  - binary_sensor:     
      - name: "Sump Level High"
        state: "{{ states('sensor.sump_level_sensor') | float(0) >= 75.1 }}"

  - binary_sensor:     
      - name: "Hot Tub Temp Low"
        #state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= 30.0 }}"
        state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= states('input_number.hot_tub_low_temp_alarm_setpoint') | float(0) }}"

Developer Tools > Template

The purpose of the exercise is to see the values of the sensor, input number, etc.

Perfect, thanks (slowly learning), result below…

Based on the results you posted, the water temperature is currently 33.5 degrees, the input number is 32, so the template reports false because 33.5 is not less than 32.

Therefore the current value of binary_sensor.hot_tub_temp_low should be off. Can you confirm that?

1 Like

Correct, I want the binary sensor to turn on to trigger the alert if the temp is below the setpoint. I assume just change the sign from the current “<=” to “>=” to accomplish this?.

That’s what it’s currently designed to do. It turns on only when the temperature is below the input number’s value.

It’s currently off because the temperature is above the input number’s value.

Sorry you are correct, I am thinking in the opposite direction. I appreciate the help and I did learn something with the template editor that is pretty slick. Do you remember my other post from yesterday about the alerts not triggering, then I uploaded and older setup from a few days back and everything worked as it should ?. Well without touching it, other than what we worked on, the alerts do not trigger again (I did not update anything0, any magic tricks to see what is going on ?

template:

      
  - binary_sensor:
      - name: "Garage Temp Low"
        state: "{{ states('sensor.garage_temp_sensor') | float(0) <= 10.0 and is_state('input_boolean.pause_alerts', 'off') }}"

  - binary_sensor:     
      - name: "Sump Level High"
        state: "{{ states('sensor.sump_level_sensor') | float(0) >= 75.1 }}"

  - binary_sensor:     
      - name: "Hot Tub Temp Low"
        #state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= 30.0 }}"
        state: "{{ states('sensor.hottub_water_temp_sensor') | float(0) <= states('input_number.hot_tub_low_temp_alarm_setpoint') | float(0) }}"
 
hottub_water_temp_sensor:
    name: Hot Tub Low Temperature
    entity_id: binary_sensor.hot_tub_temp_low
    state: "on"
    repeat: 1
    skip_first: False
    message: Hot Tub Temperature is Low
    done_message: Hot Tub Temperature has Returned to Normal
    notifiers:
     - mobile_app_RK_12
     - gmail

If the suggestion I made answers your original question, please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

It appears that you have chosen to mark your own post with the Solution tag, despite the fact it contains no information about how to answer your original question (namely how to create a Template Binary Sensor that compares a sensor’s value to an input number’s value).

This choice of Solution post won’t be helpful to other users who may be looking for answers to similar questions.

I was trying to delete it and could not, sorry

  • You can only mark one post in a topic with the Solution tag.

  • If you mark a post with the Solution tag and then mark another post, the Solution tag will be automatically removed from the first post and assigned to the second one.

Ok thanks for the notes, I will remember for next time. Should I create a new post about my alert issue ?

Why not try it now in this topic given that you have clearly marked the wrong post with the Solution tag.

Ok, I think it’s good now?

Nothing has changed.