# How to "trigger" an mqtt topic to read another topic

**URL:** <https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239>\
**Category:** Beginners\
**Created:** [January 2, 2020, 12:45pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239 "2020-01-02T12:45:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 12:45pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/1 "2020-01-02T12:45:30Z")

</div>

So I have a TRV setup with MQTT and “Generic Thing” - successfully using PaperUI (do not want to use files - please note) . The TRV automatically reports one state topic - TEMPERATURE which is the Actual Temperature of the room. It does this without any intervention and I can see the temperature on a linked item.

My “Generic Thing TRV” has a number of MQTT topics where a command topic (no payload) must be sent in order to read the corresponding state topic. For example, to obtain the VOLTAGE topic , one must send a null payload to topic /energenie/eTRV/Command/VOLTAGE/8008 (8008=manufactuer deviceID) and then the eTRV will publish the voltage value, once but the value is persistent, to the topic /energenie/eTRV.Report/Voltage/8008, for example 3.012 (an asci string for the voltage).

I have managed to do this through a very basic manufacturer provided control software and it all works, but my question to you good folk is:-  
How would I model this (or how should I) in OH PaperUI? I have got the channels set up for the VOLTAGE command and state topics, but I’m not sure what Items I need and how to set these up or if indeed Items are the right thing to do? And do I have do do something else with the Channels? I have also noted the ability to setup a “Publish Trigger” on the MQTT Broker thing, is something I need?

All state topic payloads are of type String and all are persistent, that is to say that once the topic state value is updated, then the corresponding value persists until it is refreshed by means of publishing to the corresponding command topic - which is effectively a “Refresh request” . It is this refresh request that I’m not sure how to model in OH.

And, then, how might I setup HABpanel ? Maybe a widget that that shows the state and refreshes when clicked? Is it even possible?

I do not work with files so please kindly , I am looking for help with Paper or Basic UI, please, no files , please 🙂

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [January 2, 2020, 1:06pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/2 "2020-01-02T13:06:44Z")

</div>

> [@tillykeats](#):
>
> So I have a TRV setup with MQTT

What is it? I am interested. Thanks

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 1:07pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/3 "2020-01-02T13:07:38Z")

</div>

Sorry?Pardon?

---

<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:** [January 2, 2020, 1:13pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/4 "2020-01-02T13:13:36Z")

</div>

I think I’d be building -  
An Item representing your reading - “Voltage” - that links to an MQTT state topic listening for updates from the device.

An Item representing your “fetch button” - that links to an MQTT command topic that sends the needed “prompt” to the device.  
You’d probably model that as a switch, and additionally link to expire binding to set back off after use.

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 1:17pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/5 "2020-01-02T13:17:13Z")

</div>

Yes, I have the first, and that works but the second bit you mention is currently outside HAB as per my OP. So yes, how would I build the second bit - that was precisely my question. Are you able to elaborate how please? I have a Switch item but it’s not sending anything to the command topic. What would be REALLY great is for one refresh button to send all the commands needed , to refresh all the states

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [January 2, 2020, 1:20pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/6 "2020-01-02T13:20:07Z")

</div>

