gaetancollaud / digitalstrom-mqtt

Bridge between digitalSTROM and MQTT
GNU Affero General Public License v3.0
23 stars 4 forks source link

deviceType fitting HomeAssistant "MQTT Discovery" #25

Closed Druesel closed 2 years ago

Druesel commented 2 years ago

Hi gaetancollaud

Is it possible to config this tool to fit the supportet MQTT Discovery device types of HomeAssistant? For example "Lights" "Sensors" "Switches" and so on https://www.home-assistant.io/docs/mqtt/discovery/

In addition it is nessesary to put some information as json payload in a /config topic. Would be perfect if it would be possible to config this payload also with static and dynamic parameters.

Otherwise it is necessary to configure every single device manually in yalm, or is there a misunderstanding on my side? So this would be a real big advantage to everyone using HomeAssistant and maybe other smart home systems.

Thanks for feedback and best regards Andreas

gaetancollaud commented 2 years ago

Hello @Druesel ,

Since MQTT has no real standard I didn't want to implement a "proprietary" one. But I know that in the end half of the people are using HomeAssistant (I don't use it myself).

This project is open source and I'm willing to accept pull requests for this. My only requirement is that this function has to be disabled by default and we should have a simple switch. Something like HOME_ASSISTANT_DISCOVERY_ENABLED=true in the config.

I'm also open to the homie convention (which is not bound to any automation system): https://homieiot.github.io

Cheers

albertomontesg commented 2 years ago

I have started to work on this and most likely will have some implementation done soon.

albertomontesg commented 2 years ago

Regarding the homie convention, that is completely orthogonal to have MQTT discovery in Home Assistant. What Homie tries to do is to define which should be the topic structure to setup the devices, their values and how to update them. At the same time it tries to add metadata by adding additional topics.

MQTT discovery for Home Assistant aims to provide directly the Home Assistant configuration for a device stating the topics and expected payloads to control that device. You could have any MQTT topic structure in your project (and I have seen multiple projects having their own way to specifying them), but then you are only configuring Home Assistant to read those.

gaetancollaud commented 2 years ago

I didn't know how homeassistant MQTT was working before your implementation. It's quite clever actually (to adapt to any convention). So at the end we could implement the Homie convention, and still use homeassistant discovery, that's cool. I won't do it though as it would not be retro compatible.

And no one requested homie anyway.

Thank you very much for your PR. it's really appreciated.

gaetancollaud commented 2 years ago

I'm closing this one since 1.5.0 was released. Please open new issues if something's wrong with the implementation.

Thanks again @albertomontesg

Druesel commented 2 years ago

Hi @albertomontesg Really great! Thank you very much for your commitment. I am unfortunately already a bit far away from the actual programming, that would probably have cost me weeks. I just tested it and all devices could be detected automatically.

Is there also a way to read out and trigger the scenes or even the actions and states in addition to the devices?

Unfortunately I can't really get involved in the implementation, so I would like to donate both of you a coffee, a pizza .... Is there somewhere a dedicated button?

Regards

gaetancollaud commented 2 years ago

Not sure about the implementation of homeassistant, I guess @albertomontesg can tell something.

Regarding the scene, I would strongly suggest programming them in homeassistant, and not having two "master" systems. In my opinion, you should configure your scene only in one system.

The initial goal of digitalstrom-mqtt was to be able to use any automation system as master and digitalstrom is just a slave (https://github.com/gaetancollaud/digitalstrom-mqtt#motivation).

But I understand why you would want to have them. Actually, scenes are exposed, see #12 But you cannot trigger them.

albertomontesg commented 2 years ago

I didn't forgot that also scenes were exported in MQTT from DigitalStrom. I believe adding those should be quite trivial as Scenes can also be configured from MQTT resources (as explained here).

Right now I am on vacation and I can not test any implementation on my home setup, but I believe it should be quite trivial to implement:

  1. A new block should be added here that iterates through all the scenes available in the SceneManager.
  2. Some function needs to be implemented (like this one) that will create the MQTT JSON config message (specified here)

I can try to give it a try, but without the ability to test the implementation.

albertomontesg commented 2 years ago

Giving it a deeper look at the implementation I realised about one thing: Home Assistant MQTT Scenes are meant to activate and scenes through MQTT, but currently digitalstrom-mqtt only exposes the Scenes events through MQTT, but you can not activate Scenes through MQTT (AFAIK). This makes the integration with Home Assistant not possible, as you need to specify a command topic for which you can send the command to DigitalStrom to activate a specific scene and I believe that is not possible right now.

As @gaetancollaud said, you could use Home Assistant as the manager for the scenes and DigitalStrom the worker that perform the changes on the devices that are already exposed.