MQTT Agents Publish subscription

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

Hi Denis
I hope you finally solve the problem.
btw, i use “Adafruit_MQTT_Library”. but because of SSL/TLS MQTT setup on Openremote, you must use client in a secure manner. see the example of library

Good Lock

2 Likes

Hey,

yes i solved it by myself. Thank you, sir!

Hi,

There is no way to write multiple attributes via a single MQTT topic at the moment and not sure it would be very ‘MQTT like’, can you describe your use case i.e. why you cannot publish each sensor value to its’ own MQTT topic?

1 Like

Hi,
Thank you for your response. I’ve already send small JSON data to MQTT on other project (i am not sure if it is MQTT friendy :slight_smile: ). i was curious about how can i use this in OpenRemote.
I will publish sensor data with it`s own topic.