Template switch with several targets

Hi,

I want to create a template switch with several entities as target.

I tried the following code:

switch:
  - platform: template
    switches:
      heizung_eg_heat:
        turn_on:
          service: switch.turn_on
          target:
            - entity_id: switch.heizung_eg_a8_relay1
            - entity_id: switch.heizung_eg_a8_relay2
        turn_off:
          service: switch.turn_off
          target:
            - entity_id: switch.heizung_eg_a8_relay1
            - entity_id: switch.heizung_eg_a8_relay2
            - entity_id: switch.heizung_eg_a8_relay3
            - entity_id: switch.heizung_eg_a8_relay4
            - entity_id: switch.heizung_eg_a8_relay5
            - entity_id: switch.heizung_eg_a8_relay6

But I get as error the following:

Logger: homeassistant.components.hassio
Source: components/hassio/__init__.py:586
Integration: Home Assistant Supervisor (documentation, issues)
First occurred: 11:36:08 (1 occurrences)
Last logged: 11:36:08

The system cannot restart because the configuration is not valid: Invalid config for [switch.template]: expected a dictionary for dictionary value @ data['switches']['heizung_eg_heat']['turn_off'][0]['target']. Got None expected a dictionary for dictionary value @ data['switches']['heizung_eg_heat']['turn_on'][0]['target']. Got None. (See ?, line ?). 

Can someone tell me what is wrong? Or is that not possible and I can only do that via grouping the elements before into one entity ?

Thank you in advance.

Greets Karl

You only need a single entity_id key for each service, then list the entity IDs below that… Also, you need a value template:

switch:
  - platform: template
    switches:
      heizung_eg_heat:
        value_template: |-
          {{ is_state('switch.heizung_eg_a8_relay1', 'on') and 
          is_state('switch.heizung_eg_a8_relay2', 'on') }}
        turn_on:
          service: switch.turn_on
          target:
            entity_id: 
              - switch.heizung_eg_a8_relay1
              - switch.heizung_eg_a8_relay2
        turn_off:
          service: switch.turn_off
          target:
            entity_id: 
              - switch.heizung_eg_a8_relay1
              - switch.heizung_eg_a8_relay2
              - switch.heizung_eg_a8_relay3
              - switch.heizung_eg_a8_relay4
              - switch.heizung_eg_a8_relay5
              - switch.heizung_eg_a8_relay6

sometimes it is really easy - but now it is clear.

Thank you.

What for is the value template in the code ? I thought it is optional.