Invalid config for [switch]: required key not provided @ data['platform']. Got None

Hello,

since the update 2022.12.1 i cant reach my “openMQTTgateway” entities. i am controlling my 433mhz switches.
without changing anything i did get no issues, but also not the entities that i had before.

in configuration.yaml i do: switch: !include switches.yaml
and in switches.yaml i changed this:

- platform: mqtt
  name: Strom
  icon: mdi:power-socket-de
  state_topic: home/OpenMQTTGateway/433toMQTT
  command_topic: home/OpenMQTTGateway/commands/MQTTto433
  payload_on: '{"value":17745,"protocol":1,"length":24,"delay":313}'
  payload_off: '{"value":17748,"protocol":1,"length":24,"delay":313}'
  optimistic: "true"
  qos: 1
  retain: false

to this:

mqtt: 
  switch:
    - name: Strom
      icon: mdi:power-socket-de
      state_topic: home/OpenMQTTGateway/433toMQTT
      command_topic: home/OpenMQTTGateway/commands/MQTTto433
      payload_on: '{"value":17745,"protocol":1,"length":24,"delay":313}'
      payload_off: '{"value":17748,"protocol":1,"length":24,"delay":313}'
      optimistic: "true"
      qos: 1
      retain: false

according to the documentation of mqtt.
now i get the issue “Invalid config for [switch]: required key not provided @ data[‘platform’]. Got None.”

what do i wrong?

You are using to many keys switch->mqtt->switch
In your configuration.yaml you should use: mqtt: !include mqtt.yaml
Create the file mqtt.yaml and put in the entities you want. For example your switch:

  switch:
    - name: Strom
      icon: mdi:power-socket-de
      state_topic: home/OpenMQTTGateway/433toMQTT
      command_topic: home/OpenMQTTGateway/commands/MQTTto433
      payload_on: '{"value":17745,"protocol":1,"length":24,"delay":313}'
      payload_off: '{"value":17748,"protocol":1,"length":24,"delay":313}'
      optimistic: "true"
      qos: 1
      retain: false

ok, thank you for your reply,

i try this.
there have been changed something in HA at the update to 2022.12.1. And i don´t know what to solve it. everything has worked fine before.

thank you.

so,

the issue is solved. the entities can be founded now but they don´t work. when i click on them, there is no reaction. thats not easy… why do they change working things… damn…

Did you check if the mqtt broker is working and with a mqtt broker tool, you could check if messages are sent from HA.

Hey,

yesterday i did first the programming like you told me. then i had no reaction. after that i did the update to the latest HA version. now the same: no entities anymore and this issue comes:
“Invalid config for [mqtt]: [mqtt] is an invalid option for [mqtt]. Check: mqtt->mqtt->mqtt.”
in configuration.yaml i have this: mqtt: !include mqtt.yaml
filename is correct.

How does the content of your file mqtt.yaml looks like?

it looks like this:

# MQTT Geräte  
mqtt:
  broker: http://IP_ADRESSxxx.xxx.xxx.xx
  username: usernamexxx
  password: passwordxxx


sensor: 
  - state_topic: "kellertuer"
    name: "Kellertür"
  - state_topic: "Waschm_Test"
    name: "Waschmaschie_test"

# Steckdose Strom "A"
switch: 
  - name: Strom
    icon: mdi:power-socket-de
    state_topic: home/OpenMQTTGateway/433toMQTT
    command_topic: home/OpenMQTTGateway/commands/MQTTto433
    payload_on: '{"value":17745,"protocol":1,"length":24,"delay":313}'
    payload_off: '{"value":17748,"protocol":1,"length":24,"delay":313}'
    optimistic: "true"
    qos: 1
    retain: false
    
# Steckdose Beleuchtung "B"
  - name: Beleuchtung
    icon: mdi:power-socket-de
    state_topic: home/OpenMQTTGateway/433toMQTT
    command_topic: home/OpenMQTTGateway/commands/MQTTto433
    payload_on: '{"value":20817,"protocol":1,"length":24,"delay":313}'
    payload_off: '{"value":20820,"protocol":1,"length":24,"delay":313}'
    optimistic: "true"
    qos: 1
    retain: false
  
# Steckdose Vitrine "C"
  - name: Vitrine
    icon: mdi:power-socket-de
    state_topic: home/OpenMQTTGateway/433toMQTT
    command_topic: home/OpenMQTTGateway/commands/MQTTto433
    payload_on: '{"value":21585,"protocol":1,"length":24,"delay":313}'
    payload_off: '{"value":21588,"protocol":1,"length":24,"delay":313}'
    optimistic: "true"
    qos: 1
    retain: false
  
