Skip to content
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

Delay homebridge startup until deCONZ has discovered all lights #246

Closed
ebaauw opened this issue Jan 1, 2018 · 19 comments
Closed

Delay homebridge startup until deCONZ has discovered all lights #246

ebaauw opened this issue Jan 1, 2018 · 19 comments

Comments

@ebaauw
Copy link
Owner

ebaauw commented Jan 1, 2018

From #245 (comment):

Do you already know when you have solved the problem with the accessibility of the lamps at the start of homebridge? I have currently bypassed it with a service.timer that homebridge launches 5 minutes after deconz.

Yeah, this sucks. I start the homebridge service manually because of this. Luckily you can restart deCONZ while keeping homebridge/homebridge-hue running, so it's only an issue when you reboot the Raspberry.
This needs to be solved by deCONZ, see dresden-elektronik/deconz-rest-plugin#97, or in homebridge-hue by moving to the dynamic accessory model, see #4. No E.T.A. on either, I'm afraid.
I've been thinking about a workaround, holding up the homebridge startup (or simply exiting homebridge) until all lights are available. Unfortunately, deCONZ doesn't maintain /groups/0/lights, so either that needs to be maintained manually (need some testing to see whether that's reliable), or we'd need another homebridge-hue resourcelink (in addition to the whitelist and blacklist). I could provide a command in ph.sh to create/update that list automatically.

ebaauw added a commit to ebaauw/ph.sh that referenced this issue Jan 1, 2018
New command, `ph_lightlist` creates a resourcelink with all lights.
This is used by homebridge-hue to delay startup, until deCONZ has
discovered (and exposed through the REST API) all lights.  See
ebaauw/homebridge-hue#246.
@Krocko
Copy link

Krocko commented Jan 1, 2018

What about the sensors?

ebaauw added a commit that referenced this issue Jan 1, 2018
homebridge-hue now delays the startup of homebridge, until all
whitelisted resources are available, see issue #246.  A special
`lightlist` can be created through `ph.sh`, to list all resource that
have to be available, but aren’t necessarily exposed.

Also when deCONZ hasn’t initialised the RaspBee/ConBee, homebridge-hue
no longer exits homebridge, but delays startup until the `bridgeid` has
been initialised.
@ebaauw
Copy link
Owner Author

ebaauw commented Jan 1, 2018

What about the sensors?

Not an issue, as deCONZ restores their resources from its database and exposes these directly on startup. It's only the light resources that are missing, see dresden-elektronik/deconz-rest-plugin#97.

Anyway, homebridge-hue will wait for all whitelisted resources to be available.

@Krocko
Copy link

Krocko commented Jan 1, 2018

For me some Xiaomi Aqara door and temperature sensors appear after some minutes if i restart the gateway.

Can you show, how such a whitelist looks like? I would create it with a REST client.

@ebaauw
Copy link
Owner Author

ebaauw commented Jan 1, 2018

For me some Xiaomi Aqara door and temperature sensors appear after some minutes if i restart the gateway.

Appear where? In the deCONZ GUI or in the REST API. I find all my /sensors resources, including those for my Xiaomi devices, are available immediately after startup, typically with config.reachable set to false.

Can you show, how such a whitelist looks like? I would create it with a REST client.


$ ph_lightlist
pi2: /resourcelinks/1: 42 lights
$ ph_get /resourcelinks/1
{
  "classid": 1,
  "description": "lightlist",
  "links": [
    "/lights/101",
    "/lights/111",
    "/lights/201",
    "/lights/202",
    "/lights/211",
    "/lights/221",
    "/lights/222",
    "/lights/223",
    "/lights/224",
    "/lights/225",
    "/lights/226",
    "/lights/227",
    "/lights/228",
    "/lights/229",
    "/lights/230",
    "/lights/231",
    "/lights/232",
    "/lights/233",
    "/lights/234",
    "/lights/241",
    "/lights/242",
    "/lights/243",
    "/lights/244",
    "/lights/251",
    "/lights/261",
    "/lights/271",
    "/lights/272",
    "/lights/273",
    "/lights/301",
    "/lights/302",
    "/lights/311",
    "/lights/312",
    "/lights/313",
    "/lights/314",
    "/lights/315",
    "/lights/321",
    "/lights/322",
    "/lights/323",
    "/lights/324",
    "/lights/331",
    "/lights/332",
    "/lights/341"
  ],
  "name": "homebridge-hue",
  "owner": "**********1",
  "recycle": false,
  "type": "Link"
}

@ebaauw
Copy link
Owner Author

ebaauw commented Jan 1, 2018

In v0.5.55.

@Krocko
Copy link

Krocko commented Jan 2, 2018

Appear where? In the deCONZ GUI or in the REST API. I find all my /sensors resources, including those for my Xiaomi devices, are available immediately after startup, typically with config.reachable set to false.

You are right. It is only in the GUI. The REST API have all sensors on startup.

With v0.5.55 and the lightlist, the delayed start of homebridge works perfect.

@jaal2001
Copy link

jaal2001 commented Jan 7, 2018

I tried a few hours by reading all available information here, but I still dont understand how (and where) to add the output from ph_get. Do I add this to the config.json? (already tried but only getting an error during statup)
Or do I have to send this via REST client to deCONZ? (also tried, but no luck).

Can you give me a hint? Thanks!

@ebaauw
Copy link
Owner Author

ebaauw commented Jan 7, 2018

ph_lightlist creates the resourcelink on the gateway. The ph_get is just to verify that is has been created - no need to do anything with its output.

@Razeeer
Copy link

Razeeer commented Mar 5, 2018

Hello, can you perhaps explain to me again how to apply the lightlist exactly so that Homekit does not lose the lamps?

Even better would be in the Hue Wiki a guide step by step how to proceed?

I installed homebridge-hue in the last version.

Thank you.

@ebaauw
Copy link
Owner Author

ebaauw commented Mar 5, 2018

OK, step by step (ph is now included in homebridge-hue):

  1. Wait for deCONZ to have discovered all you lights;
  2. On the command line, issue: ph lightlist -v. It will respond with something like ph lightlist: /resourcelinks/1: 42 lights.

To update the resourcelink after you've added more lights, simply re-run ph lightlist.

@Razeeer
Copy link

Razeeer commented Mar 6, 2018

Thank you for your prompt reply. That's really not much and seems to be easy but i get this message?

Which user does he mean?

ph lightlist: error: 1 unauthorized user

@ebaauw
Copy link
Owner Author

ebaauw commented Mar 6, 2018

Like any client, ph needs to a valid username, an API key, to access the deCONZ REST API. You need to unlock the gateway from the web app, the Phoscon app, or homebridge-hue (the Linkbutton characteristic on the bridge service) and then issue ph createuser. This will create a username and store it in ~/.ph for future use.

@Razeeer
Copy link

Razeeer commented Mar 6, 2018

Ok, now it worked. Thank you.

A question, still sensors and switches are also stored with them that can not be lost or only lights?

I dont have lights in deconz only switches and sensors.

ph lightlist: /resourcelinks/1: 0 lights

@ebaauw
Copy link
Owner Author

ebaauw commented Mar 6, 2018

Please see above.

@Razeeer
Copy link

Razeeer commented Mar 6, 2018

Shit, I completely overlooked. Thank you.

@ckeech
Copy link

ckeech commented Sep 21, 2020

Thanks for this. I'm finding the same problems so I just ran ph lightlist -v. I noticed you mentioned it shouldn't affect sensors, how about the Sonos' exposed in the SonosZP plugin? I just had to reboot my pi and all the Lights moved to default room but so did the Sonos'. It seems the ph lightlist -v is only for lights?

@ebaauw
Copy link
Owner Author

ebaauw commented Sep 21, 2020

Sonos is a different issue, see ebaauw/homebridge-zp#139.

It seems the ph lightlist -v is only for lights?

Exposed by Homebridge Hue.

@marmitol
Copy link

Hello.
Thank you very much, I was able to solve the problem by following the instructions.

@khituras
Copy link

Just in case this might be of interest to someone. I forked the plugin and added a loop that tries to find lights on startup. If there are none, it tries again until lights have been found. This would obviously be an issue if you don't have any lights. But for me it seems to work fine until now. Finally lights stopped from disappearing from HomeKit after restarts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants