# MQTT Hub/Gateway

**URL:** <https://community.homey.app/t/mqtt-hub-gateway/6766>\
**Category:** Apps\
**Created:** [January 14, 2019, 6:59pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766 "2019-01-14T18:59:50Z")\
**Posts on this page:** 20\
**Page:** 19

<div class="post-metadata">

**Author:** ![Viktor](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/viktor/32/8030_2.png) [@Viktor](https://community.homey.app/u/Viktor)\
**Post date:** [February 18, 2019, 7:46pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/366 "2019-02-18T19:46:13Z")

</div>

Hi @HarriedeGroot on/off is perfect for me atm, thank you very much.

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 18, 2019, 8:02pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/367 "2019-02-18T20:02:53Z")

</div>

👍 Color & dim/brightness should work also.

---

<div class="post-metadata">

**Author:** ![RobertP](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertp/32/3820_2.png) [@RobertP](https://community.homey.app/u/RobertP)\
**Post date:** [February 19, 2019, 4:41pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/368 "2019-02-19T16:41:38Z")

</div>

Hi HarriedeGroot,

sorry for asking, but again, I am new to MQTT.  
I now know that the MQTT Hub/Gateway will send all states to the broker (by means of the MQTT Client app) as soon as it connects to the broker (in this case, my app)

However, the Broker doesn’t have to be my app, but can also be another app (like Mosquitto).  
What if your app is already connected (and sent the status) to the Broker and I am connecting at a later time?  
How do we synchronize? Is there a special command I can send so you will broadcast all states again?  
Or does the broker needs to send all the cached data (belonging to the subscription)?.

I hope you understand my problem/question.

edit:  
For now, I will retain the messages in my own broker. But I just wondering about brokers that do not retain the messages.

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 19, 2019, 5:26pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/369 "2019-02-19T17:26:37Z")

</div>

@RobertP All messages are send with the retained flag. This means the broker will keep a copy of the last message for each topic & send this message on subscription. It’s part of the MQTT protocol.

