Toggle template gives invalid configuration

I am new so hopefully just a lack of comprehension.

I have an electronic gate with two relays controlled and a sensor for closed by ESPHOME nodemcu.
I have two buttons in home assistant, one for open and one for close.
The above works.

I want one button that will toggle the gate either closed or open so i can add it to single push button.
I read that what i think i want is a template. I wrote this

# Example configuration.yaml entry
switch:
  - platform: template
    switches:
      GateToggle:
        value_template: "{{ is_state('binary_sensor.driveway_gate_2', 'on') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: switch.gate_open_2
        turn_off:
          service: switch.turn_on
          target:
            entity_id: switch.gate_close_2

But when i paste this into my confgiuration.yaml


# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# custom toggle template for the garage
switch:
  - platform: template
    switches:
      GateToggle:
        value_template: "{{ is_state('binary_sensor.driveway_gate_2', 'on') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: switch.gate_open_2
        turn_off:
          service: switch.turn_on
          target:
            entity_id: switch.gate_close_2

and then go to developer tools, YAML, Check configuration i get this:

Invalid config for [switch.template]: invalid slug GateToggle (try gatetoggle) for dictionary value @ data[‘switches’]. Got OrderedDict([(‘GateToggle’, OrderedDict([(‘value_template’, “{{ is_state(‘binary_sensor.driveway_gate_2’, ‘on’) }}”), (‘turn_on’, OrderedDict([(‘service’, ‘switch.turn_on’), (‘target’, OrderedDict([(‘entity_id’, ‘switch.gate_open_2’)]))])), (‘turn_off’, OrderedDict([(‘service’, ‘switch.turn_on’), (‘target’, OrderedDict([(‘entity_id’, ‘switch.gate_close_2’)]))]))]))]). (See ?, line ?).

The see ? line? isn’t helpful to me.
I know that switch.gate_open_2 and switch.gate_close_2 and binary_sensor.driveway_gate_2 are all valid entities(?) i’m ote sure what GateToggle is, that’s what i’d like this new ‘switch’ to be called.

Am i making sense?

The ID of your switch needs to be configured as a slug (all lower case, no punctuation except _, no spaces)…

switch:
  - platform: template
    switches:
      gatetoggle:
        value_template: ......
1 Like

Thanks, that’s got me through!