Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: MQTT Birth implementation #418

Closed
starwolf73 opened this issue Mar 15, 2019 · 17 comments
Closed

Feature Request: MQTT Birth implementation #418

starwolf73 opened this issue Mar 15, 2019 · 17 comments

Comments

@starwolf73
Copy link

Hi,
Using Home Assistant HASSIO and MQTT pluging, I'm trying to find a way to trigger when Milight_hub connect/reconnect to the MQTT server to assigned an automation task.

Is it possible for the device to announce himself in a specific topic? Unless there is already a feature in MQTT Mosquitto I didn't saw.

Thanks
Eric

@sidoh
Copy link
Owner

sidoh commented Mar 16, 2019

Hi Eric,

The 1.9.0 dev branches support MQTT LWT, which sends a message to a specified topic when the device disconnects.

There is not currently a way to send a message when first connecting, but that wouldn't be terribly hard to add.

@starwolf73
Copy link
Author

starwolf73 commented Mar 21, 2019

Thanks @sidoh. I believe the feature is call MQTT Birth https://www.home-assistant.io/docs/mqtt/birth_will/ I'll rename the title for sake of clarity.

@starwolf73 starwolf73 changed the title MQTT Connection status Feature Request: MQTT Birth implementation Mar 21, 2019
@sidoh sidoh added this to the 1.9.0 milestone Mar 24, 2019
@sidoh
Copy link
Owner

sidoh commented Mar 24, 2019

This is released in 1.9.0-dev10.

@starwolf73
Copy link
Author

Thanks, I'll give a try this week and provide feedback.

@rejoe2
Copy link

rejoe2 commented Apr 12, 2019

E.g. tasmota by default uses the LWT to inform about the online and offline status. I personally found this helpfull, but afai can see, there's no option to configure a "opposit to LWT" message.

So is there an option to add also a online LWT message when the hub is connecting to the broker to revoke e.g. "offline"?

@sidoh
Copy link
Owner

sidoh commented Apr 12, 2019

Yes, it's in the 1.9.0 branch, as mentioned above. Try the RC release:

https://github.com/sidoh/esp8266_milight_hub/releases/tag/1.9.0-rc2

@rejoe2
Copy link

rejoe2 commented Apr 13, 2019

My remark already refferenced to version 1.9.0-rc2. Both message types (LWT and birth messages) are great! But one has to "clean up" the LWT message "manually" on the HA controller side (may be different in HASS), as there is only one message to the LWT topic, but not a second, indicating the hub is online again. This one (birth) is to a different topic and in a different structure - single word payload (or whatever is configured) vs. JSON.
So my suggestion would be to also send a second "birth" message info to LWT also (same way as eg. tasmota devices do).

@sidoh
Copy link
Owner

sidoh commented Apr 13, 2019

Okay, I understand the suggestion now. But not sure I see the value. Why should it be the same topic? Why should it have the same structure? Is this some standard that I'm not aware of? If it's a broad thing that many MQTT integrations do, happy to consider it. If it's just a particular arbitrary way of doing things, I think I'll probably pass.

@rejoe2
Copy link

rejoe2 commented Apr 13, 2019

Same topic, same structure: My HA software expects the same type (JSON/non-JSON), otherwise I have to add a more complex message treatment (which is possible).
Looking at the IBM official guide at https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.1.0/com.ibm.mq.doc/tt60360_.htm there's at the end of the text:

To monitor connections, complement the "last will and testament" publication with other publications to record connections and programmed disconnections.

So imo the tasmota implementation - just sending "Online" and "Offline" seems to be very close to the inventor's description of the intended behaviour. On the other hand, at least imo, there's no need to make the LWT message configurably at all, if, an option to manipulate the time before LWT (when disconneted) is sent used by the broker.

@sidoh
Copy link
Owner

sidoh commented Apr 14, 2019

Ah ok, I see the rationale. It's a single topic that indicates device status. That is nicer.

What if I change this to have a single topic used for LWT, birth, disconnects, etc.? It could have all of the same information that the birth message does (with IP address, firmware version, etc.), and also include a "status" field which could be one of connected, disconnected_clean, or disconnected_unclean.

How does this sound?

@rejoe2
Copy link

rejoe2 commented Apr 15, 2019

No need for end-users to configure things twice, plus additional info privided.
Imo that sound great!

@sidoh
Copy link
Owner

sidoh commented Apr 15, 2019

@sidoh
Copy link
Owner

sidoh commented Apr 15, 2019

Thank you for the suggestion!

@rejoe2
Copy link

rejoe2 commented Apr 15, 2019

Thanks a lot for implemeting that fast!
V. 1.9.0-rc3 is up an running grin

@lightning1
Copy link

This looks quiet nice. But sadly, Homeassistant does not support extracting values from json when it comes to availability. To use this with HA flawlessly, a predictable payload to a fixed topic is required (e.g. "ON" or "OFF").
See Homeassistant MQTT Light documentation for details. Lookout for the settings:

  • availability_topic
  • payload_available
  • payload_not_available

@sidoh
Copy link
Owner

sidoh commented May 19, 2019

Yeah, I noticed this as well. It probably should support templates for this, but I don't have the bandwidth to open a PR for it right now.

I'll add a setting to support simple client status messages (will just hardcode "connected" and "disconnected").

@lightning1
Copy link

lightning1 commented May 21, 2019

Great, this worked out quiet well.
Thank you, keep up the good work!

@sidoh sidoh closed this as completed May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants