Home Assistant MQTT Discovery

Posted on
Wed Apr 22, 2020 6:00 am
Hackencrash offline
User avatar
Posts: 251
Joined: Dec 16, 2015
Location: UK

Home Assistant MQTT Discovery

I'm trying to get MQTT Discovery working in Home Assistant such that Indigo devices are automatically created in Home Assistant.

To do this, the Topic from this plugin needs to be in the format: <discovery_prefix>/<component>/<object_id>/config
where:
<discovery_prefix> : The prefix for the discovery topic, e.g. indigo
<component> : One of the supported MQTT components, eg. binary_sensor or light
<object_id> : The ID of the device where we could use the Indigo Device ID

See: https://www.home-assistant.io/docs/mqtt/discovery/

In the Indigo MQTT Broker Device config, we could set the Topic in the Device Publishing Template as:

Code: Select all
indigo/light/{{deviceId}}/config
(assuming we only had lights in our smart home setup)

Based on haavarda's work with dimmable devices, we would need to make the template Payload as:

Code: Select all
{‘name’: ‘{{name}}’, ‘unique_id’: ‘{{deviceId}}’,’state_topic’: ‘indigo/devices/{{deviceId}}/update’,’command_topic’: ‘indigo/devices/{{deviceId}}/command/set’,’brightness_state_topic’: ‘indigo/devices/{{deviceId}}/update’,’brightness_command_topic’: ‘indigo/devices/{{deviceId}}/command/brightness’,’state_value_template’: ‘{{ “on” if value_json.states.onOffState == "True" else "off" }}’,’brightness_value_template’: ‘{{value_json.states.brightnessLevel}}’,’qos’: 0,’payload_on’: ‘on’,’payload_off’: ‘off’}
If I make the above settings to the Device Publishing Template within Indigo, I get MQTT messages from Indigo similar to:

Message 1508 received on indigo/light/1121785643/config at 12:28 PM:
{‘name’: ‘Dining Room Desk Light’, ‘unique_id’: ‘1121785643’,’state_topic’: ‘indigo/devices/1121785643/update’,’command_topic’: ‘indigo/devices/1121785643/command/set’,’brightness_state_topic’: ‘indigo/devices/1121785643/update’,’brightness_command_topic’: ‘indigo/devices/1121785643/command/brightness’,’state_value_template’: ‘’,’brightness_value_template’: ‘’,’qos’: 0,’payload_on’: ‘on’,’payload_off’: ‘off’}
QoS: 0 - Retain: false

To get MQTT Discovery to work and automatically create devices in Home Assistant, I would need my Home Assistant configuration.yaml file to be similar to:

Code: Select all
# MQTT Broker
mqtt:
  broker: localhost
  port: 1883
  username: whatever
  password: foobar
  discovery: true
  discovery_prefix: indigo

mqtt_eventstream:
  publish_topic: homeassistant
  subscribe_topic: indigo/devices/#
The problem I have with this is that I am unable to put any conditional logic in the Device Publishing Template Topic to set the component to be anything other than light (in this example). For instance, I could say that if an Indigo device has a state "brightnessLevel" then this almost certainly is a light. Something like:

{{ “light” if value_json.states.hasOwnProperty(“brightnessLevel”) else “binary_sensor” }}

But this does not work.

Also, by modifying the Device Publishing Template, it appears to change every message sent from Indigo to Home Assistant. I was hoping perhaps as the name "Device Publishing Template" suggests that the Plugin would send out a list of all the Indigo devices that would then be modified by this template and then separately send out device update status messages as needed separately so that the device states, etc. are not filtered-out by the template and reach Home Assistant.

Please can you help me out here so that I can achieve this somehow? 8)

Posted on
Wed Apr 22, 2020 7:00 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

I gather you're set up to publish all devices? You're not publishing specifically listed devices?

If you only publish dimmer type devices, then it would work as is, correct?

Where did you get this syntax from?
Code: Select all
{{ “light” if value_json.states.hasOwnProperty(“brightnessLevel”) else “binary_sensor” }}

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 22, 2020 7:02 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

Also, the design intent was that if you need different templates for different devices, you set up an additional Connector devices for each device type, with it's own template.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 22, 2020 7:59 am
Hackencrash offline
User avatar
Posts: 251
Joined: Dec 16, 2015
Location: UK

Re: Home Assistant MQTT Discovery

Ah OK, I can see that working. Not completely automated as I had hoped but nevertheless seems like a very good solution which I am implementing now... :idea:

I will post the topics and payloads for each device type once I work them out. I am not sure how to get around combining the MQTT Discovery device creation in Home Assistant with updating the device states with one template (per device) but one thing at a time...
Last edited by Hackencrash on Wed Apr 22, 2020 8:05 am, edited 1 time in total.

