fredck / lightener

Magically control the state and brightness of lights in Home Assistant.
MIT License
99 stars 2 forks source link

Ghost in the lights #120

Closed fcassata closed 6 months ago

fcassata commented 7 months ago

I have 16 WiZ bulbs set up in one lightener device. All of which have 4 mapping lines, allowing me to gradually turn them on one by one, and then gradually increase brightness slowly.

When it works it's great, but after setting this up, the lights change brightness on their own every few minutes, always down, until they eventually turn off. The mapping config also slowly drifts "off", so that 100% on the lightener device seems to only go to about 30% on the config.

The automation that connects the wireless rotary dimmer to the light is not being triggered when the dimming happens, and there is nothing in the logs. I've turned on debug logging for the integration, but nothing their either.

Any ideas?

fcassata commented 7 months ago

User reports same issue in a reddit thread, so probably not particular to my setup.

fredck commented 7 months ago

I think I have faced something similar myself. It was tricky to debug the problem though and I figured a workaround that worked for me.

In my case, it felt like the Lightner configuration got messed up during HA (re)load. The following automation stabilized everything:

alias: Reload Lightener configurations on Home Assistant start
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - service: homeassistant.reload_config_entry
    data: {}
    target:
      entity_id:
        - light.living_room
        - light.dining_room
        - light.kitchen
        - light.club
        - light.hall
        - light.stairs
        - light.office
        - light.eduardo
        - light.ewa
        - light.riki
        - light.kids_bathroom
        - light.master_bedroom
        - light.master_bathroom
        - light.closet
        - light.cinema
mode: single

If I remember well, I believe I was seeing this problem in rooms with many lights. Maybe you're seeing the same with your 16 bulbs.

I hope someone else can confirm tha this automation helps. It could give hints on what's the cause of this issue bucause, in any case, we need a reliable way to reproduce the problem before we even try to fix it.

fcassata commented 7 months ago

Thanks, I'll see if this makes a difference in my case.

fcassata commented 7 months ago

