Generic Thermostat Helper Template Switch Help

I have been using Generic Thermostats to control radiator valves. I’m using an input_boolean helper to indicate if the generic thermostat conditions mean the radiator should be on or off and another input_boolean which is related to whether or not I actually want the heating to come on.

- platform: generic_thermostat
  name: b_temp
  unique_id: b_temp_av
  heater: input_boolean.b_state
  target_sensor: sensor.average_temp_bedroom
  min_temp: 17
  max_temp: 22
  cold_tolerance: 0.2
  hot_tolerance: 0
    seconds: 5
- id: srv_b
  alias: sRV_B
  - platform: state
    - input_boolean.b_state
    from: 'off'
    to: 'on'
  - platform: state
    - input_boolean.b_state
    from: 'on'
    to: 'off'
  - condition: state
    entity_id: input_boolean.heating_switch
    state: 'on'
  - service: '{% if is_state_attr(''climate.b_temp'', ''hvac_action'', ''heating'')
      %} switch.turn_off {% elif is_state_attr(''climate.b_temp'', ''hvac_action'',
      ''idle'') %} switch.turn_on {% endif %}'
    entity_id: switch.srv_bedroom
  initial_state: 'true'
  mode: restart
# turning the switch on closes the radiator valve

If the input_boolean.b_state turns on and I want the radiator to start warming the house (input_boolean.heating_switch is on) then my action checks the state attribute of the climate entity. If it’s already in ‘heating’ then the radiator valve switch will turn_off (or probably just remain off), so that the radiator valve stays open.

The reason I’ve done it this way is because when I turn the heating on/off, all my radiator valves run this respective automation, so they will open/close based on the generic thermostat but if I turn the heating off, all the switches will turn off and the valves will all open, to avoid any valves getting stuck closed.

I recently requested for the Generic Thermostat Integration to allow the use of input_booleans as the actuator switch but the merging to allow this was stopped by balloob and the recommendation is to use a Template Switch instead.

I created this setup many years ago and now trying to revisit it and remember my own logic is challenging (ever gone back to an excel spreadsheet and try to remember the formulas you set up!?) either way…


Could I have some guidance on how I could use a Template Switch to achieve the same? I do appreciate I could just keep this in YAML but if balloob says use a Template Switch seems something worth investigating.

- platform: template
      name: B State
      unique_id: b_state
      value_template: >
        {{ is_states('switch.srv_bedroom', 'on') }}
      availability_template: >
        {{ has_value('switch.srv_bedroom') }}
      - condition: template
        value_template: >
          {{ is_state('input_boolean.heating_switch', 'on') and is_state_attr('climate.b_temp', 'hvac_action', 'idle') }}
      - service: switch.turn_on
          entity_id: switch.srv_bedroom
      - condition: template
        value_template: >
          {{ is_state('input_boolean.heating_switch', 'on') and is_state_attr('climate.b_temp', 'hvac_action', 'heating') }}
      - service: switch.turn_off
          entity_id: switch.srv_bedroom
1 Like

Ah brill thank you! I didn’t realise you could put a condition into it. I’ll give it a go.

Turns out my input_boolean.b_state is in so many automations that it will take me quite a bit longer to test and I’m away for a week as of tomorrow.

I had to change name: to friendly_name: and the first is_states to is_state, just to clear some initial setup glitches.

One question, to help me debug behaviour - what causes the template to update? Would a state change of any entity update the template, or would it only be controlled by the climate helper? I’m wondering if I could expect the input_boolean.heating_switch going from ‘off’ to ‘on’ to have an affect on the state of the switch, depending on the climate attribute state.

switch.srv_bedroom is what causes the state of switch.b_state to update it’s state.

the climate helper will turn switch.b_state on or off depending on the temperature used for that helper.


1 Like