Hi there!
Long time lurker, first-time poster! I’m trying to figure out how I can add and remove a sensor within a helper (combine the state of several sensors) based on the time of day. I’m using helpers to avg out temperatures across multiple heating zones, and want to remove one of the sensors overnight.
There’s another option of creating a second helper w/o this sensor, but how would I tell the thermostat to use the other “target sensor” outside of X hours? Here’s the thermostat from config.yaml:
I suggest a simpler approach that doesn’t involve modifying the membership of a group helper.
Create a Template Sensor that computes the average of your multiple temperature sensors. Have it exclude a temperature sensor from the average calculation during overnight hours.
Example
template:
- sensor:
- name: Average Room Temperature
device_class: temperature
unit_of_measurement: '°F'
state: >
{% set sensors = ['sensor.room1', 'sensor.room2', 'sensor.room3' ] %}
{% set is_night = is_state('sun.sun', 'below_horizon') %}
{% set sensors = sensors if is_night else sensors + ['sensor.room4'] %}
{{ sensors | map('states') | map('float', 65) | average }}
Use this Template Sensor for the Generic Thermostat integration.
In the following example, float is applied to each one of the three items in the list. The third item, cat, is non-numeric so float will replace it with its default value of 2.5. Therefore the average of three instances of 2.5 is 2.5.
{{ ['2.5', '2.5', 'cat'] | map('float', 2.5) | average }}