No change with the proposed workaround, here is my 16 bulb config in case it helps...

  {
    "entry_id": "7579a8ab4410a2532461a2cd5ad2a1fb",
    "version": 2,
    "minor_version": 1,
    "domain": "lightener",
    "title": "Svefnherbergi_Loftljós",
    "data": {
      "friendly_name": "Svefnherbergi_Loftljós",
      "entities": {
        "light.wiz_dandelion_1": {
          "brightness": {
            "1": "1",
            "60": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_2": {
          "brightness": {
            "1": "0",
            "5": "0",
            "60": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_3": {
          "brightness": {
            "1": "0",
            "10": "0",
            "60": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_4": {
          "brightness": {
            "1": "0",
            "15": "0",
            "65": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_5": {
          "brightness": {
            "1": "0",
            "20": "0",
            "65": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_6": {
          "brightness": {
            "1": "0",
            "22": "0",
            "65": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_7": {
          "brightness": {
            "1": "0",
            "25": "0",
            "70": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_8": {
          "brightness": {
            "1": "0",
            "28": "0",
            "70": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_9": {
          "brightness": {
            "1": "0",
            "30": "0",
            "70": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_10": {
          "brightness": {
            "1": "0",
            "35": "0",
            "70": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_11": {
          "brightness": {
            "1": "0",
            "40": "0",
            "70": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_12": {
          "brightness": {
            "1": "0",
            "42": "0",
            "70": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_13": {
          "brightness": {
            "1": "0",
            "45": "0",
            "75": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_14": {
          "brightness": {
            "1": "0",
            "50": "0",
            "75": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_15": {
          "brightness": {
            "1": "0",
            "52": "0",
            "75": "1",
            "100": "50"
          }
        },
        "light.wiz_dandelion_16": {
          "brightness": {
            "1": "0",
            "55": "0",
            "75": "1",
            "100": "50"
          }
        }
      }
    },
fcassata commented 7 months ago

Having given it some time, I believe the automation workaround is making it somewhat more stable. It is definitely usable now with the occasional quirk. Thank you @fredck

fredck commented 7 months ago

If that's the case, you may try using the "Reload" option of the specific Lightener configuration in your system at https://my.home-assistant.io/redirect/integration/?domain=lightener when this situation happens.

If this really helps, it can give us some hints that could help figure this thing out. Thanks!

fredck commented 7 months ago

@fcassata Are you able to give a try to Lightener v2.3.0-beta.3 and see if there is any improvement. This is a pre-release so HACS doesn't install it by default but it gives you the option to install it ("redownload").

This release has lots of small improvements and I have hope that they may help. Also, it comes now with a lot of debug logging. If your problem persists, please enable debug logging in your ha configuration:

logger:
  default: info
  logs:
    custom_components.lightener: debug

Then, play with the lights and see what your logs says (check the log file directly, not the log page). You may find something helpful there. You can even attach some logs here.

As you can imagine it is very difficult to reproduce your specific use case. It may be related to the lights themselves. I really hope this release can help us figuring this out.

Thanks!

fcassata commented 7 months ago

Thanks @fredck, installed and will monitor. Will also disable the workaround-automation that was proposed earlier so it's not getting in the way while I test this release out.

fredck commented 7 months ago

@fcassata, just to keep you posted, we're already at Beta 5. Some logic changed so it's worth giving a try with them as well. Thanks!

fcassata commented 7 months ago

Thanks @fredck, will update. Btw, seeing the same issue as before with Beta 3 that I'm currently on. Lights dimming on their own, and in rare cases it seems the brightness is reported back incorrectly since the lovelace slider creeps upward on its own without a brightness change.

fredck commented 7 months ago

@fcassata, just to clarify, I didn't make any fixes specific to your use case. What we have in the betas are overall improvements in the internals of Lightener, with the hope that they may have a positive impact on your use case.

Also, there is a good chance that the issue has little to do with Lightener. What it does is, in theory, very simple: it sends individual calls to the "turn_on" service for each of the controlled lights, with the calculated brightness level configured for each of them, and that's it. Then it's the job of HA, the WiZ integration, and the bulbs themselves to do what they have to do.

You're talking about 16 wireless bulbs being controlled at once. By nature, all this happens in an asynchronous way where some bulbs may respond earlier than others. All those actions also enter a queue which, depending on the delay of the bulbs in answering, could cause the ghost behavior.

To that, add a rotary dimmer, which may be sending many changes to the brightness level in a very short amount of time. This means you multiply 16 "turn_on" calls for each change received, which may be piling up and overloading the system.

In a few words, it may be that your setup and your goals are too much for Lightener, the WiZ Integration, Home Assistant, and the WiZ bulbs to handle, and you'll have to settle with what is possible.

But that's not a definitive answer, for sure. We can only accept that after further investigation. That's the reason the betas included extensive debug logging. So, please enable the debug logging for the integration as I described before, and let's see if the logs can tell us anything that could help us form a final opinion on this matter.

I really hope we'll find that there is an issue with Lightener, so we'll be able to get it fixed. But I've started to doubt it has anything to do with that. Please prove me wrong.

Thanks!

fcassata commented 7 months ago

Haha I'll try proving you wrong @fredck. I do appreciate your time on this hard to reproduce vaguely described issue though!

The gradual dimming I've described happens long after any change is made to brightness (5 minutes at the earliest), and usually after "brightness up" is sent either through lovelace slider or a wireless dimmer knob/remote. I would agree strongly with a possible queue congestion if it was the same command as was last sent manually.

I've also had these WiZ bulbs set up "normally" for a long time before, controlling them all at once through a group, but no unexpected behaviour.

I'll do an experiment now and create a new lightener device with only 4 of the bulbs and see if there's a difference.

One noob question, I've enabled the debug logging, where is the log located?

fredck commented 7 months ago

The thing is, if we look at the Lightener source code, it calls "turn_on" for the bulbs just inside it's own "turn_on" function and immediatelly. Therefore the only way to execute it is by "actively" changing a Lightener light, either by user action or automation. It doesn't do anything that could again change the bulb state in a random moment in the future.

One noob question, I've enabled the debug logging, where is the log located?

You'll find the home-assistant.log file inside the config directory of ha.

I like to open it using the "Studio Code Server" official add-on that you can easily install in ha. This allows me to see the whole contents of the file and it shows me updates (almost) instantly.

fredck commented 6 months ago

There is no evidence that this issue is caused by Lightener. In fact, the source code doesn't give any indication that Lightener is capable of randomly changing the state of its controlled lights without receiving direct turn_on requests, which are handled immediately.

There's a good chance that this issue is related to the limitations of the installation and the smart home technology, especially regarding wireless devices. It's very likely that the wireless network is being flooded with light change requests that are being asynchronously handled in a non-linear way. That's, for sure, a difficult situation to fix or optimize.

I'm closing this issue for now, but I'll be happy to revisit it if it becomes clear that Lightener is the cause of this issue. Actually, I would be relieved if that were the case, as it would at least give us a chance to fix it.

@fcassata, please stay in touch if you have more news. Thanks!