Jump to content

MQTT message with retain parameter


Recommended Posts

If I understand the question, you are asking if I want to display the message on the device display? if is this the question the anser is, no.

I only need to retain the message on the MQTT broker.

The usage is to have a system thats connects to the broker and gets the retained message from the Shelly H&T Gen3. Today, without retain, the message doesn't exist, on the broker, when this systens make the connection.

Link to comment
Share on other sites

I second this.

I currently have a few shellies (uni plus in this particular case) where the messages are not sent with retain: 1, so whenever home assistant (or any mqtt client) connects the value shows as unavailable.

Is there a way to make shelly send messages with retain: 1?

Link to comment
Share on other sites

Yes the script can be used. But it's kind of a work-around in this case since you need to build a script into the device itself in order to publish a message in a topic and set retain=true.

What I'm after is the ability to set retain for the native topics that the device publishes to. That way, if for whatever reason I restart my MQTT client (and it happens reasonably frequently with HASS) I don't need to wait for an update to the topic by the device to set the value of the entity since retain=true it'll get the last message.

Link to comment
Share on other sites

Anyway I've taken what @If_then_else said to heart and created a simple script to update the voltage and set retain==true.

https://github.com/tintii/shelly_scripts/blob/master/publish_voltage_mqtt.js

note this comes with some caveats, since MQTT messages are not retained by default, if the script is not run periodically then the value of the last time the script was run will be retained.

 

cheers

Edited by tintii
clarity
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...