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

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

Thanks anyway

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?

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

1 Like

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.

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.

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

/* 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? 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 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?

:frowning_face: 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.

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

Not in this case I think.

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.

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). Your struggles are because you lack an understanding of how OH works. In particular, the relationships between Things, Items and Rules.

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:-

/* 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" ]
   }
}

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 for how to create the Group in a .items file, or you can create it in PaperUI.

See the following for creating the Rule

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.

" 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

See the following for creating the Rule

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.

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.

Hint: you can’t
You need to split your channels
One for the state topic
One for the command topic
Then create items for each
Create groups
Create a dummy switch
Create a rule and send a command to the command topic group (One line rule!)

Makes senses
As @rlkoshak said, basic stuff

That’s what we’re telling you - you can’t.
What you can do is use a Group of MQTT linked Items to simulate that.

GUYS GUYS GUYS
WTF is going on here.
How many times, I need EXAMPLES of the “refresh trigger” the “update” the “group refresh” whatever you want to call it.
You all seem to possess the knowledge I have no doubt, so why cannnot you grasp the basic request for AN EXAMPLE…

Here is my full files FYI , there , now , an example in your next would be wonderful? That would be a REAL REAL help.

.things

/* 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 */
        Type 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) */
        Type string : Voltage                  "Voltage"                [stateTopic="/energenie/eTRV/Report/Voltage/8008", commandTopic="/energenie/eTRV/Command/Voltage/8008" ]
        Type string : Target_Temp              "Target temperatue"      [stateTopic="/energenie/eTRV/Report/TargetTemperature/8008", commandTopic="/energenie/eTRV/Command/Temperature/8008" ]
        Type string : Diagnostics              "Diagnostics"            [stateTopic="/energenie/eTRV/Report/Diagnostics/8008", commandTopic="/energenie/eTRV/Command/Diagnostics/8008" ]
        Type string : Identify                 "Identify"               [commandTopic="/energenie/eTRV/Command/Identify/8008" ]
        Type string : Exercise                 "Excercise"              [commandTopic="/energenie/eTRV/Command/Exercise/8008" ]
        Type string : Valve_State              "Valve state"            [commandTopic="/energenie/eTRV/Command/Valve_State/8008" ]
        Type string : Power_Mode               "Power mode"             [commandTopic="/energenie/eTRV/Command/Power_Mode/8008" ]
        Type string : Reporting_Rate           "Reporting rate"         [commandTopic="/energenie/eTRV/Command/Reporting_Interval/8008" ]
   }
}

.items

Group g_Refresh_TRV

