# HabApp / MQTT Beginner Question

**URL:** <https://community.openhab.org/t/habapp-mqtt-beginner-question/143513>\
**Category:** 3rd Party\
**Tags:** habapp\
**Created:** [January 18, 2023, 5:19pm UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513 "2023-01-18T17:19:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gthorsten](https://community.openhab.org/user_avatar/community.openhab.org/gthorsten/32/45732_2.png) [@Gthorsten](https://community.openhab.org/u/Gthorsten)\
**Post date:** [January 18, 2023, 5:19pm UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/1 "2023-01-18T17:19:40Z")

</div>

HI,  
actually I have a openhab running, combined with rules running on HABApp/Python, and everything is fine.  
Now I have my first Devices that needs a MQTT.  
So I installed zigbee2mqtt and it is running on openhab side

Now I want to use the mqtt things/items in HabApp/Rules.  
Connection from HabAtt to mqtt works fine.

Then I tried to switch a SmartPlug On/Off from a rule an my confusion begins:  
Doing this from a mqtt client i did:

```yaml
mosquitto_pub -h X.X.X.X -u user -P 'pw' -t zigbee2mqtt/SPOS_1/set -m "OFF"
or
mosquitto_pub -h X.X.X.X -u user -P 'pw!' -t zigbee2mqtt/SPOS_1/set -m "{\"state\": \"ON\"}" 

```

The same i tried from the rule:

```yaml
        self.my_mqtt_item = MqttItem.get_create_item("zigbee2mqtt/SPOS_1")
        self.my_mqtt_item.publish("{\"STATE\": \"OFF\"}")
        self.my_mqtt_item.publish("ON")

```

Both commands were not working → No error, but no result on the smartplug

The only thing that works

```yaml
        self.mqtt.publish("zigbee2mqtt/SPOS_1/set", "OFF")

```

So even after reading the docs I’m not clear where the problem is.

I thought the behaviour is the the same as with openhab items:

```yaml
self.Presence = SwitchItem.get_item(PRESENCE_ITEM)

```

After that i can send commands or post updates to the openhab item

So what did I wrong?

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [January 18, 2023, 6:23pm UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/2 "2023-01-18T18:23:29Z")

</div>

```auto
self.my_mqtt_item = MqttItem.get_create_item("zigbee2mqtt/SPOS_1")

```

you missed the `/set` on the topic. Correct would be

```auto
self.my_mqtt_item = MqttItem.get_create_item("zigbee2mqtt/SPOS_1/set")

```

Note that there is also the [MqttPairItem](https://habapp.readthedocs.io/en/latest/interface_mqtt.html#mqttpairitem) which works well with zigbee2mqtt

---

<div class="post-metadata">

**Author:** ![Gthorsten](https://community.openhab.org/user_avatar/community.openhab.org/gthorsten/32/45732_2.png) [@Gthorsten](https://community.openhab.org/u/Gthorsten)\
**Post date:** [January 18, 2023, 7:48pm UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/3 "2023-01-18T19:48:46Z")

</div>

Ok, thanks.  
I was the opinion that after

```yaml
self.my_mqtt_item = MqttItem.get_create_item("zigbee2mqtt/SPOS_1")

```

the

```yaml
self.my_mqtt_item.publish("ON")

```

works because the Mqtt lib adds the set..

But after thinking about that, you could not know which item /topic is used to set or get.

The usage of MqttPairItem also works.

So one more Question:  
The MqttItem has a get\_value and a push\_update function.  
How did they work?  
Did push\_update(“ON”) the same as the self.my\_mqtt.publish(“ON”)?

---

<div class="post-metadata">

**Author:** ![Gthorsten](https://community.openhab.org/user_avatar/community.openhab.org/gthorsten/32/45732_2.png) [@Gthorsten](https://community.openhab.org/u/Gthorsten)\
**Post date:** [January 18, 2023, 9:03pm UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/4 "2023-01-18T21:03:38Z")

</div>

OK, I think I understood it. But my confusion is growing.  
I have another Zigbee Device ( a Heating actuator, just today out of the box).

It’s main topic is: zigbee2mqtt/KZET\_HA  
With zigbee2mqtt/KZET\_HA/get or zigbee2mqtt/KZET\_HA/set I can set or get values

Example:  
zigbee2mqtt/KZET\_HA/get with payload “{"valve\_position": ""}” queries the actual valve position  
or  
zigbee2mqtt/KZET\_HA/get with payload “{"system\_mode": ""}” queries the actual system\_mode

Looking at the teminal log every cmd produces

```yaml
MQTT publish: topic 'zigbee2mqtt/KZET_HA', payload '{"current_heating_setpoint":21,"eurotronic_error_status":0,"eurotronic_host_flags":{"boost":false,"child_protection":false,"mirror_display":false,"window_open":false},"eurotronic_system_mode":1,"eurotronic_trv_mode":1,"eurotronic_valve_position":200,"linkquality":191,"local_temperature":18.5,"occupied_heating_setpoint":21,"pi_heating_demand":31,"system_mode":"auto","trv_mode":"1","unoccupied_heating_setpoint":21,"update":{"state":"idle"},"update_available":false}'

```

zigbee2mqtt/KZET\_HA/set with payload “{"valve\_position": "100"}” sets the actual valve position to 100  
Same with the terminal log here.

But how did that work in a rule.  
I tried:

```yaml
        self.my_mqtt_heat_get = MqttItem.get_create_item("zigbee2mqtt/KZET_HA/get")
        self.my_mqtt_heat_set = MqttItem.get_create_item("zigbee2mqtt/KZET_HA/set")

        self.my_mqtt_heat_get.publish("{\"system_mode\": \"\"}")
        self.my_mqtt_heat_get.publish("{\"valve_position\": \"\"}")

```

But during debug I inspect self.my\_mqtt\_het\_get and found there none of the values in the log.  
If I did this additional ( so use main topic)

```yaml
self.my_mqtt_heat = MqttItem.get_create_item("zigbee2mqtt/KZET_HA")

```

I saw some of the results.

Then I tried to set a value with:

```yaml
self.my_mqtt_heat_set = MqttItem.get_create_item("zigbee2mqtt/KZET_HA/set")
self.my_mqtt_heat_set.publish("{\"valve_position\": \"200\"}")
and
        self.my_mqtt_heat_get.publish("{\"valve_position\": \"\"}")

```

But Inspecting the objects I did not saw the changed valve position.

Also usinf the Pair did not succed:

```yaml
self.my_mqtt_heat_set = MqttPairItem.get_create_item("zigbee2mqtt/KZET_HA", "zigbee2mqtt/KZET_HA/set")

```

So any ideas for that`?

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [January 19, 2023, 4:53am UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/5 "2023-01-19T04:53:01Z")

</div>

You are mixing `MqttItem` and `MqttPairItem`. These are different item types. `MqttItem` will work with one topic, `MqttPairItem` will work with two topics, one to publish on one to load the value from.

> [@Gthorsten](#):
>
> How did they work?

See docs, the functions are described there.

> [@Gthorsten](#):
>
> So any ideas for that`?

You have your topics wrong. You typically one topic where you send something to the device and one topic where it answers. You are mixing these in your examples.  
Look at the HABApp events log and you’ll see which messages are received.

Also you don’t have to publish a string, you can just pass a python dict and it will be sent as a json.

---

<div class="post-metadata">

**Author:** ![Gthorsten](https://community.openhab.org/user_avatar/community.openhab.org/gthorsten/32/45732_2.png) [@Gthorsten](https://community.openhab.org/u/Gthorsten)\
**Post date:** [January 20, 2023, 11:28am UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/6 "2023-01-20T11:28:36Z")

</div>

OK, I checked the eventlogs.

I have 3 diffrent topics  
zigbee2mqtt/KZET\_HA/set it is to publish values to the topic ( e.g set valve position).  
Result could be seen in the logs to the topic zigbee2mqtt/KZET\_HA  
zigbee2mqtt/KZET\_HA/get is used to query values (eg: actual valve position)  
Here also the result comes to the topic zigbee2mqtt/KZET\_HA

If I create 3 mqtt\_items  
MqttItem.get\_create\_item(“zigbee2mqtt/KZET\_HA/set”)  
MqttItem.get\_create\_item(“zigbee2mqtt/KZET\_HA/get”)  
MqttItem.get\_create\_item(“zigbee2mqtt/KZET\_HA”)  
it looks that it works.

And with Pair:  
MqttPairItem.get\_create\_item(“zigbee2mqtt/KZET\_HA”, “zigbee2mqtt/KZET\_HA/Set” )  
this works.  
But what with the get toppic?  
Is it enough to use  
MqttItem.get\_create\_item(“zigbee2mqtt/KZET\_HA/get”)  
and the result is seen in the item created by Pair above?

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [February 2, 2023, 7:47am UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/7 "2023-02-02T07:47:58Z")

</div>

Have you everything working as desired? If yes what is your working configuration now?

---

<div class="post-metadata">

**Author:** ![Gthorsten](https://community.openhab.org/user_avatar/community.openhab.org/gthorsten/32/45732_2.png) [@Gthorsten](https://community.openhab.org/u/Gthorsten)\
**Post date:** [February 2, 2023, 9:39am UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/8 "2023-02-02T09:39:26Z")

</div>

Hi, yes actually it is working.  
I will sent you the configuration. But it could be earliest on weekend. Actually my work is to heavy.  
After sitting 10 hours before the work pc reduces my flow to sit before a laptop in the evening.  
But will sent it to you ASAP.

---

<div class="post-metadata">

**Author:** ![Spaceman\_Spiff](https://community.openhab.org/user_avatar/community.openhab.org/spaceman_spiff/32/56883_2.png) [@Spaceman\_Spiff](https://community.openhab.org/u/Spaceman_Spiff)\
**Post date:** [February 2, 2023, 12:58pm UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/9 "2023-02-02T12:58:42Z")

</div>

No worries - it’s not urgent! I just wanted to see if we have to do some more investigation or the topic can be marked as resolved.

---

<div class="post-metadata">

**Author:** ![Gthorsten](https://community.openhab.org/user_avatar/community.openhab.org/gthorsten/32/45732_2.png) [@Gthorsten](https://community.openhab.org/u/Gthorsten)\
**Post date:** [February 5, 2023, 7:37pm UTC](https://community.openhab.org/t/habapp-mqtt-beginner-question/143513/10 "2023-02-05T19:37:46Z")

</div>

Hi,  
actially I use the following config:

```javascript
        self.mqtt_heat_set = MqttPairItem.get_create_item("zigbee2mqtt/KZET_HA", "zigbee2mqtt/KZET_HA/set")
        self.mqtt_heat_get = MqttItem.get_create_item("zigbee2mqtt/KZET_HA/get")

```

With the first item I set values to mqtt an receive the anwser-  
With the second I sent a call to read values.

That’s working for me.
