Add/Remove Sensor in Helper based on time

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:

    name: 3rd_Floor_Thermostat
    heater: switch.tasmota4
    target_sensor: sensor.3rd_floor_mean_temp
    min_temp: 60
    max_temp: 70
    ac_mode: false
    target_temp: 60
    cold_tolerance: 0.5
    hot_tolerance: 0.5
    min_cycle_duration:
      seconds: 20
    initial_hvac_mode: "heat"
    away_temp: 60
    home_temp: 67
    sleep_temp: 64
    precision: 1.0

Any help is greatly appreciated.

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.

1 Like

Thanks so much. I will give this a try!

what does the 65 do ???

That’s the default value for the float filter.

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 }}

1 Like

Thanks bro