Switch for Generic Thermostat

I have two generic thermostats which i would like to control with a switch. Basically i would like to use one switch to change the mode of both thermostats from off to heat. Seems simple but i cannot find a solution. Thanks for any help.

The turn_on and turn_off options can be lists of actions to perform.

Thanks for your help and the rapid response.
I don’t quite understand. I want to create a switch that I can include in a dashboard that will change the mode of two generic thermostats from off to heat. Below is the yaml; code for one of the thermostats:

# Office Fan heater
    # HASSIO platform 
  - platform: generic_thermostat
    # Thermostat name
    name: office_fan_thermostat
    # Switch entity to be controlled
    heater: switch.office_fan
    # Temperature sensor entity
    target_sensor: sensor.lumi_lumi_weather_09c74404_temperature
    # Set minimum set point available.
    min_temp: 15
    # Set maximum set point available.
    max_temp: 17
    # Set the switch specified in the heater option to be treated as a cooling device instead of a heating device.
    ac_mode: false
    # Set initial target temperature.
    target_temp: 16
    # Set a minimum amount of difference between the temperature read by the sensor specified in the target_sensor option and the target temperature that must change prior to being switched on.
    cold_tolerance: 0.0
    # Set a minimum amount of difference between the temperature read by the sensor specified in the target_sensor option and the target temperature that must change prior to being switched off.
    hot_tolerance: 0.3
    # Set a minimum amount of time that the switch specified in the heater option must be in its current state prior to being switched either off or on.
    min_cycle_duration:
        seconds: 5
# Set a keep-alive interval if required
#    keep_alive:
#      minutes: 3
#    initial_hvac_mode: "off"
    # Set the temperature used by preset_mode: away.
    away_temp: 5
    # The desired precision for this device.
    precision: 0.1

You create the template switch and put it in your dashboard.

switch:
  - platform: template
    switches:
      heat_mode:
        friendly_name: Heat Mode
        value_template: "{{ is_state('climate.your_first_one_here', 'heat') and is_state('climate.your_second_one_here', 'heat') }}"
        turn_on:
          - service: climate.set_hvac_mode
            target:
              - entity_id: 
                  - climate.your_first_one_here
                  - climate.your_second_one_here
            data:
              hvac_mode: 'heat'
        turn_off:
          - service: climate.set_hvac_mode
            target:
              - entity_id: 
                  - climate.first_one_here
                  - climate.second_one_here
            data:
              hvac_mode: 'off'

I tried this:

switch:
  - platform: template
    switches:
      heat_mode:
        friendly_name: Heat Mode
      value_template: "{{ is_state('climate.office_thermostat', 'heat') and is_state('climate.office_fan_thermostat', 'heat') }}"
        turn_on:
          - service: climate.set_hvac_mode
            target:
              - entity_id: 
                  - climate.office_thermostat
                  - climate.office_fan_thermostat
            data:
              hvac_mode: 'heat'
        turn_off:
          - service: climate.set_hvac_mode
            target:
              - entity_id: 
                  - climate.office_thermostat
                  - climate.office_fan_thermostat
            data:
              hvac_mode: 'off'

But I get:

Configuration warnings
Invalid config for 'template' from integration 'switch' at configuration.yaml, line 1 31 : expected a dictionary for dictionary value 'switches->heat_mode-
>turn_on->0->targetI, got [{'entity_id': ['climate.office_thermostatl, 'climate.office_fan_thermostat']}]
Invalid config for 'template' from integration 'switch' at configuration.yaml, line 139: expected a dictionary for dictionary value 'switches->heat_mode-
>turn_off->0->target', got [Centity_idl: ['climate.office_thermostatl, 'climate.office_fan_thermostat']}]

Once again many thanks for your help.

Your indentation is wrong, see @tom_l for correct indentation :stuck_out_tongue:
image

Thanks. Corrected the indentation but still got the same error!

switch:
  - platform: template
    switches:
      heat_mode:
        friendly_name: Heat Mode
      value_template: "{{ is_state('climate.office_thermostat', 'heat') and is_state('climate.office_fan_thermostat', 'heat') }}"
        turn_on:
          - service: climate.set_hvac_mode
            target:
              entity_id: 
                - climate.office_thermostat
                - climate.office_fan_thermostat
            data:
              hvac_mode: 'heat'
        turn_off:
          - service: climate.set_hvac_mode
            target:
              entity_id: 
                - climate.office_thermostat
                - climate.office_fan_thermostat
            data:
              hvac_mode: 'off'

Got there! Thats great, many thanks for all your help.