Posted on
Wed Apr 22, 2020 8:01 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

Hackencrash wrote:
Ah OK, I can see that working. Not completely automated as I had hoped but nevertheless looks like a very good solution which I am implementing now... :idea:


Was your intention to publish ALL devices, or are you doing specific ones?

There's no way to filter devices at the publishing template level - by the time it's being processed it's too late. But I could add some additional filters other than all or listed (or not listed).

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 22, 2020 8:09 am
Hackencrash offline
User avatar
Posts: 251
Joined: Dec 16, 2015
Location: UK

Re: Home Assistant MQTT Discovery

Yes Home Assistant has specific device types like light, binary_sensor, switch, etc. and it would be good if there could be some way of mapping Indigo "Models" to Home Assistant "Components".

Posted on
Wed Apr 22, 2020 8:22 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

Hackencrash wrote:
Yes Home Assistant has specific device types like light, binary_sensor, switch, etc. and it would be good if there could be some way of mapping Indigo "Models" to Home Assistant "Components".


There's no way to do a mapping in the MQTT plugin, because it doesn't know that you're sending to HA. As I said, the right way to do that is to set up multiple connector devices, one for each specific topic/payload template you need to use.

I could add some code to make it easier to specify the group of devices you're going to publish.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 22, 2020 9:01 am
Hackencrash offline
User avatar
Posts: 251
Joined: Dec 16, 2015
Location: UK

Re: Home Assistant MQTT Discovery

Currently I'm torn between setting-up multiple MQTT Broker devices in Indigo per device type (as you suggest) and creating an automation template in Home Assistant to do the Indigo topic formatting instead. I know your solution will work and be achieved relatively quickly but the other solution potentially could be completely automated, but then may prove too complicated to be worthwhile and may need maintaining as new Indigo device model values appear with new plugins - your thoughts?...

Posted on
Wed Apr 22, 2020 9:14 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

I haven't spent enough time in HA to have an opinion. Sorry.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 22, 2020 9:21 am
Hackencrash offline
User avatar
Posts: 251
Joined: Dec 16, 2015
Location: UK

Re: Home Assistant MQTT Discovery

OK what would be useful for me is if the MQTT plugin exposed the Indigo device class for each device (DimmerDevice, RelayDevice, etc.) as per https://wiki.indigodomo.com/doku.php?id ... _reference

This would make it very easy for me then to map this against the Home Assistant equivalents for creating these Indigo devices in Home Assistant (and vice versa perhaps?)

Posted on
Wed Apr 22, 2020 9:22 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

Hackencrash wrote:
OK what would be useful for me is if the MQTT plugin exposed the Indigo device class for each device (DimmerDevice, RelayDevice, etc.) as per https://wiki.indigodomo.com/doku.php?id ... _reference

This would make it very easy for me then to map this against the Home Assistant equivalents for creating these Indigo devices in Home Assistant (and vice versa perhaps?)


Exposed how? Made available to the topic/payload templates? I think I can do that.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 22, 2020 9:28 am
Hackencrash offline
User avatar
Posts: 251
Joined: Dec 16, 2015
Location: UK

Re: Home Assistant MQTT Discovery

Yes that would be ideal

Posted on
Wed Apr 22, 2020 9:31 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

I'll look into it. I have a funny feeling this is not going to be as simple as you'd like.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Apr 22, 2020 10:23 am
Hackencrash offline
User avatar
Posts: 251
Joined: Dec 16, 2015
Location: UK

Re: Home Assistant MQTT Discovery

The big picture is to integrate Android and iPhones together using your plugin, so you can say "Hey Siri" or "OK Google" and control all devices the same.

I have all my devices in Indigo as the central hub and getting Siri to work was easy - Homebridge.

To use Google Android, I will need to create replicas of all the Indigo devices in Home Assistant via MQTT and subsequently link this to Google Home Assistant for OK Google speech control to work.

I also plan to use Home Assistant to get the odd device that Indigo doesn't support to appear as an Indigo device via Shims, but this is only going to be one or two devices so I don't need to automate device creation the other way en-masse - these devices can be created in Indigo manually.

I want to be able to create a device once in Indigo and for that to be automatically visible via Google.

No more phone wars, everything is just a device that works!

Posted on
Thu Apr 23, 2020 3:25 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Home Assistant MQTT Discovery

Have you looked at using the new HassBridge plugin instead of rolling your own?

viewtopic.php?f=134&t=23796

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Who is online

Users browsing this forum: No registered users and 2 guests