# 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:** 50

<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:** [May 13, 2021, 9:00pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/991 "2021-05-13T21:00:28Z")

</div>

> The ‘setTopic’ is called when the MQTT Device state (capability value) is changed.  
> A change can be triggered manually, via a flow / script or a message on the state topic…

Why is the set topic called when the MQTT Device state changes? Is this wanted behavior?

---

<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:** [May 13, 2021, 9:01pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/992 "2021-05-13T21:01:13Z")

</div>

Yes, that’s wanted behaviour.  
If you change the value in Homey (dim slider / button press) you want the value to be send to the listening party(ies). It’s 2-way communication…and I have no clue who is listening an who changed the value.

This loop will break if the incoming value equals the current value (state). But I agree is not stable the way it’s implemented now. Needs some attention…

---

<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:** [May 13, 2021, 9:04pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/993 "2021-05-13T21:04:43Z")

</div>

> [@HarriedeGroot](#):
>
> If you change the value in Homey (dim slider / button press) you want the value to be send to the listening party.

But this isn’t what I’m talking about.

It’s very clear from the Mosquitto log and from my tests that when I change the value of the device from OTHER sources than homey and homey sees this state change of the state topic it puts this change into the SET topic.

> The /set topic should never be updated by Homey on device state change

This is absolutely what is happening here.

---

<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:** [May 13, 2021, 9:06pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/994 "2021-05-13T21:06:12Z")

</div>

Homey receives a new value for the capability (unregarding the source) and therefore calls the setTopic (in a seperate process). My above statement is not correct…

---

<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:** [May 13, 2021, 9:07pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/995 "2021-05-13T21:07:35Z")

</div>

Why though? Since /set is not a state topic why does it need to reflect the state? I don’t get it. HA does NOT work this way either.

---

<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:** [May 13, 2021, 9:08pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/996 "2021-05-13T21:08:20Z")

</div>

Do you want the dim level to be send to the set topic when changing the value from within Homey (adjusting the slider)?

---

<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:** [May 13, 2021, 9:09pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/997 "2021-05-13T21:09:46Z")

</div>

I do yes. When I change the value of a device in Homey I want Homey to post to /set.

When I change the value of the device from another source ideally I want Homey to read the state topic and change the state shown in Homey to reflect the real state of the device. I do not want Homey to adjust the /set topic to reflect this because it increases traffic in the MQTT stream with no benefit that I can think of at the moment.

---

<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:** [May 13, 2021, 9:11pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/998 "2021-05-13T21:11:20Z")

</div>

Two things:

1. I don’t know who changed the value (the slider, script, flow, or mqtt input).
2. There can be multiple listeners, these also need to know the new value if adjusted from mqtt

---

<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:** [May 13, 2021, 9:16pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/999 "2021-05-13T21:16:02Z")

</div>

> 1. I don’t know who changed the value (the slider, script, flow, or mqtt input).

I’m not sure what you mean by this. What value?  
If the state changes then something has made it change and Homey should update its device to reflect the current state. Why involve /set?  
Maybe I’m just not understanding some part of this.

> 1. There can be multiple listeners, these also need to know the new value if adjusted from mqtt.

But these listeners are listening to the state topic that updates from zwavejs2mqtt after it has performed the /set task. I’m not pointing my listeners to the /set topic. The only subscriber to /set should ideally be zwavejs2mqtt and noone else. That’s the only device that should care what’s written there.

---

<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:** [May 13, 2021, 9:18pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1000 "2021-05-13T21:18:47Z")

</div>

> [@Camelen](#):
>
> I’m not sure what you mean by this. What value?

The Homey capability value. That’s what’s being updated when the external device state changes (message on value/state topic). A value changed listener on this capability fires the /set message. That SAME capability value gets updated when moving the slider.

1. Your’re probably correct.

---

<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:** [May 13, 2021, 9:22pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1001 "2021-05-13T21:22:36Z")

</div>

> [@HarriedeGroot](#):
>
> The Homey capability value. That’s what’s being updated when the external device state changes (message on value/state topic). A value changed listener on this capability fires the /set message.

I’m sorry I don’t really understand this.  
What’s Homey capability value?  
`“capability”: “dim”,`?

---

<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:** [May 13, 2021, 9:23pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1002 "2021-05-13T21:23:20Z")

</div>

Yes

---

<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:** [May 13, 2021, 9:23pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1003 "2021-05-13T21:23:52Z")

</div>

Basically I’m starting to believe that this is a limitation of Homey.  
When you change state of the Homey device it might be that Homey sees this as the same thing as moving the dim-slider which then triggers /set.

(Maybe that’s what you’ve been trying to tell me)

---

<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:** [May 13, 2021, 9:24pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1004 "2021-05-13T21:24:15Z")

</div>

correct. It’s like the same variable getting changed.

---

<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:** [May 13, 2021, 9:24pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1005 "2021-05-13T21:24:48Z")

</div>

Thanks for explaining. That’s a bit disappointing then since it seems impossible to solve.

---

<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:** [May 13, 2021, 9:25pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1006 "2021-05-13T21:25:04Z")

</div>

We’re not done yet!

---

<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:** [May 13, 2021, 9:26pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1007 "2021-05-13T21:26:00Z")

</div>

Next thing would be to try to detect if the change is just triggered by an incoming mqtt message (we know ofcourse) and adjust the behaviour if needed.

---

<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:** [May 13, 2021, 9:26pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1008 "2021-05-13T21:26:49Z")

</div>

Yeah if that’s possible!

---

<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:** [May 13, 2021, 9:27pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1009 "2021-05-13T21:27:46Z")

</div>

All is possible 🤓, but I’m not sure yet if its the correct solution.  
Breaking the loop when the values are equal (meaning all devices got the correct value), should also do the trick. But obviously, it’s not working as expected the way it’s currently implemented…

---

<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:** [May 13, 2021, 9:54pm UTC](https://community.homey.app/t/mqtt-hub-gateway/6766/1010 "2021-05-13T21:54:10Z")

</div>

> [@Camelen](#):
>
> output template to value\*99/100

Did some re-reading and there are some additional points to make:

1. The oposite calculation is needed for the input value: value\*100/99
2. Maybe the ‘percentage scaling’ option is working agains us here…

Since the introduction of the value template (i.e. mathJS), this ‘percentage scaling’ option is obsolete (and even confusing sometimes). I already planned to change the default setting from `int (0...100)` scaling to `keep original` value, for newly created MQTT Devices. The downside: the value template is probably needed for every percentage value, because Homey scales all percentages between 0…1 while the rest of the world uses 0…100 (or 0-99 in your case). But it removes the ‘magic’ behavior and the values line up with the displayed capability details.

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

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