seb821 / espRFLinkMQTT

ESP8266 gateway between RFLink and MQTT server
96 stars 32 forks source link

Feature Request: Ability to Set Retain on Published Messages #7

Closed TimothyGaray closed 4 years ago

TimothyGaray commented 4 years ago

A feature that I haven't easily been able to figure out how to add myself to the sketch would be to set the MQTT published message with the retain=1.

Case: door/window switches send code when their state changes such as the door opens. If home home automation software (Home Assistant) is not running or is rebooting at the time then it will miss that message and think the door or window is closed when it is actually open.

Setting the message to be retained will keep it available for when HA comes back up.

I'm not sure the impact for all published messages being retained or if it would really matter. Ideally the ability to specify which IDs get retained messages would be nice.

Thank you. Aside from some little tweaks, this has been working nicely for me.

-TimG

seb821 commented 4 years ago

Hey,

See PubSubClient documentation.

Try to replace

MQTTClient.publish(MQTT_TOPIC,JSON);

with

MQTTClient.publish(MQTT_TOPIC,JSON,1);

I will keep the issue open for now and think about adding a setting for that.

TimothyGaray commented 4 years ago

Thank you, I will give that a try.

seb821 commented 4 years ago

Implemented in the dev branch