Phype / purei9_unofficial

This project includes a client/library to connect to Electrolux and AEG cleaner robots.
https://pypi.org/project/purei9-unofficial
MIT License
27 stars 5 forks source link

Integration with home assistant #2

Closed drgreenbaum closed 3 years ago

drgreenbaum commented 3 years ago

Great work! Been waiting for this a long time. Their integration with IFTTT has been failing for a long time. Is it possible to integrate your code with home assistant or MQTT so that the robot can be used with the Vacuum template: https://www.home-assistant.io/integrations/vacuum.template/ ?

Phype commented 3 years ago

Well, it's possible, but writing a home assistant addon seems not that straightforward tbh. When i look at this code i only find layers upon layers of abstractions, but nowhere seems to be code which controls how the connection to the robot is made and how the protocol looks like.

Maybe home assistant allows you to create a simple plugin which just work by calling a command line program or something like that? Then you can just point it to the purei9-cli program and set some parameters.

Phype commented 3 years ago

Ah i see. So home assistant seems to be built mostly on third party libs (like this one). Maybe you can create an issue there and ask if they can build in integration based on my code?

MartinWilden commented 3 years ago

I am also looking for a Home Assistant Integration. The simplest integration seems to be the template (https://www.home-assistant.io/integrations/vacuum.template/)

_The template platform creates vacuums that combine integrations and provides the ability to run scripts or invoke services for each of the start, pause, stop, return_to_base, clean_spot, locate and set_fanspeed commands of a vacuum.

Alternatively would be nevertheless also over MQTT (https://www.home-assistant.io/integrations/vacuum.mqtt/) a good and lasting, although probably more complicated way

Phype commented 3 years ago

I think you could hack something together by creating a shell command service (https://www.home-assistant.io/integrations/shell_command/) and then invoking this service via the vacuum template. I don't know or have a Home Assistant Installation, so i cannot test. Still, i think the proper way of doing this would be to create a integration like the ones in here: https://github.com/home-assistant/core/tree/dev/homeassistant/components

For MQTT, you would need a proxy which understands MQTT and calls the script, since the robot does not.

drgreenbaum commented 3 years ago

Seems like a good place to start! Does the robot push out data or do you have to poll state changes every x seconds?

Phype commented 3 years ago

You have to poll. Even if the TCP connection is left open, its a query/response protocol, the robot won't send anything without a request.

Phype commented 3 years ago

Home assistant integration is available here: https://github.com/anhaehne/homeassistant_electrolux_purei9 based on code from this repository