> [@tillykeats](#):
>
> Sorry?Pardon?

What device is it? I have been looking for MQTT trvs  
Thanks

---

<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:** [January 2, 2020, 1:20pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/7 "2020-01-02T13:20:09Z")

</div>

> [@tillykeats](#):
>
> the second bit you mention is currently outside HAB as per my OP.

You have an MQTT thing with a command topic to do what you want? Link it to an Item. Send your Item commands.

If you choose a Switch type Item (as the closest thing to a “button”) you would want to see that the ON command gets transformed into whatever MQTT payload you actually need.

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 1:25pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/8 "2020-01-02T13:25:16Z")

</div>

Ah, sorry. It’s Energenie: [Product doesn't exist | Energy Saving Products | Energenie](https://energenie4u.co.uk/catalogue/product/MIHO013)

Although I acquired 5off for £99 in Black Friday 🙂

Works perfectly with Raspberry Pi running Energenie’s ENER314-RT 433Mhz transceiver board: [Two way Pi-mote - ENER314-RT | Energy Saving Products | Energenie](https://energenie4u.co.uk/catalogue/product/ENER314-RT) running @gbpenton Client code that I setup as a systemd service on Openhabian.

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [January 2, 2020, 1:30pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/9 "2020-01-02T13:30:13Z")

</div>

Ok, so not Wifi MQTT but 433MHz - “Gateway” - MQTT  
Not for me…  
433MHz is just too unreliable  
Not to mention the price!

Thanks anyway

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 1:33pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/10 "2020-01-02T13:33:55Z")

</div>

I have a Thing with Channels where each Channel is setup for the corresponding State or Command topic. So I have:

TEMPERATURE  
State =/energenie/eTRV/Report/Temperature/ to read current temp  
TARGET TEMPERATURE  
Command =/energenie/eTRV/Command/Temperature/ to set target temp  
State =/energenie/eTRV/Report/TargetTemperature/ to read AFTER the command was sent for set temp  
VOLTAGE  
Command =/energenie/eTRV/Command/Voltage/ to request a report on current voltage  
State =/energenie/eTRV/Report/Voltage/ to read AFTER the command was sent for voltage  
POWER MODE  
Command =/energenie/eTRV/Command/Power/ to request a report on current power mode  
State =/energenie/eTRV/Report/Power to read AFTER the command was sent for powermode

etc.

What do I need to do so that I can press a “Refresh Button” and get ALL of them refreshed?

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 1:36pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/11 "2020-01-02T13:36:33Z")

</div>

Wifi = more expensive, more power hungry, issues with congestion  
433mhz = cheap (board was £2, TRVs were £20) but you can get remote controlled TRVs and switches for a tenner on auction sites - they use 433Mhz.

So far, no reliability issues - works perfectly - just want to use HAB now as the single integrated smart home system

---

<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:** [January 2, 2020, 1:44pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/12 "2020-01-02T13:44:18Z")

</div>

> [@tillykeats](#):
>
> What do I need to do so that I can press a “Refresh Button” and get ALL of them refreshed?

You need to send multiple command topics, right?  
More than one way to go about it.

I think because you need to send “real” commands to your TARGET TEMPERATURE that would make it difficult to also send the “refresh” over the same channel.

One file-free approach;  
Set up individual channels with your “refresh” command topics.  
Link these channels to individual “do it” Items.  
Put those Items in a Group.  
Send a command to your group.

There are more elegant ways using rules, but you want to avoid files.

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 2:13pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/13 "2020-01-02T14:13:03Z")

</div>

Not sure I understand,  
I have channels setup, with State and Command topics.  
I added a Switch Item and a Switch channel on the TRV thing, set the command topic, but when I operate the switch item, nothing happens?

EDIT: Hang on,  
I have to say, this UI is better than nothing but it’s not intuitive.  
This isnt easy or quick with the UI, so my “no files please” was unwarranted.  
I will create a basic file setup and post back for help..  
How would I do this in files (.things and .items) ? Can you provide an example using some arbitary IDs that I will substitute for my own.

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 2:42pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/14 "2020-01-02T14:42:59Z")

</div>

Here is a working .things file, what next, please?

```csv
/* Bridge to TRV over MQTT */
Bridge mqtt:broker:MQTT_Broker [host="localhost", secure=false] {
  /* Generic MQTT Thing for TRV */
  Thing topic Lounge_TRV_Thing "Lounge TRV" @ "Lounge" {
    Channels:
        /* Current temp , is published periodically by the TRV */
        State String : Temperature [stateTopic="/energenie/eTRV/Report/Temperature/8008"]
        /* In the following channels , states can only be obtained AFTER the corresponding commandTopics are triggered (with NIL payload) */
        State String : Voltage [stateTopic="/energenie/eTRV/Report/Voltage/8008", commandTopic="/energenie/eTRV/Command/Voltage/8008"]
        State String : Target_Temp [stateTopic="/energenie/eTRV/Report/TargetTemperature/8008", commandTopic="/energenie/eTRV/Command/Temperature/8008"]
   }
}

```