# Steckdose Dekolicht "D"
  - name: Dekolicht
    icon: mdi:power-socket-de
    state_topic: home/OpenMQTTGateway/433toMQTT
    command_topic: home/OpenMQTTGateway/commands/MQTTto433
    payload_on: '{"value":21777,"protocol":1,"length":24,"delay":313}'
    payload_off: '{"value":21780,"protocol":1,"length":24,"delay":313}'
    optimistic: "true"
    qos: 1
    retain: false

btw: the mqtt broker works fine

The whole mqtt part needs to be deleted:

mqtt:
  broker: http://IP_ADRESSxxx.xxx.xxx.xx
  username: usernamexxx
  password: passwordxxx

The mqtt broker is configured in the mqtt integration (settings->Integrations->).

it doesn’t matter if its in or deleted. same issue. i think HA doesn’t accept this including for mqtt, does it?

HA does except !include for mqtt!
You can’t leave the mqtt settings part in the file mqtt.yaml, because when the configurations files are merged on startup, you get the double mqtt key and the integration or manual configured devices will not load.

Do you have the mqtt integration installed and working? (see setting->integrations)

Several releases ago the MQTT integration deprecated the old style of specifying entities for an integration. By old style I mean putting the config for those entities under the type of entity (like switch) with a platform key. Essentially doing this was deprecated:

switch:
- platform: mqtt
  name: Strom
  ...

You should’ve seen repairs warning you about this for a number of releases. Recently the deprecation reached end of life, you can no longer specify mqtt entities in that deprecated style. You now must migrate to the new configuration and specify all mqtt entities under the integration key (mqtt). Like this:

mqtt:
  switch:
    - name: Strom
      ...

See here for all config details and examples so you can see how to migrate everything.

Also @bertreb is right, having these details in your configuration.yaml does nothing now:

You now configure the broker details in the UI. Any YAML you had specifying those details has been migrated to a config entry and is now entirely managed in the UI. Specifying those details in YAML is deprecated and can be safely removed (since it does nothing now). You have a repair telling you this as well. If you ignore it then eventually that deprecation will also reach end-of-life and in a future release HA will fail to start with an invalid config.

thank you.
i deleted the mqtt settings in configuration.yaml.
so i tried to put the switch directly in configuration.yaml according to the mqtt switch documentation. and now it works.
looks like this:

# Steckdose Strom "A"
mqtt: 
  switch: 
    - name: Strom
      icon: mdi:power-socket-de
      state_topic: home/OpenMQTTGateway/433toMQTT
      command_topic: home/OpenMQTTGateway/commands/MQTTto433
      payload_on: '{"value":17745,"protocol":1,"length":24,"delay":313}'
      payload_off: '{"value":17748,"protocol":1,"length":24,"delay":313}'
      optimistic: "true"
      qos: 1
      retain: false

try to outsourcing mqtt or switch, both dont work. Its always the same issue as the topic of this thread.

So this works right?

What is the change you’re trying to make to this which causes an error? What file are you trying to move this switch to and how is that file connected to configuration.yaml via !include?

yes, thats the way it works.

i tried to put this in file mqtt.yaml or switches.yaml and both caused the issue.
and i tried to load it via !include.
for me its ok now, because it works and i dont have so many things in configuration.yaml so its still clear.
but it would be very interesting which way it has to be outsourced to make it work.

The way !include works is by inserting the contents of the referenced file in that spot. So let’s say you dropped the exact yaml you showed earlier into a file called mqtt.yaml (shortened to simplify):

mqtt: 
  switch: 
    - name: Strom
      ...

And then let’s say you put this in configuration.yaml:

mqtt: !include mqtt.yaml

That’s the exact same thing as putting this in your configuration.yaml:

mqtt:
  mqtt: 
    switch: 
      - name: Strom
        ...

Obviously that’s not correct. It’s different then what you had in configuration.yaml before, mqtt is in there twice.

I don’t know what you put in configuration.yaml when you tried to use !include because you didn’t show me. But whenever you use !include that’s how it works. The only actual config file is configuration.yaml, when you use !include HA assembles the real file by copying the contents of files into that spot. If your config doesn’t make sense when you do that then something is incorrect.

Ok. That makes sense. Thank you for the explanation.
I will play around and try to make it work with !include

1 Like

Hey again,

I did it like you explained, now it works also with !include.

Thanks a lot.