i built a binary sensor for open window detection using a couple of components. the first part consists of a statistics sensor to get min and max values computed from 4 samples:
sensor:
- platform: statistics
name: tado kinderzimmer statistik
entity_id: sensor.tado_kinderzimmer_temperatur
sampling_size: 4
i then calculate the delta value of the min/max values of the thermometer in the room where i want to detect an open window:
sensor:
- platform: template
sensors:
kinderzimmer_temperatur_delta:
friendly_name: "Kinderzimmer Temperatur Delta"
value_template: "{{ states.sensor.tado_kinderzimmer_statistik_mean.attributes.max_value | float - states.sensor.tado_kinderzimmer_statistik_mean.attributes.min_value | float }}"
entity_id: sensor.tado_kinderzimmer_statistik_mean
unit_of_measurement: "C"
third part is a trend sensor, to see if the temperature is falling due to an open window:
binary_sensor:
- platform: trend
sensors:
kinderzimmer_temperatur_down:
entity_id: sensor.tado_kinderzimmer_temperatur
invert: Yes
fourth part is an automation, that notifies me of the open window, if delta is above 0.3 and the trend falling:
automation:
alias: 'fenster kinderzimmer offen'
trigger:
- platform: numeric_state
entity_id:
sensor.kinderzimmer_temperatur_delta
above: 0.3
condition:
- condition: state
entity_id: binary_sensor.kinderzimmer_temperatur_down
state: 'on'
action:
- service: notify.notify
data:
title: "oops: "
message: "fenster kinderzimmer offen"
this is rather complicated, but it works. however it takes up to 5 minutes to register the open window and it doesn’t notify if the window is closed again. registering a closed window would work the same way: if delta > 0.3 and the temperature trend is rising, it’s likely, that the window is closed again. it probably would be fairly easy to do this with app daemon, but (i guess) also with a component that would create a binary sensor of type opening.
the sensor configuration would need these parameters:
binary_sensor:
- platform: open_window
sensors:
living_room_window:
entity_id: sensor.living_room_temperature
sampling_size: 4
threshold: 0.3
this binary sensor would then calculate the mean value using sampling_size
samples, calculate the delta and check if the trend is up or down as soon as the delta is greater than threshold
.