Automation condition - delta of change

User story: As a user I would like to switch off my thermostat when I’m air-venting my house.

Would like to have a condition for a delta of change. For example, during winter, if my thermostat starts heating when the room temperature drops by 5 degrees within 5 minutes, I want to switch if off for a while (20-30 minutes), because I’m air-venting.

I can imagine something like this:
condition: delta_change
entity_id: sensor.temperature
value: 5
within:
minutes: 5

I put some temp sensors to my sauna. I have a wood stove meaning when warming the sauna, I have to add wood to keep it warming up. With delta-values it would be possible to create triggers when there’s no wood left.

You can see the temp starts to rise and delta is positive. In 16:35 the delta turns negative and I was a little late for adding more wood. Same thing in 16:45- 17:00. If there is some kind of delta, in this situation Dtemp/Dtime, it would be easy to create rule to inform me I have to go add more wood.

Differentiating measured data greatly amplifies the noise of the measurement (http://dx.doi.org/10.5402/2011/164564) as you can see easily by the spikes in your plot. You do not want to trigger e.g. when the temperature drops by 0.001 C just because that is the limit of the tempersture sensor precision. Thus to do meaningfull triggers on value changes one has to filter the data (e.g. Smooth the curve). Smoothing demands to have several older values stored and the strength of the needed smoothing depends on the sensor data itself. I am not sure how this can be implemented in hass but I guess it will not be straight forward.

Actually, I’ve started using Postgres as history database, so that I can filter the fluctuation off. So it’s better to me, that there is a way in HA to run queries in Postgres and use that data as ‘sensors’.

With Postgres, I can actually increase the accuracy to 0,05C because when the temp fluctuates between two values (x, x±0,01) , the real value will be x±0,005C.

I have just done this via the new Statistics Sensor platform on 30.1, by taking the max_value and min-value attributes of the statistics sensor (suffixed with “_mean”) - here’s how:

- platform: statistics
  name: YOUR SENSOR Stats
  entity_id: sensor.your_sensor
  sampling_size: 4
- platform: template
  sensors:
    ensuite_humidity_delta:
      friendly_name: "Ensuite Humidity Delta"
      value_template: "{{ states.sensor.your_sensor_stats_mean.attributes.max_value | float - states.sensor.your_sensor_stats_mean.attributes.min_value | float }}"
      entity_id: sensor.your_sensor_stats_mean
      unit_of_measurement: "YOUR UNIT OF MEASUREMENT"

This might help in the meantime for anyone wanting a solution.

3 Likes