itavero / homebridge-z2m

Expose your Zigbee devices to HomeKit with ease, by integrating 🐝 Zigbee2MQTT with 🏠 Homebridge.
https://z2m.dev
Apache License 2.0
312 stars 49 forks source link

[Feature] Adaptive Lighting #30

Closed itavero closed 1 year ago

itavero commented 3 years ago

After #18 is finished, support for Adaptive Lighting can probably be added for lights that exposes a color temperature property.

As a reference, the implementation for homebridge-hue can be looked into (see ebaauw/homebridge-hue#766).

itavero commented 3 years ago

Initially I thought of using the transition property to make a smooth transition and reduce the needed Zigbee traffic. After asking about the maximum value of this property, it appears that it is very device dependent (some support many minutes, others support < 30 seconds).

I guess I'll have to see how often the values change and if the transition really adds anything. Otherwise, I can always add an option to have the end user configure the transition time (and have a default of 0).

thomaspleasance commented 3 years ago

I'm looking at adding this via a pr what is the best way to call versiongreaterorequal ? https://developers.homebridge.io/homebridge/interfaces/api.html#versiongreaterorequal

itavero commented 3 years ago

@thomaspleasance That would be awesome. I reckon you'd need this in the Light service handler, right? I think we should add it to the BasicAccessory interface in that case.

itavero commented 3 years ago

@thomaspleasance I wasn't aware of this function yet, but I think it's introduced in the version that's currently in beta. Any particular reason you need it?

thomaspleasance commented 3 years ago

@itavero thats correct that’s why I want to check if it’s available to use. So I don’t break currently functionality

itavero commented 3 years ago

@thomaspleasance Not sure if we are talking about the same thing. What I meant to say was that versionGreaterOrEqual will be in the next release of Homebridge (I don't believe it's in the current stable version already).

There are already a couple of plugins that have added support for Adaptive Lighting, so I don't believe we'll need anything specific from Homebridge that's currently in beta. Of course, please correct me if I'm wrong.

thomaspleasance commented 3 years ago

Yes you are correct versionGreaterOrEqual is only available in 1.3.0. I was planning on using https://developers.homebridge.io/HAP-NodeJS/classes/adaptivelightingcontroller.html what is now in 1.3 to do the Adaptive Lighting

itavero commented 3 years ago

I wasn't aware that this is also added in 1.3.0. That would make life a lot easier.

I'll see if I can make a function for this in the BasicAccessory later today, that simply returns false if the function is versionGreaterOrEqual is not available on the API. This is also pretty much what is done in the BaseAccessory of homebridge-tuya to check if adaptive lighting is supported by the installed version of Homebridge.

PS: Thanks for making me aware of this. Just updated to the beta in my home setup and now I can also use adaptive lighting with some other plugin I'm using. 💡

itavero commented 3 years ago

@thomaspleasance By the way, since this controller you've mentioned should make integration a piece of cake, I can probably also do it myself in the coming days, if you don't mind.

itavero commented 3 years ago

Just wrote the code for the Homebridge server version requirement check during my lunch break and put it in a PR already so the GitHub Actions can do some verification.

My lunch break is over now, so no time to also integrate the Adaptive Lighting Controller, but I think I'll find some time later today or tomorrow.

itavero commented 3 years ago

Basic integration is done, I guess, but there's still several things I want/need to verify (see PR for specifics).

thomaspleasance commented 3 years ago

Will give it a test later and let you know if I find anything

itavero commented 3 years ago

@thomaspleasance As mentioned in the PR, I still have some things to figure out to make it work better. I think in the end I should probably implement it using the manual mode, instead of the automatic mode, to make the transitions work better.

itavero commented 3 years ago

Added some tests as well. Although I still see room for improvement, I think I'll just release the integration I have right now and have it run at home for a while. I can always improve it later on if needed.

jwilling commented 3 years ago

This is awesome to see!

One thing I dislike about Hue's native adaptive lighting is that it's leans significantly on the colder side than I'd prefer. Unfortunately there's no way to modify this.

I'd definitely consider bringing my Hue bulbs into my Z2M ecosystem if it meant I could customize the upper and lower bounds of color temperatures. Is that something that the Homebridge adaptive lighting controller could allow? From a quick glance at the API it seems doubtful.

[moved comment from PR]

itavero commented 3 years ago

@jwilling I think the homebridge-hue plugin has an adjustment factor for this. If I remember correctly, it actually uses a given percentage of the actual brightness to determine the color temperature. A lower brightness means a warmer color, so that would allow for some tuning/calibration.

I think I'll try to look into this, because for this to work, I definitely cannot use the automatic mode of the Adaptive Lighting controller built into Homebridge (which was already feeling a bit "less than ideal" for this plugin).

itavero commented 3 years ago

No updates this week unfortunately. Been a bit busy at work, as well as doing some research for another project of mine.

itavero commented 3 years ago

Been a bit short on time. I still intend to continue with this implementation, but to be honest, I don't know when I'll be able to do so.

The "automatic" version is sort of ready to go, I believe, but as mentioned before, it's not the ideal implementation. However, due to my "lack" of time, I'm thinking of releasing it anyway. At least it will help us gather feedback on how well it works "in real life". Based on that it might be possible to have a better understanding on what the "requirements" are for the manual implementation (what kind of configuration options would we need, what kind of "problems" do we need to try and prevent, etc.)

itavero commented 3 years ago

Spent some time today preparing to release this. Added an option to set a minimum delta in color temperature before an MQTT message is published, as well as an optional transition value. Both still based on the Automatic Mode of the Adaptive Lighting Controller.

Unfortunately I did notice that it's difficult to disable the adaptive lighting automatically when a different value is sent to Zigbee2MQTT by another MQTT client (or i.e. by a remote connected directly to a lightbulb). At this point in time I do not yet have a good solution for this.

RaffoNin commented 3 years ago

Hi is there a way to try out the adaptive lighting feature? I do not use another MQTT broker to send commands nor do I use a remote. Would love to provide feedback.

itavero commented 3 years ago

is there a way to try out the adaptive lighting feature?

I haven't worked on it recently, but the code I did make for this feature can be found in #60. That branch is lagging a bit behind on the master branch, but I guess you could check it out and give it a spin.

nikbyte commented 3 years ago

Any chance to include it to main branch?

itavero commented 3 years ago

@nikbyte Unfortunately last time I worked on it, it was not ready to go into a release yet. master has changed in the mean time, so I will have to rebase the changes and still figure out the "loose ends". I don't expect that to happen in the near future (unfortunately I'm also struggling with some health issues).