Furthermore I still need to implement [birth & last will](https://www.home-assistant.io/docs/mqtt/birth_will/) messages for the hub.

---

<div class="post-metadata">

**Author:** ![RobertP](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertp/32/3820_2.png) [@RobertP](https://community.homey.app/u/RobertP)\
**Post date:** [February 22, 2019, 10:11am UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/370 "2019-02-22T10:11:13Z")

</div>

@HarriedeGroot, I am trying to set a value (switch light on), but I cannot get it to work.  
Topic: ‘homie/lamp-eethoek/onoff/set’  
Payload: ‘true’  
Retain: false  
QoS: AtMostOnce

I have all default in the two apps  
The MQTT Client has no setting activated  
The MQTT Hub has only DEVICEID=homie

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![xAPPO](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/xappo/32/13726_2.png) [@xAPPO](https://community.homey.app/u/xAPPO)\
**Post date:** [February 22, 2019, 2:01pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/371 "2019-02-22T14:01:06Z")

</div>

You look to be missing a topic hierarchy in your MQTT set comand - your Homey name.

homie/ **HomeyName** /lamp-eethoek/onoff/set

K

---

<div class="post-metadata">

**Author:** ![RobertP](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertp/32/3820_2.png) [@RobertP](https://community.homey.app/u/RobertP)\
**Post date:** [February 22, 2019, 2:18pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/372 "2019-02-22T14:18:49Z")

</div>

@xAPPO, but I do receive the Topic that way (without the HomeyName)  
It says in the settings that the HomeyName is optional (and I didn’t fill this in)  
I do receive: ‘homie/lamp-eethoek/onoff’

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/b/be80a64943d05c47a7e32a858a288880c30b5fbb.png)

---

<div class="post-metadata">

**Author:** ![dewenni](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dewenni/32/7912_2.png) [@dewenni](https://community.homey.app/u/dewenni)\
**Post date:** [February 22, 2019, 4:01pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/373 "2019-02-22T16:01:04Z")

</div>

> [@xAPPO](#):
>
> homie/ HomeyName/lamp-eethoek/onoff/ **set**

the “/set” is not necessary I think. But to be honest I am not really sure.  
I just tried this, but for me it also do not work. I can receive alle states but I am not able to set states.

I have tried the Homie Convention and also the Custom format.

---

<div class="post-metadata">

**Author:** ![xAPPO](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/xappo/32/13726_2.png) [@xAPPO](https://community.homey.app/u/xAPPO)\
**Post date:** [February 22, 2019, 4:21pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/374 "2019-02-22T16:21:09Z")

</div>

@dewenni If you are using the homie3 protocol to control devices in Homey then the set topic is mandatory. Also you do have a space between homie/ and HomeyName but that might be a typo.

[https://homieiot.github.io/specification/](https://homieiot.github.io/specification/)  
section 5.4.1

@RobertP I also suspect it maybe mandatory to use both ‘homie’ as the root topic and to have a Homey name set to adhere to the homie3 spec. You have the Homey name set as ‘homie’ and the homie root topic blank, which is bound to be challenging. Try it with both set and see if it works, if so then regress and see when it stops working.

N.B. In the homie3 spec `device ID` refers to your Homey - and a device within Homey has a `node ID`

K

---

<div class="post-metadata">

**Author:** ![RobertP](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertp/32/3820_2.png) [@RobertP](https://community.homey.app/u/RobertP)\
**Post date:** [February 22, 2019, 4:57pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/375 "2019-02-22T16:57:07Z")

</div>

> [@xAPPO](#):
>
> I also suspect it maybe mandatory to use both ‘homie’ as the root topic and to have a Homey name set to adhere to the homie3 spec. You have the Homey name set as ‘homie’ and the homie root topic blank, which is bound to be challenging. Try it with both set and see if it works, if so then regress and see when it stops working.
> 
> N.B. In the homie3 spec `device ID` refers to your Homey - and a device within Homey has a `node ID`

You are absolutely right!  
I added a root id to setting (‘Homey’) and now it works.  
You get: ‘Homey/homie/lamp-eethoek/onoff

Seems to me that the description of the setting should be changed. It is not optional at all if you want to set a value.  
(unless it is a bug)

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 22, 2019, 5:20pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/376 "2019-02-22T17:20:33Z")

</div>

I’ll check.

Currently working on a new version of the settings. Including options for HA discovery, topic normalization, birth & last will, etc.

---

<div class="post-metadata">

**Author:** ![RobertP](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertp/32/3820_2.png) [@RobertP](https://community.homey.app/u/RobertP)\
**Post date:** [February 22, 2019, 5:41pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/377 "2019-02-22T17:41:19Z")

</div>

Another issue/question.  
Check out the log below;  
At line 790 I set the dim value to 0.3  
The light dims (yeah! It works! 😃

But, however the light stays dimmed, I get the new state back with Payload=1

What is causing this?

EDIT:  
Got it. You should use Retain=true when you set a value.

> | 795 | 18:36:06.396 | 123 | MTTQ Client Local =\> From=f331881e5a004c6fa522f3a11a8967a9 → Message: Topic=Homey/homie/werkkamer-lamp/dim, Payload=1, QoS=AtMostOnce, Retain=False |
> | --- | --- | --- | --- |
> | 794 | 18:36:06.383 | 12 | MTTQ Broker=\> From=homey\_6d1f3ea5 → Message: Topic=Homey/homie/werkkamer-lamp/dim, Payload=1, QoS=AtMostOnce, Retain=True |
> | 793 | 18:36:06.325 | 123 | Controller action: Device.GetDeviceProperties |
> | 792 | 18:36:06.259 | 123 | ExecuteWithinTransaction: Added 0, Deleted 0, Updated 1 objects in tables DevicePropertyValue |
> | 791 | 18:36:06.251 | 123 | MTTQ Client Local =\> From=f331881e5a004c6fa522f3a11a8967a9 → Message: Topic=Homey/homie/werkkamer-lamp/dim, Payload=0.3, QoS=AtMostOnce, Retain=False |
> | 790 | 18:36:06.246 | 12 | MTTQ Broker=\> From=homey\_6d1f3ea5 → Message: Topic=Homey/homie/werkkamer-lamp/dim, Payload=0.3, QoS=AtMostOnce, Retain=True |

---

<div class="post-metadata">

**Author:** ![Camelen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/camelen/32/9613_2.png) [@Camelen](https://community.homey.app/u/Camelen)\
**Post date:** [February 23, 2019, 9:51pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/378 "2019-02-23T21:51:42Z")

</div>

Hey. Just wanted you to notice the requirement that gbridge has regarding Lastwill. I don’t really understand it honestly but see the thread about gbridge and Google home 🙂

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 23, 2019, 9:55pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/379 "2019-02-23T21:55:34Z")

</div>

It’s already implemented (settings not yet available).  
 ![Screenshot_20190223-225406](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/1/1e089c6d5d38c1fb5357e33e94cfd6b9e61649c1.jpeg)

---

<div class="post-metadata">

**Author:** ![Camelen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/camelen/32/9613_2.png) [@Camelen](https://community.homey.app/u/Camelen)\
**Post date:** [February 23, 2019, 10:07pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/380 "2019-02-23T22:07:55Z")

</div>

As long as the topic is choosable it looks great! 👍😁

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 23, 2019, 10:09pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/381 "2019-02-23T22:09:16Z")

</div>

I made some changes in settings to get more control over all topics (homie, custom, ha discovery, etc.)

---

<div class="post-metadata">

**Author:** ![KonradWalsh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/konradwalsh/32/147_2.png) [@KonradWalsh](https://community.homey.app/u/KonradWalsh)\
**Post date:** [February 23, 2019, 10:19pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/382 "2019-02-23T22:19:06Z")

</div>

@HarriedeGroot  
If you can make this work with gBridge… I’ll donate to you too

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 23, 2019, 10:37pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/383 "2019-02-23T22:37:55Z")

</div>

@KonradWalsh I followed [the other thread](https://community.homey.app/t/connecting-gbridge-to-homey-for-google-assistant/9234), but what has to be implemented for the HUB to get things working?  
If it’s only the birth & last will messages, these will be available soon (configurable).

---

<div class="post-metadata">

**Author:** ![KonradWalsh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/konradwalsh/32/147_2.png) [@KonradWalsh](https://community.homey.app/u/KonradWalsh)\
**Post date:** [February 23, 2019, 10:40pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/384 "2019-02-23T22:40:39Z")

</div>

I think… Think…

It needs to send all the devices info to gBridge…

@pkappelt will know better

---

<div class="post-metadata">

**Author:** ![HarriedeGroot](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/harriedegroot/32/56160_2.png) [@HarriedeGroot](https://community.homey.app/u/HarriedeGroot)\
**Post date:** [February 23, 2019, 10:51pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/385 "2019-02-23T22:51:08Z")

</div>

@KonradWalsh I didn’t look at gBridge (yet), but in my understanding it’s already possible to connect gBridge with Homey by using the MQTT Hub with an external broker (mosquitto, cloudmqtt, HiveMQ, …). @Camelen and @xAPPO both got this working?

The problem was/is a direct connection with the internal mqtt broker of gBridge. This can be solved by sending the correct birth & last will messages (already implemented, available soon)?  
When setting the correct device topics in gBridge (follow the homie convention), you should be able to connect all your devices?

Please correct me if I’m wrong!

Is there anything I can do (within the hub) to simplify the process?

[Previous page](https://community.homey.app/t/mqtt-hub-gateway/6766.md?page=18)

[Next page](https://community.homey.app/t/mqtt-hub-gateway/6766.md?page=20)
