Need help (again) defining MQTT Connector triggers

Posted on
Sun Jan 23, 2022 8:39 am
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Need help (again) defining MQTT Connector triggers

Hi @Joe,

Hope everything is ok with you and your family in these crazy world pandemic we are going through.

Sorry to bother with what may be caused by incapacity of properly understanding MQTT and how to correctly use your fantastic MQTT Connector plugin.

I have been working recently on trying to integrate z-wave devices that exist in Indigo with virtual devices that are automatically created in my Hubitat Elevation C-7 Hub (HE), by leveraging an MQTT App and Driver for Hubitat Elevation, created by user @kevin in the Hubitat Forums. Here is the link to it, in case you get curious: https://github.com/xAPPO/MQTT

Now, the MQTT App and Driver is capable of integrating devices both ways, meaning that it can publish devices created natively in HE into an MQTT Broker, to where other apps/systems/plugins can subscribe to in order to do it's stuff. It can also do it , the other way around, meaning the other system/app/plugin is responsible for the creation of topics which adhere to either the Homie or the Home Assistant schemas, where the App/Driver can get necessary info so it can automatically create virtual devices in HE.

I'm up to the point where I defined (a lot) of triggers in Indigo, that effectively create the topic structure adhering to the Homie Schema and Hubitat Elevation MQTT App/Driver can find the devices and it's capabilities and automatically create the needed virtual device counterpart in HE.

Now, the problem I'm facing is two-fold:
a) It's a LOT of triggers to create a single device, which I'm currently using as a proof of concept;
b) Once I'm satisfied with the results, I intend to integrate ALL of my current Indigo z-wave devices with HE, which would mean an absurd number of triggers if I do it the same way I've done for the proof of concept.

So I was hoping you are not too busy so you can point me in the right direction to make my triggers generic, as it's already hard to make sure everything goes into the right topic and I have only covered ONE z-wave device as I've done it... I can't shake the feeling that can't be right, because it's 30+ triggers for one device. There MUST be an easier/more efficient way of doing it.

I feel exhausted already as I have spent the whole day Yesterday trying to figure out the correct topic structure and I cannot believe I'm doing it the right way.

So, if you can, "Help me Obi Wan Kenobi, you are my only hope..."

Below are two screen grabs: a) of the topic structure and b) the incredible amount of triggers I have defined in order to have it in MQTT Explorer.

Thanks in Advance,
Cesar

a)
Screen Shot 2022-01-23 at 11.16.40.png
Screen Shot 2022-01-23 at 11.16.40.png (52.58 KiB) Viewed 2794 times


b)
Screen Shot 2022-01-23 at 11.37.37.png
Screen Shot 2022-01-23 at 11.37.37.png (287.27 KiB) Viewed 2794 times

Posted on
Sun Jan 23, 2022 12:48 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need help (again) defining MQTT Connector triggers

Let's step back and make sure I understand exactly what you're trying to do. If you're taking a device that's connected to or controlled by Indigo, and trying to "publish" it to HE via MQTT, I don't know why you'd be making triggers at all. Or maybe one trigger per device, that then publishes a bunch of MQTT messages that describe the state of the device.

What do all the triggers you have now actually do? What are the actions associated with them?

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

Posted on
Sun Jan 23, 2022 1:05 pm
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Re: Need help (again) defining MQTT Connector triggers

I could not find a way to add several sub-topics by using a single MQTT Publishing Template, so I created a trigger per subtopic, all under a common topic, which represents de Indigo device I'm trying to publish into the same MQTT Broker that the MQTT App/Driver access, in order to "learn" of foreign devices defined elsewhere (e.g.: Indigo).

So the device I'm trying to export is named "dimmer-escritorio". Since the MQTT App/Driver follow this quite obscure Homie Schema, I spent the whole of yesterday finding out the correct subtopics to publish into Mosquitto so the darn thing would "pick up". It's now working almost perfectly, as I can turn on/off/set brightness from Indigo and the current status change in Hubitat. The part that is missing is the other way around, which I presume should work as well, but is currently not working as I cannot set off/on/brightness from the Hubitat Dashboard and have the change be reflected in Indigo, but probably has nothing to do with the way I created the topic and subtopics in Mosquitto by using your MQTT Connector trigger facility. It's probably a bug somewhere in the Hubitat MQTT App/Driver and I have already reported it to it's author, which as luck would have it, is MIA for a few months in the Hubitat Forums...