montanaishome commented 2 years ago

Any chance of including this feature in a future release?

philippebezoteaux commented 2 years ago

Would love to see this integrated and be able to get rid of Hue’s bridge for starter ! Probably the main feature Z2M is missing…

lcsjandrey commented 2 years ago

please add support for adaptive lightning! <3

itavero commented 2 years ago

I hoped to have time for this last month, but I didn't and I'm not sure when I will have time to do this.

I'm very busy at my work, doing new and exciting things. Not to mention the things going on in my personal life (all positive, luckily, but time consuming).

My earlier work on this, is pushed to the repository as well. If someone else has time to rebase it on master and put the changes behind a "experimental feature" flag (as is done with support for groups), I'd be happy to review it and give it a try.

macfr76 commented 2 years ago

That would be really great to get this feature. Unfortunately, I can't help for the code, but would be pleased to test and debug.

chigy110 commented 2 years ago

I'd love to see this feature, as it is the Main-Reason, why I'm not migrating my hue-bulbs to z2m.

zegl commented 2 years ago

Hey. I just wanted to say that I've rebased #60 on top of the latest master (v1.9.0), and have published it to my fork and npm.

I'm currently testing with three different Hue lights to make sure that everything works as expected over a longer period of time (with Homebridge v1.5.0).

After two hours of testing, it's looking promising! (see screenshot)

Screenshot 2022-07-25 at 15 20 50

I'll send an updated PR once I'm sure that the adaptive lightning works perfectly, and have made the adaptive lightning feature opt-in as suggested by @itavero above.

lcsjandrey commented 2 years ago

Dude thank you thank you so much! Very much appreciated. Happy to ‘buy you a coffee’ On Mon, Jul 25, 2022 at 10:30 Gustav Westling @.***> wrote:

Hey. I just wanted to say that I've rebased #60 https://github.com/itavero/homebridge-z2m/pull/60 on top of the latest master (v1.9.0), and have published it to https://github.com/zegl/homebridge-z2m/tree/adaptive-lighting and npm @.***/homebridge-z2m>.

I'm currently testing with three different Hue lights to make sure that everything works as expected over a longer period of time (with Homebridge v1.5.0).

After two hours of testing, it's looking promising! (see screenshot)

[image: Screenshot 2022-07-25 at 15 20 50] https://user-images.githubusercontent.com/47952/180787177-97a9461b-c311-4df6-806b-a7eb6a20b10b.png

I'll send an updated PR once I'm sure that the adaptive lightning works perfectly, and have made the adaptive lightning feature opt-in as suggested by @itavero https://github.com/itavero above.

— Reply to this email directly, view it on GitHub https://github.com/itavero/homebridge-z2m/issues/30#issuecomment-1194052353, or unsubscribe https://github.com/notifications/unsubscribe-auth/APTGKAVXA3NYUMY56Q3FV2LVV2JINANCNFSM4U44LYCQ . You are receiving this because you commented.Message ID: @.***>

robsussman commented 2 years ago

I'm interested in using adaptive lighting with homebridge-z2m and just came across this feature request which looks just like what I'm looking for! Any news on a PR to bring this over? Or, maybe I should just try out @zegl's fork? Thanks for any update...

itavero commented 2 years ago

There's still some open points on the PR if I remember correctly. If I would have time, I might look into resolving them myself, but I don't have that (yet).

My wife and I are about the become parents in the very, very near future, so I'm not sure yet how that will affect my spare time. 😅

robsussman commented 2 years ago

Thanks for the update. Exciting to be entering parenthood, congrats! Yes, I don't think spare time will be a thing for quite some time. :)

dotWee commented 1 year ago

I'm really looking forward to this feature too! I have a lot of lights from different vendors in my network - if there's something we can test, make sure to give us an update!

itavero commented 1 year ago

I think I'll be able to make a prerelease in the coming days that will include #488. You will have to enable adaptive lighting manually by setting an option in the light converter config, for example:

{
  "platform":"zigbee2mqtt",
  "defaults":{
    "converters":{
      "light":{
        "adaptive_lighting":true
      }
    }
  },
  "experimental":[
    "COLOR_MODE"
  ]
}

Things that still need more testing:

In general, it seems to work, but I'd love to get feedback on how well it works (as mentioned before).

Be aware that it is NOT released yet. Just wanted to give you guys a heads up 😉

itavero commented 1 year ago

Just published v1.11.0-beta.0, which can be installed using npm i homebridge-z2m@next (or via the "Install Alternate Version" option in the Homebridge Config UI X web interface).

If you gave it a try, please let me know about your experiences and if there's any improvements you'd like to see.

itavero commented 1 year ago

I've opened up a new discussion to gather feedback on this feature.

Please add your feedback to #590.