!include mqtt.yaml not working

I tried to put the mqtt in a separate .yaml file. so the config.yaml does not get too full.
So in my config.yaml I put:

mqtt: !include mqtt.yaml

I crated a file called

mqtt.yaml

- plattform: mqtt
  unique_id: Rasenbewässerung Hochbeet Nord
  name: "Rasenbewässerung Hochbeet Nord"
  state_topic: mqtt/irrigation/relay1/state
  command_topic: mqtt/irrigation/relay1/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
- platform: mqtt
  unique_id: Tropfbewässerung Terrasse
  state_topic: mqtt/irrigation/relay2/state
  command_topic: mqtt/irrigation/relay2/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
  name: "Tropfbewässerung Terrasse"
- platform: mqtt
  unique_id: Tropfbewässerung Haus
  state_topic: mqtt/irrigation/relay3/state
  command_topic: mqtt/irrigation/relay3/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
  name: "Tropfbewässerung Haus"
- platform: mqtt
  unique_id: Tropfbewässerung Hochbeet
  state_topic: mqtt/irrigation/relay4/state
  command_topic: mqtt/irrigation/relay4/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
  name: "Tropfbewässerung Hochbeet"
- platform: mqtt
  unique_id: Rasenbewässerung Terrasse
  state_topic: mqtt/irrigation/relay5/state
  command_topic: mqtt/irrigation/relay5/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
  name: "Rasenbewässerung Terrasse"
- platform: mqtt
  unique_id: Dummy Switch 6
  state_topic: mqtt/irrigation/relay6/state
  command_topic: mqtt/irrigation/relay6/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
  name: "Test Schalter  6"
- platform: mqtt
  unique_id: Rasenbewässerung rechts
  state_topic: mqtt/irrigation/relay7/state
  command_topic: mqtt/irrigation/relay7/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
  name: "Rasenbewässerung rechts"
- platform: mqtt
  unique_id: Schalter 8
  state_topic: mqtt/irrigation/relay8/state

upon checking the config it gives me the following error:

Invalid config for [mqtt]: expected dictionary for dictionary value @ data['mqtt']. Got [OrderedDict([('plattform', 'mqtt'), ('unique_id', 'Rasenbewässerung Hochbeet Nord'), ('name', 'Rasenbewässerung Hochbeet Nord'), ('state_topic', 'mqtt/irrigation/relay1/state'), ('command_topic', 'mqtt/irrigation/relay1/switch'), ('payload_on', '1'), ('payload_off', '0'), ('state_on', 'ON'), ('state_off', 'OFF')]), OrderedDict([('platform', 'mqtt'), ('unique_id', 'Tropfbewässerung Terrasse'), ('state_topic', 'mqtt/irrigation/relay2/state'), ('command_topic', 'mqtt/irrigation/relay2/switch'),.... (See /config/configuration.yaml, line 12).

What do I do??
Thanks for the answer.

You don’t put binary sensors using the mqtt platform under the mqtt: integration, they go under the binary_sensor: integration, likewise for sensors using the mqtt platform, they go under sensors:. Look at the examples:

Thanks.
The post you referring to explains about sensors. From what I understand and I’m more likely to refer to buttons.

MQTT Buttons

So that way I could exclude the in mqtt from config.yaml

button: !include mqtt.yaml?

Confused…

button: !include buttons.yaml

buttons.yaml:

- plattform: mqtt
  unique_id: Rasenbewässerung Hochbeet Nord
  name: "Rasenbewässerung Hochbeet Nord"
  state_topic: mqtt/irrigation/relay1/state
  command_topic: mqtt/irrigation/relay1/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"
- platform: mqtt
  unique_id: Tropfbewässerung Terrasse
  etc...

I did as suggested.

added in confog.yaml
button: !include buttons.yaml
created a new file called buttons.yaml

  unique_id: Rasenbewässerung Hochbeet Nord
  name: "Rasenbewässerung Hochbeet Nord"
  state_topic: mqtt/irrigation/relay1/state
  command_topic: mqtt/irrigation/relay1/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"

I get this as an error in chkconfig.

Invalid config for [button]: required key not provided @ data['platform']. Got None. (See /config/configuration.yaml, line 12).

:thinking:

  • platform is missing at the top. And remember: platform instead of plattform

I changed buttons.yaml to:

- platform: mqtt
  unique_id: Rasenbewässerung Hochbeet Nord
  name: "Rasenbewässerung Hochbeet Nord"
  state_topic: mqtt/irrigation/relay1/state
  command_topic: mqtt/irrigation/relay1/switch
  payload_on: "1"
  payload_off: "0"
  state_on: "ON"
  state_off: "OFF"

I get

Invalid config for [button.mqtt]: [state_topic] is an invalid option for [button.mqtt]. Check: button.mqtt->state_topic. (See ?, line ?).

in result. So i changed it back for now.

You have used invalid options. See the available ones in the docs:

I get it.
So by using the button configuration I cannot use the state topic.
Right now I am using the binary sensor where it is also possible to get state information displayed.
I guess I’d rather leave it in the config.yaml and do not exclude it into a separate file.

It has nothing to do with your includes. It’s that fact that buttons and binary_sensors have different configuration options.

So why can’t include them as a switch?
That is what I originally tried.

That way I can keep the state topic in my mqtt file. I would like to know so whether the mqtt switch actually changed to on or not. I do not seem to be able to do that by using buttons.

Would

Binary_sensors: !include buttons.yaml

Work?

You can’t make up integration options. You can only use the ones specified. So if it is an mqtt switch, use the mqtt switch options.

And you don’t use capital letters for the integration key.

So you could put valid button platform configs here:

buttons: !include buttons.yaml

Switch platforms here:

buttons: !include switches.yaml

Binary sensors here:

binary_sensors: !include switches.yaml

etc…

No you tried to include a binary sensor under the mqtt: integration using an include. Which I already explained. !include mqtt.yaml not working - #2 by tom_l