/* Lounge TRV */
        /* States */
        String Get_Temperature          "Current temperature [%s]C"     (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Temperature"}
        String Get_Target_Temperature   "Desired temperature [%s]C"     (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Target_Temp"}
        String Get_Voltage              "Current voltage [%s]V"         (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Voltage"}
        String Get_Diagnostics          "Diagnostics code [%s]"         (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Diagnostics"}
        /* Commands */
        String Set_Temperature          "Set temperature [%s]"          (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Set_Temperature"}
        String Exercise                                                 (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Exercise"}
        String Identify                                                 (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Identify"}
        String Set_Valve_State          "Valve state [%s]"              (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Valve_State"}
        String Set_Power_Mode           "Power mode [%s]"               (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Power_Mode"}
        String Set_Reporting_Rate       "Report rate [%s]"              (gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Reporting_Rate"}
        /* Commanded by Refresh */
        String Refresh_Voltage                                          (g_Refresh_TRV,gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Voltage"}
        String Refresh_Diagnostics                                      (g_Refresh_TRV,gTemperature) {channel="mqtt:topic:MQTT_Broker:Lounge_TRV_Thing:Diagnostics"}
        /* Refresh button */
        Switch Refresh_Event            "Refresh Button"                (g_RefresH_TRV)

One assumes I need to do something with the g_Refresh_TRV group which will “trigger” (for want of a better word), the publishing of TWO topics with null payload to force a refresh of Voltage and Diagnostics. in CODE ? :slight_smile:

As per Rich, above,

https://www.openhab.org/docs/configuration/rules-dsl.html 1
https://www.openhab.org/docs/configuration/rules-dsl.html#time-based-triggers
https://www.openhab.org/docs/configuration/rules-dsl.html#manipulating-item-states

But now I’m out of my experience, this is gettnig into Java etc, which is where I need the help, as stated, many times. Phew. Someone save me

Well in time it took to type all that, you could have provided the potential rule .
Sigh

I really do not understand this forum. It is a place for help, and I have asked for specific help. Several hours later, what I note is “clever people” telling me what I should do but vitally, NOT answering the question. In of the posts above, all that is required, is a few lines of rule code. That’s all. I really do not understand why - if you really want to help- you post the obvious. It is obvious because I’ve already read the articles and I am stuck. I thought that was pretty obvious. Perhaps you do not actually know how to do it - that would explain a lot. I am 55, I am not a programmer, I have a wife kids and grandchildren to care for, I dont sit up through the night coding up programs and scripts, I dont really care for all that, Im just trying to ask a very basic question for specific basic answer. “Basic Stuff” you all say, really, is it - show me!

In the meantime, I shall await guidance from a clever person who just posts an example/suitable close enough code rule , with an exclamation mark so that I can finish the job.

So easy , yet proving so difficult.

In our extensive experience, writing the code for you ends up resulting in a huge time sink. We write this Rule for you, you copy it, don’t under stand it, then need us to write the next one and the next one and so on forever. Or even worse, we need to debug it for you when it doesn’t work.

So here.

rule "Request a refresh"
when
    Time "cron 0 0/5 * 1/1 * ? *"
then
    g_Refresh_TRV.sendCommand(ON)
end

It doesn’t get much simpler than that. You should have been able to come up with that from the links I provided. This is like half a step away from “hello world” the canonical first program one writes in any language. This is literally as simple as it gets for Rules.

And this is pretty close to at least one of the Examples in the Rules Documentation I linked to:

rule "Increase counter"
when
    Time cron "0 0 0 * * ?"
then
    counter = counter + 1
end

So now one must ask, do you really know any more now than when you started? Do you understand what the Rule above does? Why it works? How to debug it when it doesn’t work? No, you don’t. And now you will copy and paste that code, run it, and have no idea what to do when/if it doesn’t work. You have no idea how to expand it. You have no idea how to write another rule that does something different. And we here on the forum are now suck for ever writing your code for you.

And when you ask for examples, it shows that you neither read the docs which are riddled with examples (e.g. Rules | openHAB) nor did you browse or search the forum (Tutorials & Examples - openHAB Community).

Anyway, you get this one for free. But as you can see, in the future, we won’t usually be writing your code for you, especially when you demonstrate either a lack of understanding which is made clear from reading the docs, or a lack of effort to search for something in the forum that already addresses what you need.

Then state clearly and explicitly where you are stuck. And the real key is show us what you’ve done (i.e. show us your attempts at .rules code). I’m stuck isn’t something we can help with. “I’ve written this rule (paste in code) and put it in a file at path blah/blah/blah and nothing happened.” THAT we can provide help for.

So far what you’ve asked for is for us to do it for you. And we don’t do that because it ends up becoming a huge time sink for all of us. For a one liner Rule like this “show me an example” literally is “do it for me.” And you’ve shown no attempt to do it yourself.

Don’t know where to save the Rule file?

Don’t know what format a Rule should have?

Don’t know how to cause a rule to trigger periodically?

Don’t know how to send a command to a Group Item?

Don’t know how to put it all together?

So either you didn’t bother to read the docs or use the resources available to you or you did in which case you need to tells us exactly and specifically where you went wrong. Don’t like reading docs? Prefer Videos? If you had bothered to click on the link I provided in post 15 above you would have encountered a bunch of great video guides that will help.

We have all provided just about everything you need on this thread to do what you are after. But you have not bothered to even click on the links. You just want what you want exactly the way you want it.

We all have wives and kids and families too. We don’t sit up through the night coding up other peoples home automation system for them. We don’t even do so for our own home automation systems. But if you think you can get away with building a home automation system without learning to write Rules you are in for disappointment. If you can’t or wont use the resources provided to you, and there are thousands of man hours of effort provided to you in documentary and explanatory effort in the links that exist in this thread that you have ignored, you will not be successful with openHAB.

If there is something specifically not clear in these docs, tell us and we will try to make them better. But so far all you’ve done is ask us to do it for you. It doesn’t work like that. You have to be able to read the docs and apply them to be successful with openHAB or any home automation system really.

And yes, we are spending way more time here on these posts telling you what to do but not coding it for you for a reason. If we give you a fish, we’ll be stuck being your fisherman forever. If we teach you to fish than ultimately we have more time to help more people.

As I like to say, our time has value too. None of us are getting paid for this.

1 Like

Lol. Oh Rich that was priceless. How much time have you guys invested in writing essay on this “basic stuff” to use words above. Would it not be much simpler to paste the code, quciker, easier and far far less time. That’s where I needed help, having read the docs , I’m not good enough yet to complete the job.

Im still LoL at your statement above. My sides…

Rich, youre asking me the question, so your posing a load of questions to A QUESTION. It doesnt get better does it.

Ok , well now that you post that I went here:
http://www.cronmaker.com/
So now I have learnt something - See! My method works.

I get that you once were stupid like me, and had to start somewhere, but unlike you Rich I am neither interested nor inclinded to become an expert in OH. I asked a specific question which until now, several hours later and hundreds of lines in posts, you have answered. I am most grateful to you Rich, now I shall play with this and other rules and items to get what I want and how I want it to work. This is a great help Rich. Thanks

p.s. your first Time "cron … " should be Time cron "…:slight_smile:
AND
It’s erroneous …

2020-01-02 22:02:00.216 [WARN ] [lipse.smarthome.core.items.GroupItem] - Command 'ON' has been ignored for group 'g_Refresh_TRV' as it is not accepted.

I’ll need to debug your solution,

anyone else have an idea on WORKING code? This is getting silly, all day on this forum to get a bloody simple TRV status.

That’s because the items in the group are not the same type

Yes Rich, Ive just noticed.
My topics need to be an empty string so I changed the trigger to

g_Refresh_TRV.sendCommand(new StringType(""))

All working THANKS Rich, albeit on a cron job. To preserve battery in the TRV I only want to send commands when a “REFRESH” button is pressed on HABpanel. I will need to do more digging on this but for now at least the TRV is working and reporting.