-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Home Assistant MQTT Template #1314
Comments
It seems that openHAB now have gone from having a starting https://docs.openhab.org/addons/bindings/mqtt1/readme.html So based on these new info I'd say we could at least change the default to |
If OpenHAB and HomeAssistant are different, we could add a new controller, which will share a lot of code between them, but have their own implementation where they differ. So please try to think of the best topic template for Home Assistant. (and for OpenHAB if the current one could be better) |
Related to this topic. Eclipse Smarthome (OpenHab is based on this) gets a shinny new MQTT stack while I'm writing these lines. Some research went into auto-discovery of (IoT) devices and published sensors/actuators. The need for devices to describe themselves and their capabilities is inherent. To form some sort of standard (convention on top of MQTT), members of the OpenHab community collaborated with the creator of the Homie convention. It would be very convenient if ESPeasy could speak Homie 3.x and allows easy point and click integration in future OpenHab versions. |
Sounds like a good idea. Too bad you have to read documents like this. An audiobook/podcast would be great, since I'm behind the wheels about 10 - 15 hours/week ;) |
Has there been any discussion/progress among the team in implementing one of these standards (Homie or HomeAssistant) within the ESPEasy Controller? @davidgraeff 's newest MQTT binding in openHAB is now live (https://community.openhab.org/t/mqtt-binding-version-2-4/53811/55) and supports auto-discovery of MQTT topics, as long as they're defined in the Homie/HomeAssistant format, as I understand it. It would be excellent if I could convert all of my sensors to use this, rather than having to manually build them into my openHAB configuration... |
Do you have an easy to read document on how such an auto-discovery should look like? |
This is the official convention that I could find for Homie. There seems to be a lot of topics that need to be populated for auto-discovery, but, I did see an issue (homieiot/convention#45) opened that aims to thin down those topics to a minimal set of required ones. |
It looks like well documented and elaborate. So can you give an example, for me to get a feeling about this discovery, to for instance let a switch input be discovered. |
A "in a nutshell" paragraph is missing, indeed.
That's it! |
@bkpsu Please refer to the web-page https://homieiot.github.io/ instead of the repository. The repo contains the latest/in-development specification, and is not meant to be used for implementers. |
I currently start my home automation new from scratch. The "old" system was based on openHAB 1.8 and mosquitto MQTT server and a lot of openHAB code. I waited a wile until openHAB 2.x settled. Recently I discovered that with Version 2.4 openHAB committed to MQTT by integrating a MQTT server inside as a binding - great!. With some rules and a little mod of the MQTT-import plugin to receive true and false payloads It is possible to get sensors and actors running ESPEasy autodiscovered and working with no line of code, rules or conf files. I'm planning to implement a controller plugin for homie and/or home assistant. For a "proof of concept" I did a test implementation which works out fine
after a few seconds a new thing is detected So with the little mod of the source code to handle incomming true/false msgs by the MQTT import plugin the relais work. And it is usable after a few clicks. Now I'm planning to implement this as a controller plugin to do most things automatically.
My "only" concern is adding/deleting devices as the retained flag should be set. There will be the need of a little bit of housekeeping to get rid of unused devices/nodes: With the above rules "New Thing" and "Thing updated" is working inside paper UI.
so with every reboot the header and node informations should be send/updated. If a user do modifications a reboot once he is happy is better than having openHAB handle "half backed" configurations with every change. Finally I like the home assistant spec a little bit better because of less topics with JSON formatted payload but I first took a look on the homie as recomended by @davidgraeff
So my questions are:
BTW: I'm totally new in contributing to an open source project and so please be partitioned. |
These look like they can be incorporated in an extension to the existing OpenHab controller. Maybe we must also add something to the plugins themselves, or to a group of plugins. |
I would not extend the openHAB controller, which should only stay as a legacy controller (or be removed, depending on your backwards compatibility policies). openHAB is now fully compliant to the MQTT Homie specification and for OH 2.5 we aim to be fully compatible to the HomeAssistant MQTT-Components specification. A Homie convention controller and a HA-controller is fully sufficient.
Homie tries to stay json free, that's true. But HA MQTT has the issue that they are not generic. They have specified a set of components and that's it. If your device has more features or does not fit into one of the components you are out of luck with their specification. That's why I think both conventions should be considered.
That is actually happening. But the OH core does not remove a once-seen thing or channel, no matter what the binding requests. There is an issue on our issue tracker and also a PR. Might be fixed for OH 2.5. |
I agree to start with a new "homie" controller and perhaps a extra homeassistant controller later when openHAB 2.5 is ready. Looking into homeassistants definition I agree that there are some limitations. as tools like mqtt-forget are available and openhab ignores old $nodes there should be no problem with "housekeeping" |
Hello or doese the build in mqtt server recognizes the retained flag and "consumes" it? |
The mqtt specification allows MQTT servers to ignore the "retained" flag if QoS is 0. Might that be your problem? |
The question is if "retained" is nessesary for autodiscover? And if so should I use a higher QoS? |
Retained is not necessary and only affects how the server processes and stores messages. openHAB will use whatever message it receives. |
Fine, than I‘ll not wasting my time on this any further. |
I finished 1st draft version of the homie protocol/controller plugin (I called it c014 for now if it's ok) currently the basic discovery for sensors is implemented. Incomming messages are the next task. I ran into several issues:
Every comments and help welcome. I committed the plugin and some changes in the framework to my repro. |
@Christian-Me : Could you please link your repo here (with the correct branch preselected)? That saves people time, who are willing to have a look. I also suggest that you create small PRs for required framework changes separately and try to get those in first. Your repo/branch should at the end only contain your new controller. |
For now it is only possible to have 1 MQTT controller active in ESPeasy. About the queue system used for controllers. For testing purposes you can increase the limits of those queues, but keep in mind they tend to use a lot of memory if they retain the entire MQTT message. If you need to process the items in the queue, please have a look at the function As can be seen there, the scheduler is having an entry for handling the MQTT delay queue and processing incoming messages. So please try to use the existing MQTT functions as much as possible and if there's something missing, don't try to interact directly with PubSubClient, but try to find a way to use or extend the code in ESPeasy. Also note that we're not using the same code as on the official PubSubClient Github. |
you can find my 1st attempt here complete fork The autodiscover information for my test setup are more than 20 topics (10-12 for the system information, 3 for every device and 2 for every value) so expanding the queue is not an option I think. I used the following code for each topic (example for the system name):
This works fine in most cases. The plugin will need 4 new events
I'm not sure were to place the function calls. |
Well at first I would suggest to make a separate function to show the extra plugin functions needed. About the queue for all those topics. Edit: |
The plan is to create a controller plugin to be as close as possible to the homie convention without changing code inside plugins and as less as possible in the firmware. In the beginning I thought I could uses the INIT message but this is to early in the boot process.
All required messages for sensors can be acquired without any change in plugins leaving the unit open. Can you point me to an good example controller how a enum could be implemented? Every topic acording to this scheme homie/%deviceName%/%nodeName%/%valueName% Sending Values work "of the shelf" by sending to "homie/%sysname%/%tskname%/%valname%" It would be good that beside the value name a value Unit can be selected currently °C Degree Celsius, °F Degree Fahrenheit, ° Degree, L Liter, gal Galon, V Volts, W Watt, A Ampere, % Percent, m Meter, ft Feet, Pa Pascal, psi PSI, # Count or Amount. I can thing about some more Hz, Ah, Wh, VA, LUX, .... Hey this started looking like a quick hack and going to be a real task, Its the first time in contribute to an opensource project ... |
Totally agree on that. It should be protocol first.
Den tors 11 juli 2019 23:28Misiu <[email protected]> skrev:
… @Grovkillen <https://github.com/Grovkillen> if this can be set via front
end then even better, but please another option to Protocol dropdown. I'm
aware that we can just edit Controller Subscribe and Controller Publish
but why should we choose openHAB if we want Home Assistant, that's
confusing for new users.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1314?email_source=notifications&email_token=AGLYCYTYAPN66HFT5FWDZPDP66QYRA5CNFSM4E4LF2MKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZYBBBA#issuecomment-510660740>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGLYCYUV4FZ4K4H5LVWZ4JTP66QYRANCNFSM4E4LF2MA>
.
|
@Grovkillen I see all the HTML comes from |
Currently there can be only one MQTT controller active. |
@TD-er so the easiest way would be to add new controller (Home Assistant MQTT), but as @Grovkillen suggested here we should reuse existing controller. |
What are the exact differences between Home Assistant MQTT and OpenHAB MQTT? |
@davidgraeff could You please help me with this one? The changes are minimal, @ferazambuja posted them in the first post here. Controller Subscribe: home/%sysname%/# (instead of /%sysname%/#) If Maybe name like |
I think this is the way to go if the only difference is the default topic. |
@TD-er I'm relatively new to both Home Assistant and openHAB so I'd like to ask more advanced users for confirmation. I base my answer on official HA docs and my short experience. |
openHABs preferred MQTT convention is Homie. But openHAB also supports the HomeAssistant MQTT convention. A name like this "Home Assistant (openHAB) MQTT" will do. Because it's their standard I would suggest to name Home Assistant first for the label and openHAB only in parentheses. |
Please remind me if I didn't reply this evening. |
I don't see a reason for this javascript or UI part. The openHAB implementation mimics the Home Assistant implementation. Right now it expects "homeassistant" to be the first topic part as seen in the sources: This could be configurable, but I do not see why. The HomeAssistant guys should instead settle on a good default (like for example "homeassistant" so what we can all agree on how to perform discovery). I propose to change the HA documents and swap the suggested "home" with "homeassistant" or get a confirmation from a HA dev, that they want to keep "home" and I will change the openHAB implementation. No matter what, a UI or different topics for both systems are not necessary. |
@Misiu
The current (old) templates are not (strictly) correct because mqtt toppics do not start with an "/". This results in an empty root topic: Here my last device running with C005 @davidgraeff : When can we expect a new openHAB milestone build or a snapshot where the mqtt issues are fixed. I currently still run into several problems (during testing C014 & P086).
All problems seems to be a result of openHAB stops receiving messages. Still have to use Mosquitto because of the QoS problem (see above). |
I'm not involved in the release process of openHAB. Could happen at any time when someone presses the release button. The mqtt update problems are related to the used paho mqtt java library which is shit. A migration to the hivemqtt library is probably required but I do not have time for that. But back to the topic: The protocol template would need a "homeassistant" base topic as well. |
Can you describe what is happening when OpenHAB stops updating values? Also ESPeasy is not perfect regarding network stability. For example a WiFi disconnect may not always be detected in ESPeasy itself, which may lead to strange behavior. Most of the times a WiFi reconnect does lead to WDT reboots, which is -in this use case- the preferable solution since it forces a proper reconnect. |
Currently performing many tests on "real hardware" with the Homie Plugins together with MQTT Explorer (which is a great help) showing that ESPEasy even when running complex rules is quite stable and can perform well even after a reboot (using RTC memory / retained mqtt messages). |
@TD-er @davidgraeff I've created PR that renames C005 plugin. Should I also change topics in C005 and add |
At least some topic descriptions/examples in the documentation would be fine. |
@TD-er, as mentioned in my PR Home Assistant, doesn't have a base topic (prefix). @davidgraeff can openHAB ignore first part? Currently |
Might be correct. But than there is no proper way to detect HA components. In Homie we have "something/{deviceid}/$homie" to recognise the Homie convention. |
@davidgraeff because of Homie there is the ability to do autodiscovery in openHAB. HA doesn't support Homie (hope this will change), but what about the old way? Was there some kind of auto-discovery? |
MQTT doesn't enforce any topic layout. There is no way of performing auto discovery. That's why those two conventions emerged. But I thought that HA had a fixed default topic. Without that, it is not really suitable for auto-discovery, I guess. |
Can #2517 get merged? @TD-er @davidgraeff any comments? Something missing? |
@Misiu I guess it can be merged, but not right now, for several reasons.
That last point is mainly why I will not yet merge code into the mega branch. If I merge code, it will trigger a rebuild and that one has about 50% chance of failing to connect to WiFi. A gamble which is unique for each and every bin file in the ZIP. |
@TD-er no worries 🙂 |
#2517 is merged so I guess this can be closed? |
Yep. |
Currently, Home Assistant users use the Openhab MQTT template changing the Controller Subscribe and Publish.
As stated in home assistant documentation:
https://www.home-assistant.io/components/sensor.mqtt/#get-sensor-value-from-a-device-with-espeasy
Controller Subscribe: home/%sysname%/# (instead of /%sysname%/#)
Controller Publish: home/%sysname%/%tskname%/%valname% (instead of /%sysname%/%tskname%/%valname%)
Since this is such a simple change wouldn't be possible to add the template?
Besides naming is just this two lines from _C005.ino:
The text was updated successfully, but these errors were encountered: