MQTT Light by include

I changed machines and did a fresh install. And all all my MQTT lights have disappeared after I copied my yaml files to the new computer … The lights no long show up as entities.

They work if I define them directly in the config file. However, moving them in separate include file breaks it. Right now I’m assuming that they’ve changed something and I need rework the include but I’m not sure how.

My old files look like this, any suggestions?

from my configuration.yaml

light: !include x_x/lights.yaml

from my x_x/lights.yaml

- platform: mqtt
  name: 'testlight'
  command_topic: "indoors/testlight"
  payload_on: 1
  payload_off: 0

As for Zigbee2MQTT: If you have not deleted HA on the old device look for the following 2 files inside /usr/share/hassio/share/zigbee2mqtt:

  • database.db
  • devices.yaml

Stop Z2M on the new computer and copy above 2 files to /usr/share/hassio/share/zigbee2mqtt. Good pratice is always to backup the original files.

Now start Z2M. All your devices should reappear.

I’m not using Zigbee, but thanks anyway

mqtt config chabged a while ago from

light:
  - platform: mqtt (etc etc)

to

mqtt:
  - platform: light (etc etc)

No that wasn’t it. It gives this error when I change the platfrom to light -

Configuration invalid!

 Invalid config for [mqtt]: expected dictionary for dictionary value @ data['mqtt']. Got [{'platform': 'light', 'name': 'Office Light RGB', 'command_topic': 'office/rgb1/light/switch', 'payload_on': 'ON', 'payload_off': 'OFF'}]. (See /config/configuration.yaml, line 13).

I’ve also noticed that when I define MQTT lights in the Config file they’re not exposed to the Emulated Hue. My other lights YEE and WiZ work fine with it.

in configuration.yaml:

mqtt: !include mqtt.yaml

in mqtt.yaml :

  light:
    name: 'testlight'
    command_topic: "indoors/testlight"
    payload_on: 1
    payload_off: 0

No that didn’t work either

Follow the instructions for Default Schema as explained in the documentation for the MQTT Light integration. Initially, follow the instructions to configure a single light in configuration.yaml. Only after you have succeeded, proceed to move the light’s configuration to a separate file. After you have confirmed it (still) works, proceed to add all of your other lights to it.

Same results -

I rewrote the single config file using the “Default Schema” and the light worked.
I moved it to a include file and the light didn’t work.

Want I need is verification that I have the exact syntax correct for the include file.

As a note - The emulated / Alexia issue was firewall related. Fully disabling the firewall the emulated hue working but didn’t change anything else.

But you haven’t given your syntax

First off, thanks for all the help so far …

I had posted it my original question. But I’ll go over it again.

This worked on my previous install, it was about 2.5 - 3 yrs old.

previous install:

configuration.yaml

light: !include x_x/light.yaml

light.yaml


- platform: mqtt
  name: Bed
  command_topic: "yee/bed"
  payload_off: "0"
  payload_on: "1"

Since then I’ve tried the other suggestions posted, but nothing seems to work.

Other things I’ve tried

Try 1:

configuration.yaml

mqtt: !include x_x/light.yaml

Light.yaml

- platform: light
  name: Bed
  command_topic: "yee/bed"
  payload_off: "0"
  payload_on: "1"

Try 2:

configuration.yaml

mqtt: !include x_x/light.yaml

Light.yaml

  light:
	name: bed
	command_topic: "yee/bed"
	payload_on: 1
	payload_off: 0

Thanks agian

configuration.yaml:

mqtt:
  light: !include x_x/light.yaml

light.yaml:

- name: bed
  command_topic: "yee/bed"
  ...

That helps to identify the step causing the failure.

I believe your second try (“Try 2”) came very close except for the format of the contents in light.yaml (entities under the light key word must be formatted as a list).

Anyway, you fix that (i.e. add a hyphen before name: to indicate it’s a list item) or use Troon’s suggestion to employ a separate file for each MQTT-based entity platform.

Troons suggestion didn’t work either. It gave me the following error.

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

Neither the documentation or Troon’s example includes a reference to platform. Post exactly what you entered under the mqtt: key in configuration.yaml and within the x_x/light.yaml file.

Troons suggestion does work. I missed that first MQTT tag. (the tag light wasn’t a sub element / nested)

But on a side note, it really did say platform error =)

Thanks again for the help