stefanvictora / hue-scheduler

☀ Adjust your Philips Hue and Home Assistant lights to your natural rhythm. With advanced schedules and transitions based on solar times.
Apache License 2.0
19 stars 0 forks source link

Better power-on / power-off detection with dumb wall switches #14

Closed cswrd closed 1 month ago

cswrd commented 3 months ago

There's one room where I want to achieve the following (given dumb wall switches):

In stated in other words: when I power on the light immediately apply the correct light settings. Most importantly, be never brighter than this. It's the bedroom (side note: when I bought Philips hue devices, I thought this is the bare minimum it can achieve, haha).

Compared to other lights, the only thing I changed was to set the initial state of the bulb to 1% in the native philips hue app. Basically, this works as intended. But as you might have already guessed, turning on the light and turning it off an on too fast will break thinks. It takes a couple of minutes until it works again as intended.

Is there anything I could do or that'd be possible in the long run with hue scheduler? Or do you see it's limited by the Hue API? Even thogh a power-off might still be detected slow (I remember you said something about it), does the new events based Hue API not simply forward power-on events liike almost on behalf of the light itself? I mean just passthrough a power-on hello message from the light to the API client? That'd sound straightforward for me.

stefanvictora commented 2 months ago

Thank you for opening the issue. Handling dumb wall switches can indeed be really frustrating. Unfortunately, I believe we have already reached the limits of what the Philips Hue bridge and lights support.

Hue Scheduler already uses the zigbee_connectivity events published by the bridge to detect lights being physically turned on as quickly as possible. Those events look, for example, like this:

[
  {
    "creationtime": "2023-07-22T15:12:39Z",
    "data": [
      {
        "id": "60b2bafa-53f4-4062-9f58-253be813b349",
        "id_v1": "/lights/39",
        "owner": {
          "rid": "f36455ed-7b92-4e5a-97ba-73d804ab03da",
          "rtype": "device"
        },
        "status": "connected",
        "type": "zigbee_connectivity"
      }
    ],
    "id": "6f772cec-7f86-4b99-8629-7f9a285129a5",
    "type": "update"
  }
]

The issue with fast turn-offs and turn-ons is that the bridge doesn't immediately detect when lights become disconnected or unavailable. This detection can take up to two minutes. So, when the lights signal to the bridge that they are back on after being quickly turned off and on, the bridge still assumes they are on in its internal state. As a result, the bridge doesn't send out an update event because it doesn't register any change. Unfortunately, there is no way to tell the bridge to directly forward events from the lights while bypassing its internal state.

The only "solution" I could think of would be to continuously update such lights ensuring they receive and update even if they reset their state after being quickly turned off and on. However, this approach would degrade the overall performance of the underlying Zigbee network, so I wouldn't want to implement this as a default behaviour.

Moving away from using dumb wall switches might not be the solution you were hoping for, but it could resolve your issue when combined with the upcoming v0.12.0 release. This release will include a new scene-sync feature that allows you to turn on your lights with the correct light state directly using smart light switches. It resolves the current issue where lights initially turn on with their previous state and are only updated afterwards by Hue Scheduler to match the current desired state. Unfortunately, this functionality cannot be implemented with dumb wall switches.

Let me know if you have any further questions on this topic or the upcoming release.

cswrd commented 1 month ago

Hey, thanks for your answers. Given that, I fully agree with the fact the limits are reached here.

Yes, installing intelligent switches in a rented apartment is not that easy. Maybe I'll give it a try for that room with v0.12.0.

stefanvictora commented 1 month ago

I agree, to fully replace dumb wall switches is not that easy. In my home I just settled with some additional smart switches, while in most cases never touching the dumb ones.

I managed to now release v0.12.0 which contains the new optional scene sync feature, which you can enable via --enable-scene-sync or by setting the ENABLE_SCENE_SYNC=true environment variable. With this feature enabled, Hue Scheduler will automatically create synced scenes for all your zones and rooms affected by your schedules.

If you have any questions or issues about the new sync feature, feel free to ask or open a new issue!