MQTT Agents Publish subscription

Hi All

Thanks to @Rich i could solve the problem to connect Openremote to external MQTT broker and receiving data an this to an Attributs.

Now my problem is how to select info if the mesaage is a json file

Mqtt msg

i like to create an Attribute and show only ID message

This is what i am doing

What i am doing wrong?

Thank you in advance
Salva

Hi,

If I understand your question fully, you’re MQTT broker publishes messages in JSON format and you would like to extract values from that?

If this is correct then you can use the Value filters parameter of the Agent link to add a JSON path value filter that accepts a JSON path expression (see https://jsonpath.com/).

Hi rich

Thank you for your answer. Yes your advise what help full.


But to received this message i need an action. If you see how i run this action on MQTT-explore

Publish topic: shellies/shellyem-XXXXXX/command
Payload: announce

How i can do this with Openremote.

Thank in advance
Salva

OK to publish you need to set the Publish topic parameter on your Agent link; you can then add the Write value parameter to you Agent link to specify a payload that should be sent on publish, this payload can have within it the special placeholder {$value} which will be replaced by the value that you actually write to the attribute.

Imagine you have a number attribute representing the brightness of a light (0-100) and you need to publish a JSON message like:

{
  "brightness": 0-100
}

Well if you use the {$value} placeholder then you can dynamically inject the 0-100 value as it is written to the attribute:

{
  "brightness": {$value}
}

If you want to publish a static message then don’t include the {$value} and whatever is in the Write value parameter should get published no matter what is sent to the attribute.

If this doesn’t cover your scenario then please provide more details.

2 Likes

NOTE: There was a bug in the Agent link UI which rendered the Write value parameter as single line input only this has been fixed in latest commit which will appear in the manager docker image shortly

Hi rich

my device send mqtt message automatically like this:

  1. Subscription
    shellies/shellyem-XXXXXX/emeter/0/returned_energy (value energy returned to the grid in Watt-minute)

once i subscribe to this topics i can read the value.

But some data on the device i need a publish action to received data like this:
2. Publish
topics: shellies/shellyem-XXXXXX/relay/0/command (accepts on, off or toggle)
Payload: On or OFF or togggle.

Now my question is how to create on Openremote a publish topics with payload.

If I use shellies/shellyem-XXXXXX/command Payload: announce

The result of this publish topics is:

{
“id”: “shellyem-B040F8”,
“model”: “SHEM”,
“mac”: “84CCA8B040F8”,
“ip”: “192.168.3.10”,
“new_fw”: false,
“fw_ver”: “20211109-131205/v1.11.7-g682a0db”
}

After i can use Value Filter if i like only “ip” data.

Thank you in advance
Salva

Hi,

I think I understand a little more clearly; you want to subscribe to a topic but data is only published to that topic by first publishing.

Is this a one time request and static data is returned or do you need to keep sending the request periodically?

The MQTT Agent doesn’t currently support this; we have similar funcionality to this in the Websocket Agent I will need to look at providing something similar for MQTT Agent but until then you could use a rule to try and achieve it in combination with the Write value parameter and Rule state configuration item on the MQTT Agent agentStatus attribute:

This rule should try writing to the attribute in the Then action whenever the MQTT agent becomes connected.

NOTE: You will need a manager image newer than this post to be able to create a When-Then rule for an agent

Hi @sdepascali @Rich Can you please tell me how you receiving and send data . here I am able to connect MQTT Explorer with MQTT broker (Openremote) but I am not able to understand how to send a demo mqtt data also I am not correctly configure assets, attribute, rules. So please make a video where we can send and recived mqtt demo data.

Thank you
vicky kumar


Why attribute is showing waiting while connecting to my localhost.

please help me out
thank you.

Hi,

It’s not clear if you’re trying to connect to the OpenRemote MQTT broker (discussed in this post) or you are trying to connect OpenRemote to an external MQTT broker as discussed here.

Thank you for your reply. Yes I am connected my mqtt explorer with open remote by following this link Notion – The all-in-one workspace for your notes, tasks, wikis, and databases. but after that it’s showing WAITING on openremote.

MQTT explorer is an MQTT client for connecting to an MQTT broker. You don’t need to create an MQTT agent in OpenRemote to be able to connect to our broker, just need a service user which is clearly described in the article you have referenced.

2 Likes

hi @Rich by following the link Tutorial: Connect your MQTT Client · openremote/openremote Wiki · GitHub. I am able to Establish a connection from client to broker. but I have doubt in “Subscribe to attributes using the MQTT API” and “Publish attribute values from the MQTT client”. where I need to write this example-- master/client123/attribute/subscribeAttribute/6xIa9MkpZuR7slaUGB6OTZ and this example–master/client123/writeattributevalue/writeAttribute/6xIa9MkpZuR7slaUGB6OTZin mqtt explorer or open remote. if openremote then where in openremote.


Thank you.

Hi @Rich
I am following the link https://github.com/openremote/openremote/wiki/Tutorial%3A-Connect-your-MQTT-Client and successfully Subscribe attributes using the MQTT API. but I don’t know how to Publish attribute values from the MQTT client.
there are some step that are mention to publish but I am not able to understand 1—how to Define the correct topic. For directly writing an attribute value:{realm}/{clientId}/attribute/{attributeName}/{assetId}
2-- 1. Send the JSON over this topic. For a Number, this is really simple: 23
3–. Go to the Manager and check if the value updated!
Thank you
vicky kumar

Hi,

The tutorial you referenced seems pretty clear about how the publish topic is structured and is explained in more detail in:

If you have managed to subscribe then you already build valid subscribe topics, the publish topics are not too different.

If you mean it doesn’t work for you then please provide details of your asset attribute(s) and configuration items.

Hi @Rich Here I am trying to show how I publish data from using mqtt explorer to openremote.




I need to write topic manually of writeAttribute. also I write same writeattribut in “ADVANCE” of mqtt explorer. so am I doing correct or not.
Also have some document or link how to connect , send and receive data openremote with raspberry pi

Thank you
Vicky Kumar

I don’t even see any port 8883 exposed from the manager container?!

Looks like you’ve successfully managed to publish to your attribute(s).

As I just posted in the other topic; TLS termination is done at the proxy service.

Hello
I have successfully connect my esp8266 MQTT client to OpenRemote MQTT server.
I have published the sensor values from esp with " {realm}/{clientId}/attribute/{attributeName}/{assetId}" based on Wiki.

The question is, how can i send multiple values of my esp with one JSON data?
for example, i want to send Temperature and Humidity like this:

{
“assetId”: “5qHzqKaANyPCrJlFSS8eYM”
“temp”:“22”,
“humidity”:“59”
}

I have tested this " {realm}/{clientId}/writeattribute " without any success and I’m sure JSON format that i sent, was wrong.

would you please help me?

Thank you