klali / ha-plejd

Plejd component for Home Assistant
Apache License 2.0
69 stars 16 forks source link

Does not work on hass.io #1

Closed pezmannen closed 5 years ago

pezmannen commented 5 years ago

If possible, it would be awesome with a hass.io port on this.

klali commented 5 years ago

One thing to investigate here is if bluepy would work better on hass.io, I had initial issues with getting notifications to work on bluepy and went with pygatt instead. There seems to be a couple of components using bluepy and some of them clain to work on hass.io.

Edit: and with that said it wasn't that tricky to get notifications working with bluepy. Maybe it would be good to move over to bluepy, I might make a test on a branch with that if I find time and interest.

klali commented 5 years ago

I just pushed some early bluepy code on a branch: https://github.com/klali/ha-plejd/tree/bluepy

This might work better with hass.io, at the least it seems to be a more popular ble library in home assistant. Though it does seem to come with it's own bugs and not being properly maintained.

pezmannen commented 5 years ago

I tried it now but cant get anything to work. Am I missing something? Should I add something more to the folder? image

Also, in my configuration.yaml i put this as is

light:

I do see this error: image

klali commented 5 years ago

Tricky to debug without running it, guess I might have to get hass.io running to be able to get the component running.

Make sure you have bluepy installed and have given it's helper the permissions to run the btle scanning.

pezmannen commented 5 years ago

Can I really install bluepy separatly? Doesnt that have to be included in the component?

pezmannen commented 5 years ago

Much appreciated is you get this up and running on hass.io. Most people are running this setup I think

atrampare commented 5 years ago

I agree would be great to have it working with hass.io witout to much hassle.

Thanks for the work your putting in.

klali commented 5 years ago

As stated in #4 I had a typo in the example, the config has to be for "devices" not "device".

For better compatibility with hass.io the integration should probably follow https://developers.home-assistant.io/docs/en/creating_integration_manifest.html

If doing the setcap part is to much and additional config is better I guess it's possible to optionally allow adding the adresses of connectable plejd devices to the config and skip the scanning step.

BertilJ commented 5 years ago

I got this working on Hass.io (after changing device to devices), seems to be some issues with Bluepy still, I've got other BT issues, but now I got all my Plejdd lights in HA and they are updated directly when I change them in Plejd app, so all good here.

pezmannen commented 5 years ago

I got this working on Hass.io (after changing device to devices), seems to be some issues with Bluepy still, I've got other BT issues, but now I got all my Plejdd lights in HA and they are updated directly when I change them in Plejd app, so all good here.

Did you do anything besides copying the files (and adding config in yaml)? Did you install anything else manually?

BertilJ commented 5 years ago

I tried to install bluepy once extra, but that installation ended with an error so I can't say if that made a difference or not.

I did also create a manifest.json for this component, but I'm not sure that did anything either. I can do a PR for the manifest.json later if needed.

BertilJ commented 5 years ago

Another update,

I've now looked through all my lights (+30) and it seems that I also get the not used outputs from Plejd (got a few DIM-02 that is currently only using one output) and I also have a few DIM-01 that are duplicates (got two numbers for each device) and those turn on and off but doesn't update state in HA.

I will take a look at getting the outputAddress instead of input that I'm currently using. Hopefully that fixes the update part.

But I'm still a little puzzled by the duplicates.

pezmannen commented 5 years ago

Your manifest file would be great!

atrampare commented 5 years ago

Your manifest file would be great!

Same here!

klali commented 5 years ago

A manifest might look like:

{
  "domain": "plejd",
  "name": "Plejd",
  "documentation": "https://github.com/klali/ha-plejd",
  "requirements": [ "bluepy" ],
  "dependencies": [],
  "codeowners": [ "@klali" ]
} 

with bluepy replaced with pygatt depending on branch.

Though this wont install correctly since the imports in light.py is in top level rather than function level. If the requirements are already installed correctly it will work though (and should without the manifest as well).

pezmannen commented 5 years ago

A manifest might look like:

{
  "domain": "plejd",
  "name": "Plejd",
  "documentation": "https://github.com/klali/ha-plejd",
  "requirements": [ "bluepy" ],
  "dependencies": [],
  "codeowners": [ "@klali" ]
} 

with bluepy replaced with pygatt depending on branch.

Though this wont install correctly since the imports in light.py is in top level rather than function level. If the requirements are already installed correctly it will work though (and should without the manifest as well).

Could you perhaps guide me on how to install the prereqs on hass.io?

pezmannen commented 5 years ago

Finally got it working!

To install bluepy i added this repository to the add-on store: https://github.com/home-assistant/hassio-addons-development

I then installed the "Custom deps deployment" add-on with the following config { "pypi": [ "https://wheels.home-assistant.io/alpine-3.10/armhf/bluepy-1.3.0-cp37-none-any.whl" ], "apk": [] }

And my manifest.json looks like this: { "domain": "plejd", "name": "Plejd", "documentation": "https://github.com/klali/ha-plejd", "dependencies": [], "codeowners": ["@klali"], "requirements": ["bluepy"] }

BertilJ commented 5 years ago

Curious if you got any error messages installing bluepy? I did it the old fashion way with "pip3 install bluepy" and the installation ended with an error.

pezmannen commented 5 years ago

No errors as far as I can recall

atrampare commented 5 years ago

I get this error when trying to set it up.

2019-07-28 13:43:07 ERROR (MainThread) [homeassistant.setup] Setup failed for devices: Integration not found. 2019-07-28 13:43:07 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for plejd which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

This is my configuration.yaml

light:

device_tracker:

Is this bluetooth device_tracker part neccesary?

When i run the bluepy code in Custom deps deployment i get this in the log.

[Info] Remove old deps [Info] Install pypi modules into deps The scripts blescan, sensortag and thingy52 are installed in '/config/deps/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. You are using pip version 19.0.2, however version 19.2.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. [Info] done

My foldersetup is for the plejd files is

/config/custom_components/plejd

Im running a pi 3B

pezmannen commented 5 years ago

Got the same messages as you. Did you add the manifest file?

atrampare commented 5 years ago

Yes i added the manifest in the same folder as light.py and init.py

BertilJ commented 5 years ago

I've been having issues on and off with this, first I got it working, then I did some changes and it didn't work any more.

Today I decided to set up a pi3 just with a clean Hass.io to see if I got it working and it works "out of the box". Add the three files (init, light and manifest) in custom components and add the config to config.yaml. Restart and it works.

Did the same on my nuc, installed a fresh installation and the files and config and it works. So the steps to add some extra isn't needed, probably due to the manifest.json or if bluepy actually is installed in Hass.io.

It doesn't work perfect for me, having a lot of issues to get the correct states back to HA, but all lights turn on and off and dims as they should.

I'm guessing that with older installations that have gone through several upgrades there may be some leftovers or other things that prevent this from working properly. So I would say that this issue should be closed. It does work on a vanilla installation on Hass.io both on pi3 and nuc.

atrampare commented 5 years ago

I also got it up and running now:-)= I did a clean installation of Hass.io. But I also had to do the step with "custom dep deployment" as described previously befor i got it to work.

klali commented 5 years ago

I've merged the bluepy branch, that comes with a manifest and the correct way of including dependencies and in a virtualenv installation the pulls in dependencies correctly.

When running on hass.io, did you have to do the setcap tricks to get it the correct permissions?

keylogicjohan commented 5 years ago

Got it running in hassio on a Thnikerboard S, I didn´t use the setcap tricks

BertilJ commented 5 years ago

No, no setcap on NUC either.