How? Create sensor to calculated rate of change?

here is the sensor I set up to calculate the estimated heating time

  - name: "Pool Estimate Heat Time"
    unique_id: diff_temp
    unit_of_measurement: "°C"
    state: >
          {% set pooltemprise = states('sensor.pool_temp_rise_rate_7day_average') | float(none) %}
          {% set poolsettemp = states('sensor.pool1_heaters0_settemp') | float(none) %}
          {% set poolcurrenttemp = states('sensor.pool1_temperature') | float(none) %}
          {{ (pooltemprise * ((poolsettemp) - (poolcurrenttemp))) | round(1, default=none) }}

starting too get the hang of this

The problem is the template sensors feeding the statistics sensors. We made them go unavailable so the statistics average would not be affected when the template sensors were not measuring.

I could make the two template sensors hold the last value, which will affect the 7 day average. Or hold the statistics average, but again this would be self referential and just reinforce the last calculated average.

How constant are the 7 day averages turning out to be?

The other option is to make two more template sensors that hold the last value of the statistics sensors. These will always display the averages but not affect them.

sounds like the last option is the go…how do you make it hold the last value?

What are your average statistics sensor entity_id’s?

sensor.pool_temp_rise_rate_7day_average
and
sensor.pool_temp_fall_rate_7day_average

  - platform: template
    sensors:
      last_pool_temp_average_fall_rate:
        friendly_name: "Last Pool Temp Average Fall Rate"
        unit_of_measurement: "°C/h"
        icon: thermometer-chevron-down
        value_template: >
          {% if states('sensor.pool_temp_fall_rate_7day_average') not in ['unavailable', 'unknown', 'none'] %}
            {{ states('sensor.pool_temp_fall_rate_7day_average') }}
          {% else %}
            {{ states('sensor.last_pool_temp_average_fall_rate') }}
          {% endif %}
      last_pool_temp_average_rise_rate:
        friendly_name: "Last Pool Temp Average Rise Rate"
        unit_of_measurement: "°C/h"
        icon: thermometer-chevron-up
        value_template: >
          {% if states('sensor.pool_temp_rise_rate_7day_average') not in ['unavailable', 'unknown', 'none'] %}
            {{ states('sensor.pool_temp_rise_rate_7day_average') }}
          {% else %}
            {{ states('sensor.last_pool_temp_average_rise_rate') }}
          {% endif %}
2 Likes