-
Notifications
You must be signed in to change notification settings - Fork 288
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
MQTT: refactor messages for better home assistant integration #134
base: master
Are you sure you want to change the base?
Conversation
Oh rad. I'll upgrade for this change. |
I am not sufficiently familiar with Home Assistant to tell. From the firmware point of view, it would make sense to maximally reuse what the HTTP API already has. For example, to trigger a manual program run, the client can publish a message to topic /mp, with payload the same format as the HTTP API command (or to make it conform with json format, the payload could be something like {"cmd":"xxxxx"}. Reusing existing code paths can help minimize the amount of work and also make it easy to adapt when we introduce additional API commands in the future. |
This is where I've been reading to implement some code that reads from MQTT to do useful things, like export metrics to a prometheus exporter. https://www.home-assistant.io/docs/mqtt/discovery/ I don't use home assistant, but the structure there seems to be where lots of IOT development is rallying around. |
Thanks for the feedback. I feel it's going in the right direction. I have updated the PR description with a new proposal 2:
I haven't updated the PR yet, I'm waiting for your comments |
Should we also insert a unique id or MAC in the topic so we can support multiple units? opensprinkler/00:11:22:33:44:55/system/power_state |
The right approach for this would be to allow to configure the node name through the interface when MQTT is enabled. The node name is the first element in the topic and it is currently hardcoded to opensprinkler.
|
In terms of an ID for the device, I like this approach pretty well: You have to keep inventory either way, and I do still want to know the MAC somehow, but perhaps reading from The rest of what you have there I think is a great start. That Anavi code does something else interesting which is to publish a "config" about the object when a new MQTT client connects to the broker. I've not dug in completely on how that is being achieved, but its easy to simulate with |
We might be covered already by the work done in #124. |
…s in the future Implemented Proposal2
I have updated the PR with my proposal 2 |
Please push after boot not only availability, but also the state of the variables like current water level, rain delay, operation status. |
Some thoughts on the messages below:
I think the
Should we add intended duration to the payload given that it can vary based on watering level.
I think it would be better to add
I know this matches IFTTT message but not sure of the use case for sending This message is only generated when the programme queue is emptied and I'm not sure how people use this to be honest. I think we should move to something more like the App where the current flow rate is published say every 30 seconds. That would allow users to setup alarms if the flow rate is below a certain value when a particular station is running or flow is present when system is idle.
Should this use the more generic |
@jbaudoux do you plan on getting these changes merged? The MQTT version has been working great for me -- would be really interesting to start accept |
I wonder if we should not change the way the messages are published to be more close to the several integrations existing in home assistant
https://www.home-assistant.io/integrations/mqtt/
This would allow in the future to also listen to "..../set" topics to receive commands
I know that json can be parsed in home assistant, but as the MQTT feature has not yet been released, it's still the time to ask our self if we should not do this small change to ease the integration.
Relates to initial issue #103 and my comment here #130 (comment)
Not tested
Before
topic: opensprinkler/system
payload: {"state":"started"}
topic: opensprinkler/station/<id starting at 0>
payload: {"state":1}
topic: opensprinkler/station/<id starting at 0>
payload:
if flow sensor configured: {"state":0,"duration":[integer],"flow":[float]}
else: {"state":0,"duration":}
topic: opensprinkler/sensor/flow
payload: {"count":[integer],"volume":[float]}
topic: opensprinkler/sensor/rain
payload: {"state":0/1}
After
topic: opensprinkler/system/power_state
payload: on
topic: opensprinkler/station/<id starting at 0>/state
payload: {"state": "on"}
topic: opensprinkler/station/<id starting at 0>/state
payload:
if flow sensor configured: {"state": "off", "duration":[integer],"flow":[float]}
else: {"state": "off", "duration":[integer]}
topic: opensprinkler/sensor/flow/state
payload: {"count":[integer],"volume":[float]}
topic: opensprinkler/sensor/rain/state
payload: "on"|"off"