So, what I'm doing is setting and individual trigger in Indigo that fires when something changes in the Indigo defined device that the trigger monitors FOR EACH subtopic in the Homie schema. I figure that can't be the best way, because I would need 30+ triggers for each device, which would result in an astonishing number of triggers I'm not willing to define in order to have this integration working.

I would be happy to do it programmatically in Python, but I don't have a clue how to start. If you would help me by providing an example, setting a topic and two or three subtopics, I can pickup from there and add the rest of the subtopics myself.

Best regards,
AND THANK YOU!!

Posted on
Sun Jan 23, 2022 1:26 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need help (again) defining MQTT Connector triggers

OK, let's take this one step at a time. Publishing Indigo devices to HE via MQTT. We won't touch the other direction at all at this time.

You're right, the publishing template was designed to produce a JSON payload, one payload per device. It's really not suitable for the Homie protocol.

Please show me the complete actions for a couple (just a couple) of the triggers you have defined. Are you using the MQTT Connector "Publish Message" action?

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

Posted on
Sun Jan 23, 2022 3:43 pm
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Re: Need help (again) defining MQTT Connector triggers

Thanks once again for your help.

FlyingDiver wrote:
Publishing Indigo devices to HE via MQTT


We won't be needing to touch the other side of things, as the duo comprised of the xAPPO/MQTT App and Driver + the Hubitat Plugin in the Indigo Plugin store take care of the integration from HE to Indigo, and that part is working very well.

FlyingDiver wrote:
Are you using the MQTT Connector "Publish Message" action?

Yes, please refer to screen grabs below to see what is being done.

The screen grabs below show two different Triggers I defined (among the 30+), showing the publishing of the TOPIC (dimmer-escritorio) and a sub-topic ($properties). The other 30+ triggers are similar to the sub-topic one, the only difference is the name of the sub-topic and the contents of the payload.

Disclaimer: I will try to order the screen grabs as expected, but with this Forum's attachment feature, you never know how they will end up showing...

Screen Shot 2022-01-23 at 18.33.06.png
Screen Shot 2022-01-23 at 18.33.06.png (44 KiB) Viewed 2750 times


Screen Shot 2022-01-23 at 18.32.54.png
Screen Shot 2022-01-23 at 18.32.54.png (229.52 KiB) Viewed 2750 times


Screen Shot 2022-01-23 at 18.39.34.png
Screen Shot 2022-01-23 at 18.39.34.png (44.01 KiB) Viewed 2750 times


Screen Shot 2022-01-23 at 18.39.13.png
Screen Shot 2022-01-23 at 18.39.13.png (234.09 KiB) Viewed 2750 times

Posted on
Sun Jan 23, 2022 4:36 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need help (again) defining MQTT Connector triggers

OK, I think I understand what's going on now.

First, you don't need a trigger for every topic. You only need a trigger for each state of the device that actually changes. Things like $name and $property don't change, so you'll never need to trigger on them. The only things that change on a standard dimmer device is the Brightness and On/Off state. So those would be the only triggers needed. You probably only need to send the metadata once on startup, or maybe once periodically for device discovery. I didn't see anything about that in the Homie docs I was looking at. I would probably use an Action Group for each device that sends all the metadata.

I would also use a single action group for the variable data for each device, and call that action group from all triggers for that device.

This would be so much easier in a script, but unfortunately even an external (background) script can't get device changed notifications. So it'll have to be a plugin. I'm going to see if I can put this into the Connector plugin as an alternative to the templates there now. It'll be a separate list of devices to publish Homie messages for.

Can you send (or post here) a TEXT list of all the messages you're sending for the one device you have implemented. I need the topic and the payload for each.

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

Posted on
Mon Jan 24, 2022 8:22 am
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Re: Need help (again) defining MQTT Connector triggers

FlyingDiver wrote:
I would probably use an Action Group for each device that sends all the metadata.

I would also use a single action group for the variable data for each device, and call that action group from all triggers for that device.

Can you send (or post here) a TEXT list of all the messages you're sending for the one device you have implemented. I need the topic and the payload for each.


Does the screen grab below show the correct way to set the single action group for discovery purposes? I'm sorry, I don't quite know how to handle multiple sub-topics in MQTT Connector...

Screen Shot 2022-01-24 at 11.17.59.png
Screen Shot 2022-01-24 at 11.17.59.png (149.54 KiB) Viewed 2705 times


TEXT FILE for topic/sub-topic schema:
Code: Select all
$name = dimmer-escritorio
/onoff = off
/onoff/$settable = true
/onoff/$name = Turned OFF
/onoff/$retained = true
/onoff/$datatype = boolean
/set = off
/$type = light
/$properties = onoff,dim
/-device-driver = Virtual Dimmer
/dim = off
/dim/$settable = true
/dim/$name = Dim Level 0
/dim/$retained = true
/dim/$datatype = integer
/dim/$format = 0:100
/dim/$unit = %
/set = 0


Does this answer your request for the list of messages I'm sending? Sorry for being such a noob.

Posted on
Mon Jan 24, 2022 9:30 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need help (again) defining MQTT Connector triggers

Actually, that's just about completely wrong. Sorry. It's one action per topic, and you put multiple actions in the action group. See the "Add new" button in the lower left of the dialog box? So, the first action would be to publish a message with the topic "homie/macpro/dimmer-escitorio/$name" and the payload "dimmer-escitorio". The second would be "homie/macpro/dimmer-escitorio/$settable" with payload "true". And so on. Note that there's no leading "/" in the topics. This is not a file path name.

Also, you don't send a topic ending in "/set". That's for commanding the device to turn on or off. You're not doing that.

I really think you would be better off waiting for Autolog to get the plugin further along, rather than trying to reproduce what the plugin is going to do with discrete Indigo actions.

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

Posted on
Mon Jan 24, 2022 11:17 am
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Re: Need help (again) defining MQTT Connector triggers

Got it! Thanks I will make needed changes and run some tests.

I agree. This is running circles around myself. :cry:
The main reason I'm doing it is for a proof of concept o my desired results, which are being able to control Indigo defined devices from Hubitat Elevation, as well as being able to control HE defined devices from Indigo, in both cases having status changes on one platform to be immediately reflected on the other, no matter in which of those two platforms the device being set was originally defined.
As a proof of concept, I think I got where I wanted and the results look very promising. I will have to wait for both @autolog and Kevin (the author of the MQTT App/Driver for Hubitat Elevation to make necessary changes. As it was originally, part of the solution was working as expected, but recent changes introduced by both authors trying to fulfill my needs resulted in a few new problems they are trying to solve between themselves.

Best regards and many thanks for you help.

Posted on
Mon Jan 24, 2022 2:00 pm
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Re: Need help (again) defining MQTT Connector triggers

I made the changes you recommended and am happy with the results. Not only it's much easier to publish initial data for each device by using Action Groups, it also makes updating changed values with triggers much simpler. Thanks again for your guidance.

On a side note, I sent a message to Kevin, the author of the Hubitat Elevation MQTT App/Driver documenting my findings on trying to integrate his App/Driver with data from my proof of concept which uses your excellent MQTT Connector Plugin. It has become much clearer now and I think he must be able to find eventual bugs in his App/Driver with ease.

Once his App/Driver are (hopefully) fixed. Then I will keep on interacting with Jon's (@autolog), as he finds the best way of updating his also excellent Indigo Hubitat Bridge Plugin, with enhancements brought out by our back and forth messages here.

Posted on
Thu Jan 27, 2022 3:24 pm
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Re: Need help (again) defining MQTT Connector triggers

Hey Joe,

Would it be possible to have the contents of %%d:99999999:onOffState%% in the Payload of a Publish Message Action somehow converted to all lowercase?

I have my triggers all working now, as per your recommendations above.

The only thing missing is that the above payload returns either True or False, with the first letter capitalized.
I understand this output is produced by the IOM, but thought I would ask if you know of any form of syntax that would produce the desired all lowercase results: either true or false.

TIA,
Cesar

Posted on
Thu Jan 27, 2022 3:40 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need help (again) defining MQTT Connector triggers

Not that I know of. It's a strict substitution.

You could have a trigger for that device state changing, which runs a one-line Python script that does a tolower() on the state and puts it in an Indigo variable. Convoluted, but it should work.

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

Posted on
Thu Jan 27, 2022 3:41 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Need help (again) defining MQTT Connector triggers

Actually, you don't even need to use Python. One trigger for when the device state becomes true, one for when it becomes false, both writing the appropriate string to a variable.

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

Posted on
Thu Jan 27, 2022 5:10 pm
cesarvog offline
User avatar
Posts: 155
Joined: Aug 13, 2016
Location: Brazil

Re: Need help (again) defining MQTT Connector triggers

Many thanks. Will try and report back.

UPDATE: Got it. Setting a variable with the onOffState converted to lower() cleared the issue. :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests