stjohnjohnson / smartthings-mqtt-bridge

Bridge between SmartThings and MQTT
https://hub.docker.com/r/stjohnjohnson/smartthings-mqtt-bridge/
MIT License
368 stars 243 forks source link

Retain flag per device #159

Open marc-gist opened 6 years ago

marc-gist commented 6 years ago

Is there anyway to set if the retain flag should be true/false for a particular device?

I have buttons in SmartThings, that i don't want the "press" action to be retained in the broker.

Thanks,!

andrewsayre commented 5 years ago

I'm running into the same challenge -- button presses (events) get published with retain which causes downstream consumers (like Home Assistant) to trigger whenever they are restarted because it thinks a new event was fired. Turning retain off globally would fix his problem but introduce sync issues with all the stateful devices. Perhaps the configurable precision should be down to the type/property level. For example, I have devices that expose both a switch and a button. I'd want "smartthings/device/switch" to be published with retain and "smartthings/device/button" not to be.

Looking at the code, this would need to be implemented in the nodejs component. I see two viable options:

  1. Extend the configuration to allow specification of retain by device, property, or device and property.
  2. Add logic for "button" and other event-type properties to always publish retain = false. (Why would someone ever want a button press event to be retained anyway?) Other portions of the code have intelligence for specific properties (switch and level) so I don't see this as a major SOC issue.

Thoughts on the approach? I'm learning more to the second option because it would be far simpler to implement and can work on a PR if others agree. :)

rwarner commented 3 years ago

Also running into this issue. Was resetting the docker container every night at 11 pm, coincidentally lights were turning on-off off-on at that time which I wasn't sure why until I realized the retain flags send the press or push along on the restart of this docker container.

Agreed @andrewsayre #2 seems to make sense