HabApp / MQTT Beginner Question

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:

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:

        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

        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:

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?

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

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

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

Note that there is also the MqttPairItem which works well with zigbee2mqtt

Ok, thanks.
I was the opinion that after

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

the

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”)?

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

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:

        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)

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:

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:

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

So any ideas for that`?

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.

See docs, the functions are described there.

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.

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?