# How to create channels when the thing uses separate mqtt topics to get and set status and returns json string?

**URL:** <https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722>\
**Category:** Beginners\
**Created:** [December 7, 2021, 2:19pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722 "2021-12-07T14:19:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ariznaf](https://community.openhab.org/user_avatar/community.openhab.org/ariznaf/32/83958_2.png) [@ariznaf](https://community.openhab.org/u/ariznaf)\
**Post date:** [December 7, 2021, 2:19pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/1 "2021-12-07T14:19:41Z")

</div>

I am trying to integrate EQ3 Bluetooth TRV with openHab.

I have setup a tasmota ESP32 device with BLE enabled to connect to EQ3 valves.

But the implementation in tasmota uses MQTT topics like `stat/<TasmotaDevice>/EQ3/<EQMACADD>` to get the status, which returns a json string with all relevant information (setpoint temperature, opening of valve, etc).

For setting temperature, for example, you use `cmnd/<TasmotaDevice>/EQ3/<EQMACADD>/settemp <tempval>`" using just raw values.

When you send a command to the valve to set one value, it returns the complete set of values in the “stat” topic with the complete JSON set of values and containing error info.

I can get the values from eq3 valves in just one channel retrieving the status JSON value.  
Then I can link items to it an use JSONPATH to extract the values from it.  
But then I cannot change that values, as there is no place to introduce the comand MQTT topics.

You can use different channels for each value, giving different topics to get the value and set it.  
But it seems quite inefective, as the valve will answer with the complete JSON with all the values of the status of the valve, from where you have to use JSONPATH to extract each value.  
Doing it multiple times seems a waste of resources.

How is the best way to interact with this kind of devices?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [December 7, 2021, 2:24pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/2 "2021-12-07T14:24:04Z")

</div>

> [@ariznaf](#):
>
> You can use different channels for each value, giving different topics to get the value and set it.  
> But it seems quite inefective, as the valve will answer with the complete JSON

The target only responds once to one command; all the channels linked to the same topic update their individual Items with the up-to-date information contained in the one message.

I think you’re imagining a problem here.

---

<div class="post-metadata">

**Author:** ![ariznaf](https://community.openhab.org/user_avatar/community.openhab.org/ariznaf/32/83958_2.png) [@ariznaf](https://community.openhab.org/u/ariznaf)\
**Post date:** [December 7, 2021, 2:30pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/3 "2021-12-07T14:30:30Z")

</div>

Thanks for answering so fast.  
May be, I am quite new to openHAB. I don’t know the indepths of it.

I am not sure to understand your answer.

The valve will respond for each command but not with just the result or the set value.  
It respond with the complete status fo the valve (and you have to extract the info with JSONPATH to see if it did it correctly).

If I understand you well, you say that the best way is just to create separate channels for each value and stablish a JSONPAT to extract the value. (it will have to retrieve the status several times to get al values and extract the value from the answer).

I will try it, then.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [December 7, 2021, 2:50pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/4 "2021-12-07T14:50:37Z")

</div>

> [@ariznaf](#):
>
> The valve will respond for each command but not with just the result or the set value.  
> It respond with the complete status fo the valve

Yes, that is a Good Thing giving you all the up-to-date information.

> [@ariznaf](#):
>
> the best way is just to create separate channels for each value and stablish a JSONPAT to extract the value.

Yes.

> [@ariznaf](#):
>
> (it will have to retrieve the status several times to get al values and extract the value from the answer)

There is only one incoming message, there is no harm in getting all the information out of it, it is all already there whether you use it or not. It is not even possible to set up a channel that only looks at some of the incoming messages on its topic, but not others.

---

<div class="post-metadata">

**Author:** ![ariznaf](https://community.openhab.org/user_avatar/community.openhab.org/ariznaf/32/83958_2.png) [@ariznaf](https://community.openhab.org/u/ariznaf)\
**Post date:** [December 7, 2021, 2:53pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/5 "2021-12-07T14:53:02Z")

</div>

OK, thanks, it is clear now.

May be I am from the old days, when transmitting messages was costly and time consuming.

If it is common to use it like that, I will use it as it is.

I thought I was missing something.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [December 7, 2021, 2:55pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/6 "2021-12-07T14:55:48Z")

</div>

> [@ariznaf](#):
>
> transmitting messages was costly and time consuming.

We have no control over that from the openHAB end. Look at Tasmota if you want something to change there.  
You’re going to get _some_ message packet either way. Whether the payload is 12 bytes or 50 bytes makes very little difference to the network overheads.

---

<div class="post-metadata">

**Author:** ![ariznaf](https://community.openhab.org/user_avatar/community.openhab.org/ariznaf/32/83958_2.png) [@ariznaf](https://community.openhab.org/u/ariznaf)\
**Post date:** [December 7, 2021, 3:06pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/7 "2021-12-07T15:06:37Z")

</div>

I have to ask to tasmota team if there is an implementation of homeassistant protocol for the valves.  
Even if I enable homeassistant the valves continue presenting their data in that sort of “propietary” format.

Thank you a lot. It is great knowing I am not doing it the usual way.  
You have saved me a lot of time trying to find a solution to what seems to be really no a problem.

---

<div class="post-metadata">

**Author:** ![pmknowles](https://community.openhab.org/user_avatar/community.openhab.org/pmknowles/32/19462_2.png) [@pmknowles](https://community.openhab.org/u/pmknowles)\
**Post date:** [December 12, 2021, 5:42pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/8 "2021-12-12T17:42:34Z")

</div>

With mine each TRV sends its own topic  
stat/EQ3/001A22126545  
and I get this JSON from a TRV  
{“cmd”:“poll”,“result”:“ok”,“MAC”:“001A22126545”,“tas”:“UtilityESP32-1876”,“RSSI”:-77,“stattime”:1639330288,“temp”:10.5,“posn”:11,“mode”:“manual”,“hassmode”:“heat”,“boost”:“inactive”,“dst”:“set”,“window”:“closed”,“state”:“unlocked”,“battery”:“GOOD”,“holidayend”:“00-00-00 00:00”}  
I have a Thing called Radiators  
For the SetPoint I create a Channel UtilitySet which gives a Channel mqtt:topic:MQTTv2:Radiators:UtilitySet  
the State field is  
stat/EQ3/001A22126545  
and in Advanced  
JSONPATH:$.temp  
The Command is  
cmnd/UtilityESP32/EQ3/001A22126545/settemp  
You can then Link the Channel to an Item (I still create my items in an .items file) so that it an be used in sitemaps etc.  
You can repeat the procedure for each parameter/valve

---

<div class="post-metadata">

**Author:** ![ariznaf](https://community.openhab.org/user_avatar/community.openhab.org/ariznaf/32/83958_2.png) [@ariznaf](https://community.openhab.org/u/ariznaf)\
**Post date:** [December 12, 2021, 6:49pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/9 "2021-12-12T18:49:50Z")

</div>

Yes, thank you, mine too, one state topic for each valve.

I had expected that each field there (mode, temp,… ) was a separate topic when you activated HOMEASSISTANT autodiscovering.

The topic commands are separated, one for each field. It was strange for me, but I have seen that is quite a usual behaviour: composing a JSON message with the state containing all the fields, and a separate command topic for each thing you can control, When you change something it answers with the whole status.

I have done as you say: use the state topic and JSONPATH to get the value and the cmnd topic to set it.

But it dos not work correctly if you use a channel fro temp defined as mqtt:number (as it should be in theory as it is a number what you receive and not a string). Only works if you define it as mqtt:string.

---

<div class="post-metadata">

**Author:** ![pmknowles](https://community.openhab.org/user_avatar/community.openhab.org/pmknowles/32/19462_2.png) [@pmknowles](https://community.openhab.org/u/pmknowles)\
**Post date:** [December 12, 2021, 10:23pm UTC](https://community.openhab.org/t/how-to-create-channels-when-the-thing-uses-separate-mqtt-topics-to-get-and-set-status-and-returns-json-string/129722/10 "2021-12-12T22:23:45Z")

</div>

Well mine work as Numbers

 ![FDFF565080C542EDA19CADCC01E03443.png](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/f/7/f7a957b3e099d9485cb0bf2c5585390f484c2a2b.png)
