I saw your post from yesterday but you have deleted it anyway, I found a way now which works fabulous for my requirement (I definitely need the threshold, as you mentioned in your deleted post).
I have modified your sensor a bit, adding an offset to the outside temp. The threshold is set to 1°C in my case.
- binary_sensor:
- name: Inside vs outside temp
icon: mdi:thermometer-low
availability: |
{{ not false in
[states('sensor.outside_temp),
states('input_number.threshold'),
states('sensor.inside_temp')]|map('is_number')
}}
state: |
{% set hysteresis=states('input_number.threshold')|float(0) %}
{% set entity=states('sensor.outside_temp')|float(0) + states('input_number.offset')|float(0) %}
{% set limit=states('sensor.inside_temp')|float(0) + (hysteresis if this.state=='on' else -hysteresis) %}
{{ entity < limit }}
For the offset-temperature, I have created an automation, it includes also a safety margin (x2.5 instead of x2). In the morning, the offset in my case is at +2°C, which increases the outside temp artificially. In the evening, the offset is at -1°C, which decreasees the outside temp artificially.
Since there is the threshold in the binary sensor, you dont have any flapping.
alias: Offset on/off
description: ''
trigger:
- platform: template
value_template: >-
{{ (states('sensor.outside_temp')|float(0) -
states('sensor.inside_temp')|float(0)) > (2.5 *
states('input_number.threshold')|float(0)) }}
id: off
- platform: template
value_template: >-
{{ (states('sensor.inside_temp')|float(0) -
states('sensor.outside_temp')|float(0)) > (2.5 *
states('input_number.threshold')|float(0)) }}
id: on
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: off
sequence:
- data_template:
value: >-
{{ states('input_number.threshold')|float(0) *
-1 }}
entity_id: input_number.offset
service: input_number.set_value
- conditions:
- condition: trigger
id: on
sequence:
- data_template:
value: >-
{{ states('input_number.threshold')|float(0) *
2 }}
entity_id: input_number.offset
service: input_number.set_value
default: []
mode: single
The only problem was, that if the outside temperature does not go below the inside temp for the defined [offset-threshold], the offset will remain as it was. For this, I have created an additional trigger at 5 AM in the above automation, which will check this, including a bit of safety margin (0.5°C):
- conditions:
- condition: trigger
id: time
- condition: template
value_template: >-
{{ (states('sensor.inside_temp')|float(0) -
states('sensor.outside_temp')|float(0)) <= (2.5 *
states('input_number.threshold')|float(0)) }}
- condition: state
entity_id: binary_sensor.invise_vs_outside_temp
state: 'on'
sequence:
- data_template:
value: >-
{{ (states('sensor.inside_temp')|float(0)
- states('sensor.outside_temp')|float(0) +
states('input_number.threshold')|float(0) +
0.5)|round(1) }}
entity_id: input_number.offset
service: input_number.set_value
This is the result (the offset would change dynamically at 5AM in this scenario, you can see inside vs outside temp was almost the same during the night):
Cheers and thanks for the help and input!