How to create custom component?

Just getting started here trying to create some custom components. I read the examples, but did not find them especially helpful.

I thought the best way to get started would be to modify an existing component, so I went to github and got the source for MQTT Light and placed it in my custom_components/light directory in a file named my_mqtt.py

I modified my yaml file which already had a working mqtt light entry and just changed the platform line from mqtt to my_mqtt like this:

light:
  platform: my_mqtt
  command_topic: "office/rgb1/light/switch"

Upon restarting hass, my home-assistant.log file has this cryptic error message:

16-09-07 06:09:06 homeassistant.bootstrap: Invalid config for [light.my_mqtt]: not a valid value for dictionary value @ data['platform']. Got 'my_mqtt'

Any clue what I might be missing?

We are using voluptuous to validate the configuration. It requires the platform to be ‘mqtt’, and not ‘my_mqtt’

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/mqtt/init.py#L110

The configuration validation needs to be adjusted.

I suggest that you start with the example sensor or another simple sensor platforms.

Thanks for the reply.

I’ll look at that and see whether I can figure it out.

Unfortunately there is a big leap from the examples to the sort of stuff I am interested in doing, but perhaps I didn’t choose the best place to start

1 Like