Can't split my config for switches

Very new to this and have been trying to split my switches into their own file but keep getting the an “Invalid Config - The following components and platforms could not be setup - switch” error

I have created a switches.yaml file in the config folder (same location as the configuration.yaml, automation.yaml etc etc) and have added switch: !include switches.yaml to the configuration.yaml file with the rest of the includes but keep getting the above error each reboot.

group: !include groups.yaml
switch: !include switches.yaml
automation: !include automations.yaml
script: !include scripts.yaml

Any ideas? I have looked at others config and switches files and have even imported the switches.yaml file and copied pasted from others config (just in case i had a space or something wrong) but no luck.

can you post a copy of your switch.yaml? It could be that the format of that file is incorrect and preventing it from loading.

The file is empty at the moment but have also tried it with the following code

#MQTT switch
switch:
- platform: mqtt
  name: gate
  state_topic: "/ESP_Easy/cmd"
  command_topic: "/ESP_Easy/cmd"
  payload_on: "Relay,0,1"
  payload_off: "Relay,0,1"

I’m currently doing it. Here’s my config:

...
zone: !include zones.yaml
group: !include group.yaml
script: !include scripts.yaml
switch: !include switch.yaml
...

and my switch.yaml .

  - platform: template
    switches:
        # INSIDE LIGHTS SWITCH
        inside:
          value_template: "{{ is_state('group.inside','on') }}"
          turn_on:
            service: homeassistant.turn_on
            data:
              entity_id: group.inside
          turn_off:
            service: homeassistant.turn_off
            data:
              entity_id: group.inside
   ... etc...

your problem is that you are including the switch, but then you add the word switch again. Get rid of the second switch: inside the file.

Your file should look like this:

#MQTT switch
- platform: mqtt
  name: gate
  state_topic: "/ESP_Easy/cmd"
  command_topic: "/ESP_Easy/cmd"
  payload_on: "Relay,0,1"
  payload_off: "Relay,0,1"

Understand the issue and thanks for your help.

Updated my error and tested it and confirms it solves my problem. Thank you…

Should it work with an empty file tho or does it need data in it to work?

Not sure about that one.

Reason I ask is I have a group: !include groups.yaml entry in my config and a groups.yaml file that is empty but it does not error like the switches one did.