Advice on how to sensor configuration

Hi All,

I’m trying to do a little HA housekeeping (I’m not terribly active) and am after advice on better ways to manage my configuration. Today my config is a mess of stuff created through the UI and yaml. Below is the configuration snippet for my hydronic heater (4CHR3 controls the hydronic boiler, along with the garden sprinklers).

Aside from moving this into sensors.yaml, I feel that that “code” (I say that very loosely) is far from ideal. Any advice on better ways to structure this?

sensor:                                                                                                                                                                                                                                             
  - platform: template                                                                                                                                                                                                                              
    sensors:                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                    
      heat_required:                                                                                                                                                                                                                                
        friendly_name: "Heat Required"                                                                                                                                                                                                              
        value_template: >-                                                                                                                                                                                                                          
          {{ (state_attr('climate.ensuite_thermostat', 'current_temperature')|int) < (state_attr('climate.ensuite_thermostat', 'temperature')|int) or                                                                                               
             (state_attr('climate.living_room_thermostat', 'current_temperature')|int) < (state_attr('climate.living_room_thermostat', 'temperature')|int) or                                                                                       
             (state_attr('climate.bedroom_thermostat', 'current_temperature')|int) < (state_attr('climate.bedroom_thermostat', 'temperature')|int) or                                                                                               
             (state_attr('climate.ruby_bedroom_thermostat', 'current_temperature')|int) < (state_attr('climate.ruby_bedroom_thermostat', 'temperature')|int) or                                                                                     
             (state_attr('climate.guest_room_thermostat', 'current_temperature')|int) < (state_attr('climate.guest_room_thermostat', 'temperature')|int) or                                                                                         
             (state_attr('climate.sitting_room_thermostat', 'current_temperature')|int) < (state_attr('climate.sitting_room_thermostat', 'temperature')|int)                                                                                        
          }}                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                    
      heat_required_ensuite:                                                                                                                                                                                                                        
        friendly_name: "Heat Required - Ensuite"                                                                                                                                                                                                    
        value_template: "{{ (state_attr('climate.ensuite_thermostat', 'current_temperature')|int) < (state_attr('climate.ensuite_thermostat', 'temperature')|int) }}"                                                                               
                                                                                                                                                                                                                                                    
      heat_required_living_room:                                                                                                                                                                                                                    
        friendly_name: "Heat Required - Living Room"                                                                                                                                                                                                
        value_template: "{{ (state_attr('climate.living_room_thermostat', 'current_temperature')|int) < (state_attr('climate.living_room_thermostat', 'temperature')|int) }}"                                                                       
                                                                                                                                                                                                                                                    
      heat_required_bedroom:                                                                                                                                                                                                                        
        friendly_name: "Heat Required - Bedroom"                                                                                                                                                                                                    
        value_template: "{{ (state_attr('climate.bedroom_thermostat', 'current_temperature')|int) < (state_attr('climate.bedroom_thermostat', 'temperature')|int) }}"                                                                               
                                                                                                                                                                                                                                                    
      heat_required_ruby_bedroom:                                                                                                                                                                                                                   
        friendly_name: "Heat Required - Ruby Bedroom"                                                                                                                                                                                               
        value_template: "{{ (state_attr('climate.ruby_bedroom_thermostat', 'current_temperature')|int) < (state_attr('climate.ruby_bedroom_thermostat', 'temperature')|int) }}"                                                                     
                                                                                                                                                                                                                                                    
      heat_required_guest_room:                                                                                                                                                                                                                     
        friendly_name: "Heat Required - Guest Room"                                                                                                                                                                                                 
        value_template: "{{ (state_attr('climate.guest_room_thermostat', 'current_temperature')|int) < (state_attr('climate.guest_room_thermostat', 'temperature')|int) }}"                                                                         
                                                                                                                                                                                                                                                    
      heat_required_sitting_room:                                                                                                                                                                                                                   
        friendly_name: "Heat Required - Sitting Room"                                                                                                                                                                                               
        value_template: "{{ (state_attr('climate.sitting_room_thermostat', 'current_temperature')|int) < (state_attr('climate.sitting_room_thermostat', 'temperature')|int) }}"

Thanks all,
Dim

  1. You could definitely use the values from the individual sensors for the global sensor.
  2. The values for all those attributes are already numbers, so the int filters are unnecessary:
sensor:                                                                                                                                                                                                                                             
  - platform: template                                                                                                                                                                                                                              
    sensors:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
      heat_required:                                                                                                                                                                                                                                
        friendly_name: "Heat Required"                                                                                                                                                                                                              
        value_template: >-
          {{ ['sensor.heat_required_ensuite', 'sensor.heat_required_living_room', 'sensor.heat_required_bedroom',
          'sensor.heat_required_sitting_room', 'sensor.heat_required_ruby_bedroom', 'sensor.heat_required_guest_room'] 
          | select('is_state', true) | list | count | bool  }}
        availability_template: |
          {{ ['sensor.heat_required_ensuite', 'sensor.heat_required_living_room', 'sensor.heat_required_bedroom',
          'sensor.heat_required_sitting_room', 'sensor.heat_required_ruby_bedroom', 'sensor.heat_required_guest_room'] 
          | select('has_value') | list | count | bool }}

      heat_required_ensuite:                                                                                                                                                                                                                        
        friendly_name: "Heat Required - Ensuite"                                                                                                                                                                                                    
        value_template: "{{ state_attr('climate.ensuite_thermostat', 'current_temperature') < state_attr('climate.ensuite_thermostat', 'temperature') }}"                                                                               
                                                                                                                                                                                                                                                    
      heat_required_living_room:                                                                                                                                                                                                                    
        friendly_name: "Heat Required - Living Room"                                                                                                                                                                                                
        value_template: "{{ state_attr('climate.living_room_thermostat', 'current_temperature') < state_attr('climate.living_room_thermostat', 'temperature') }}"                                                                       
                                                                                                                                                                                                                                                    
      heat_required_bedroom:                                                                                                                                                                                                                        
        friendly_name: "Heat Required - Bedroom"                                                                                                                                                                                                    
        value_template: "{{ state_attr('climate.bedroom_thermostat', 'current_temperature') < state_attr('climate.bedroom_thermostat', 'temperature') }}"                                                                               
                                                                                                                                                                                                                                                    
      heat_required_ruby_bedroom:                                                                                                                                                                                                                   
        friendly_name: "Heat Required - Ruby Bedroom"                                                                                                                                                                                               
        value_template: "{{ state_attr('climate.ruby_bedroom_thermostat', 'current_temperature') < state_attr('climate.ruby_bedroom_thermostat', 'temperature') }}"                                                                     
                                                                                                                                                                                                                                                    
      heat_required_guest_room:                                                                                                                                                                                                                     
        friendly_name: "Heat Required - Guest Room"                                                                                                                                                                                                 
        value_template: "{{ state_attr('climate.guest_room_thermostat', 'current_temperature') < state_attr('climate.guest_room_thermostat', 'temperature') }}"                                                                         
                                                                                                                                                                                                                                                    
      heat_required_sitting_room:                                                                                                                                                                                                                   
        friendly_name: "Heat Required - Sitting Room"                                                                                                                                                                                               
        value_template: "{{ state_attr('climate.sitting_room_thermostat', 'current_temperature') < state_attr('climate.sitting_room_thermostat', 'temperature') }}"

Thanks! That’s exactly the sort of advice I was after.

Off to pull threads and learn more now.

I appreciate you taking the time to help.

1 Like