I have tried to research this but I need help please.  
Maybe using profiles? [Items | openHAB](https://www.openhab.org/docs/configuration/items.html#profiles) will help? But i am stuck on what channels and items I need , and maybe things?  
Also read this [Design Pattern: Proxy Item](https://community.openhab.org/t/design-pattern-proxy-item/15991) but it is way above what I can do so not sure if it is suitable, but some form of Push Button widget in HABpanel that fires off multiple commandTopics would be great - if possoibe?

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [January 2, 2020, 4:40pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/15 "2020-01-02T16:40:34Z")

</div>

> [@tillykeats](#):
>
> My “Generic Thing TRV” has a number of MQTT topics where a command topic (no payload) must be sent in order to read the corresponding state topic. For example, to obtain the VOLTAGE topic , one must send a null payload to topic /energenie/eTRV/Command/VOLTAGE/8008 (8008=manufactuer deviceID) and then the eTRV will publish the voltage value, once but the value is persistent, to the topic /energenie/eTRV.Report/Voltage/8008, for example 3.012 (an asci string for the voltage).

☹ This is not how MQTT is supposed to work. The device should just publish the voltage value. It shouldn’t require the subscribers to do anything to get the value.

> [@tillykeats](#):
>
> but I’m not sure what Items I need and how to set these up or if indeed Items are the right thing to do? And do I have do do something else with the Channels?

If you want to do anything with the Channels you must link them to Items.

> [@tillykeats](#):
>
> I have also noted the ability to setup a “Publish Trigger” on the MQTT Broker thing, is something I need?

Not in this case I think.

> [@tillykeats](#):
>
> It is this refresh request that I’m not sure how to model in OH.

On first thought, assuming you have more than one of these devices:

- Create a Generic Thing for each device. Have a Channel for the refresh topic, the value topic, and any other topic provided/used by that device.
- Link Items to all the Channels you care about. The refresh Channel should probably be a Switch type. then you can sendCommand(ON) to it and it will publish the empty message to the refresh topic in response.
- Add all the Items linked to the refresh topic to a Group:Switch.
- Create a Time cron triggered Rule that periodically sendComman(ON) on the Group. The command will be forwarded to all the members of the Group, which will result in the message being sent to the refresh topic and in turn the devices will publish the value to the state topic which will be received by OH and the Items updated. I believe this trigger type works in the NGRE PaperUI Rules UI.

> [@tillykeats](#):
>
> i am stuck on what channels and items I need , and maybe things?

Step back a second. You are trying to run before you can walk. Review [How to get started (there is no step-by-step tutorial)](https://community.openhab.org/t/how-to-get-started-there-is-no-step-by-step-tutorial/75407). Your struggles are because you lack an understanding of how OH works. In particular, the relationships between Things, Items and Rules.

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 5:46pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/16 "2020-01-02T17:46:16Z")

</div>

No,…  
Actually I do understand the OH architecture , what I need help with is the specific triggering to publish to many topics at once. The rest I am okay with. I do have items and linked channels. But the whole point of the question was HOW to model this in OH - admittedly granted through the UI then I was won over by the ease of files however I lack the SPECIFIC of what and how to do it.  
Perhaps you could impart your experience with a suggestion that provides by example, a snippet of code to put in the file(s)  
I am presuming you are capable of providing an example, there are many on the docs Ive read (which are extensive), so I clearly need to tie a few things together - how?

In so far as “not how its supposed to work” - that’s the manufacturer , not my design.

EDIT, me entire .things is:-

```csv
/* Bridge to TRV over MQTT */
Bridge mqtt:broker:MQTT_Broker [host="localhost", secure=false] {
  /* Generic MQTT Thing for TRV */
  Thing topic Lounge_TRV_Thing "Lounge TRV" @ "Lounge" {
    Channels:
        /* Current temp , is published periodically by the TRV */
        State String : Temperature "Temperature" [stateTopic="/energenie/eTRV/Report/Temperature/8008"]
        /* In the following channels , states can only be obtained AFTER the corresponding commandTopics are triggered (with NIL payload) */
        State String : Voltage [stateTopic="/energenie/eTRV/Report/Voltage/8008", commandTopic="/energenie/eTRV/Command/Voltage/8008"]
        State String : Target_Temp [stateTopic="/energenie/eTRV/Report/TargetTemperature/8008", commandTopic="/energenie/eTRV/Command/Temperature/8008"]
        State String : Diagnostics [stateTopic="/energenie/eTRV/Report/TargetTemperature/8008", commandTopic="/energenie/eTRV/Command/Temperature/8008"]
        State String : Target_Temp [stateTopic="/energenie/eTRV/Report/TargetTemperature/8008", commandTopic="/energenie/eTRV/Command/Temperature/8008"]
        State String : Identify [commandTopic="/energenie/eTRV/Command/Identify/8008"]
        State String : Exercise [commandTopic="/energenie/eTRV/Command/Exercise/8008"]
        State String : Valve_State [commandTopic="/energenie/eTRV/Command/Valve_State/8008"]
        State String : Power_Mode [commandTopic="/energenie/eTRV/Command/Power_Mode/8008"]
        State String : Reporting_Interval [commandTopic="/energenie/eTRV/Command/Reporting_Interval/8008"]
   }
}

```

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [January 2, 2020, 6:05pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/17 "2020-01-02T18:05:20Z")

</div>

As I and others in this thread have recommended… to repeat myself

> - Create a Generic Thing for each device. Have a Channel for the refresh topic, the value topic, and any other topic provided/used by that device.
> - Link Items to all the Channels you care about. The refresh Channel should probably be a Switch type. then you can sendCommand(ON) to it and it will publish the empty message to the refresh topic in response.
> - Add all the Items linked to the refresh topic to a Group:Switch.
> - Create a Time cron triggered Rule that periodically sendComman(ON) on the Group. The command will be forwarded to all the members of the Group, which will result in the message being sent to the refresh topic and in turn the devices will publish the value to the state topic which will be received by OH and the Items updated. I believe this trigger type works in the NGRE PaperUI Rules UI.

Since you understand OH, which one of the above steps do you have problems with? There is nothing in the above that is complicated. It’s all _very_ basic openHAB stuff. Since you already have the Things and Items you just need to create the Group, add your Items to the Group, and write the Rule.

See [Items | openHAB](https://www.openhab.org/docs/configuration/items.html#groups) for how to create the Group in a .items file, or you can create it in PaperUI.

See the following for creating the Rule

- [Textual Rules | openHAB](https://www.openhab.org/docs/configuration/rules-dsl.html)
- [Textual Rules | openHAB](https://www.openhab.org/docs/configuration/rules-dsl.html#time-based-triggers)
- [Textual Rules | openHAB](https://www.openhab.org/docs/configuration/rules-dsl.html#manipulating-item-states)

All you have to do is sendCommand(ON) to the Group on a polling schedule.

It’s a one line Rule.

We are happy to help with details but we are not going to write this for you. We’ve told you what you need to do, more than once and from more than one user in this thread. If you have a specific problem or confusion we will be happy to help. But again, we are not going to write this for you.

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 6:08pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/18 "2020-01-02T18:08:58Z")

</div>

> " Since you understand OH, which one of the above steps do you have problems with? There is nothing in the above that is complicated. It’s all _very_ basic openHAB stuff. Since you already have the Things and Items you just need to create the Group, add your Items to the Group, and write the Rule."

Creating the rule and using that to “trigger”/“fire” the “refresh” topics

Not seeking to be boring, but in fear of repeating myself

> Perhaps you could impart your experience with a suggestion that provides by example, a snippet of code to put in the file(s)  
> I am presuming you are capable of providing an example, there are many on the docs Ive read (which are extensive), so I clearly need to tie a few things together - how?

That is the help I need. If you want to keep repeating yourself and point to this and that, then there is really no point you doing so here, because it is not helping me. Of course Ive read docs, all of the configuration ones and for my bindings. I NEED HELP

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [January 2, 2020, 6:15pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/19 "2020-01-02T18:15:51Z")

</div>

> [@tillykeats](#):
>
> Creating the rule and using that to “trigger”/“fire” the “refresh” topics

> See the following for creating the Rule
> 
> - [Textual Rules | openHAB](https://www.openhab.org/docs/configuration/rules-dsl.html)
> - [Textual Rules | openHAB](https://www.openhab.org/docs/configuration/rules-dsl.html#time-based-triggers)
> - [Textual Rules | openHAB](https://www.openhab.org/docs/configuration/rules-dsl.html#manipulating-item-states)

And since you understand OH, I’m sure you understand that Rules _don’t_ trigger MQTT topics. Rules update or send commands to Items. The Items are linked to Channels on Things. Depending on how the Channel is configured, it receives the Command and sends a message to the device using what ever technology it uses, in this case sends an MQTT message.

---

<div class="post-metadata">

**Author:** ![tillykeats](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@tillykeats](https://community.openhab.org/u/tillykeats)\
**Post date:** [January 2, 2020, 6:17pm UTC](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239/20 "2020-01-02T18:17:11Z")

</div>

Tell you what Rich, hey, many thanks for coming on here, but maybe leave it for someone else. Im getting frustrated and I dont want to hack you off so may be you can leave this thread. It is not helping one iota but I do thank you for all the links to the docs Ive read.

I’m pulling hair out here so if someone who has the capability to by example provide the code I need, Id appreciate you posting here .

I think I will await someone who can , BY EXAMPLE , using CODE , IN FILES , how to setup ,not cron , but pushbutton in HABpanel to effect an update in state topics by posting to command topics. Thank you so much.

[Next page](https://community.openhab.org/t/how-to-trigger-an-mqtt-topic-to-read-another-topic/89239.md?page=2)
