Binary sensor value greater than

Hi,
I need help with a template. I want a binary sensor that turns on if the difference between 2 temperature sensors is greater than 3.
At the moment I have the following in configuration.yaml

  - platform: template
    sensors:
      kitchen_minus_living:
        entity_id:
          - sensor.kitchen_temp
          - sensor.temp_inside_upstairs
        value_template: >-
          {% set kitchen = states.sensor.kitchen_temp.state|float %}
          {% set living = states.sensor.temp_inside_upstairs.state| float %}
          {{ (kitchen - living)|round(1) }}
binary_sensor:
  - platform: template
    sensors:
      cooking:
        friendly_name: "Cooking"
        value_template: "{{ states('kitchen_minus_living')|float > 3.0 }}" 

I honestly don’t understand anything about the language used in templates so I would greatly appreciate any help :slight_smile:

Try this:

binary_sensor:
  - platform: template
    sensors:
      cooking:
        friendly_name: "Cooking"
        value_template: >
          {% set kitchen = states('sensor.kitchen_temp')|float %}
          {% set living = states('sensor.temp_inside_upstairs')| float %}
          {{ (kitchen - living)|round(1)  > 3 }}

that’s it, thanks!

Hello,

since I am having a similar issue maybe someone can point me in the right direction.

I would like a binary sensor to measure a difference between 2 signal strength values with a twist.

Since the signal is always changing i need some kind of tolerance. This is the code I have but i need the “else” to be like last known state.
It kinda works as a normal sensor but produces so much values. I Just need “Inside” and “Outside” so binary would be much better. With the tolerance of like 10dB and before that no change.

binary_sensor:
    - platform: template
        sensor:
          ble_cat_pos_diff:
            friendly_name: Cat Position
            entity_id:
              - sensor.ble_doctor_rssi_value
              - sensor.window_ble_doctor_rssi_value
            value_template: >-
              {% set catd_rssi = states.sensor.ble_doctor_rssi_value.state|float %}
              {% set catw_rssi = states.sensor.window_ble_doctor_rssi_value.state| float %}
              {% set cat_pos = (catd_rssi - catw_rssi)|round(1) %}
              {% if ((catd_rssi - catw_rssi)|round(1) > 10) %}
                Cat Inside
              {% elif ((catd_rssi - catw_rssi)|round(1) < 0) %}
                Cat Outside
              {% else %}
                 # [{last state}]?
              {% endif %}

In case anyone is searching for this here is my solution that works as expected.
I don’t know if it is the best solution. And i miss some initialise Value because i only update (trigger) when the difference is 10db apart.
It is in the configuration.yaml under template:

  - trigger:
      - platform: numeric_state
        entity_id:
          - sensor.ble_doctor_rssi_value
          - sensor.window_ble_doctor_rssi_value
        value_template: >
            {% set indoor = states('sensor.ble_doctor_rssi_value') | float %}
            {% set outdoor = states('sensor.window_ble_doctor_rssi_value') | float %}
            {% set tmp = ((indoor - outdoor) | round(1)) %}
            {{tmp}}
        above: 9
      - platform: numeric_state
        entity_id:
          - sensor.ble_doctor_rssi_value
          - sensor.window_ble_doctor_rssi_value
        value_template: >
            {% set indoor = states('sensor.ble_doctor_rssi_value') | float %}
            {% set outdoor = states('sensor.window_ble_doctor_rssi_value') | float %}
            {% set tmp = ((indoor - outdoor) | round(1)) %}
            {{tmp}}
        below: 0
    sensor:
      - name: "Cat Position"
        state: >
          {% set indoor = states('sensor.ble_doctor_rssi_value') | float %}
          {% set outdoor = states('sensor.window_ble_doctor_rssi_value') | float %}
          {% set tmp = ((indoor - outdoor) | round(1)) %}
          {% if tmp > 9 %}
          {{ "Cat is Home" }} 
          {% elif tmp < 0 %} 
          {{ "Cat is Outside"}}
          {% endif %}