diyhue / diyHue

Main diyHue software repo
https://diyhue.org/
Other
1.52k stars 274 forks source link

Brightness value set to "null" causes DiyHue to fail to start #948

Open mcrummett opened 8 months ago

mcrummett commented 8 months ago

Issue does not already exist?

I have searched and found no existing issue

Select Environment

Install Script

Home Assistant related?

No

Description

Both with the HA addon and standard host install, the app will fail to restart with the below error

If i go into the lights.yaml and ensure that any bri values are set to 0 rather than "null" it starts fine. However i am unsure what is causing the null values rather than 0-255.

Errorlog:

Traceback (most recent call last):
  File "/opt/hue-emulator/configManager/configHandler.py", line 114, in load_config
    self.yaml_config["lights"][light] = Light(data)
  File "/opt/hue-emulator/HueObjects/__init__.py", line 291, in __init__
    "data": [self.getV2Api()],
  File "/opt/hue-emulator/HueObjects/__init__.py", line 532, in getV2Api
    "brightness": round(self.state["bri"] / 2.54, 2),
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'

Steps to reproduce

Unsure when/why brightness values for random lights will get set to null but doing so manually would allow the issue to be reproduced

Please enter your operating system details here

Ubuntu 22.04. However the HA addon has the same issue

What DiyHue version(branch) are you using?

master (latest)

mcrummett commented 8 months ago

Changed

if "bri" in self.state: result["dimming"] = { "brightness": round(self.state["bri"] / 2.54, 2), "min_dim_level": 0.10000000149011612 }

to


 if "bri" in self.state:
            bri_value = self.state["bri"]
            if bri_value is None or bri_value == "null":
                bri_value = 1
            result["dimming"] = {
                "brightness": round(float(bri_value) / 2.54, 2),
                "min_dim_level": 0.1  # Adjust this value as needed
            }


seems to be checking for null values and changing to 1 if not.  Sort of fixed it?
mcrummett commented 8 months ago

i also had to change

if "bri" in state: v2State["dimming"] = { "brightness": round(state["bri"] / 2.54, 2)} v2State["dimming_delta"] = {}

to

if "bri" in state: bri_value = state["bri"] if bri_value is None or bri_value == "null": bri_value = 1 v2State["dimming"] = { "brightness": round(float(bri_value) / 2.54, 2) } v2State["dimming_delta"] = {}

from my understanding this was due to me adding scenes to my configuration and it loading the light values differently.

mariusmotea commented 8 months ago

Hi,

Can you create a PR with your changes?

mcrummett commented 8 months ago

If I can work out how too, then yes haha

Mark Crummett


From: Motea Marius @.> Sent: Thursday, November 9, 2023 2:33:12 PM To: diyhue/diyHue @.> Cc: mcrummett @.>; Author @.> Subject: Re: [diyhue/diyHue] Brightness value set to "null" causes DiyHue to fail to start (Issue #948)

Hi,

Can you create a PR with your changes?

— Reply to this email directly, view it on GitHubhttps://github.com/diyhue/diyHue/issues/948#issuecomment-1803945001, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD35N6SMNMYLALILLBURNSLYDTSSRAVCNFSM6AAAAAA7BRHTLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBTHE2DKMBQGE. You are receiving this because you authored the thread.Message ID: @.***>

mariusmotea commented 8 months ago

Create a fork of this repo, commit your changes in your fork, then use the pull request button to create a pull request in the main repo. I think there is plenty youtube videos with these steps...

mcrummett commented 8 months ago

Top dollar. will do it over the weekend, cheers!

Jan1503 commented 7 months ago

Hey, I have this problem, too, using the official add-on in HA. @mcrummett Could you create the PR please?

mcrummett commented 7 months ago

Sorry yes. I’ll try and do it tonight. Been rather ill this last week so not had a chance

Mark Crummett


From: Jan Wrage @.> Sent: Thursday, November 16, 2023 12:30:47 PM To: diyhue/diyHue @.> Cc: mcrummett @.>; Mention @.> Subject: Re: [diyhue/diyHue] Brightness value set to "null" causes DiyHue to fail to start (Issue #948)

Hey, I have this problem, too, using the official add-on in HA. @mcrummetthttps://github.com/mcrummett Could you create the PR please?

— Reply to this email directly, view it on GitHubhttps://github.com/diyhue/diyHue/issues/948#issuecomment-1814350377, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD35N6V6LNI5ZFY532VSFS3YEYBPPAVCNFSM6AAAAAA7BRHTLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJUGM2TAMZXG4. You are receiving this because you were mentioned.Message ID: @.***>

sini180 commented 6 months ago

I did as per above and removed the bri: null from the lights.yaml and started fine. I forked but can't understand what has been updated by @mcrummett as one is commented out in main branch anyway and other code looks as per main. Workaround is to just edit the lights.yaml to not have bri: null (set to 0 for example).

mcrummett commented 6 months ago

The values will go back to null next time the lights are turned off. My changes make it so that if null is found it changes it to 0 and thus doesn’t error

Mark Crummett


From: sini180 @.> Sent: Friday, December 15, 2023 11:27:02 AM To: diyhue/diyHue @.> Cc: mcrummett @.>; Mention @.> Subject: Re: [diyhue/diyHue] Brightness value set to "null" causes DiyHue to fail to start (Issue #948)

I did as per above and removed the bri: null from the lights.yaml and started fine. I forked but can't understand what has been updated by @mcrummetthttps://github.com/mcrummett as one is commented out in main branch anyway and other code looks as per main. Workaround is to just edit the lights.yaml to not have bri: null (set to 0 for example).

— Reply to this email directly, view it on GitHubhttps://github.com/diyhue/diyHue/issues/948#issuecomment-1857722495, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD35N6TJIERSKRU75HWNZZTYJQXYNAVCNFSM6AAAAAA7BRHTLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJXG4ZDENBZGU. You are receiving this because you were mentioned.Message ID: @.***>

sini180 commented 6 months ago

I know, just couldn't figure out what you've done. Hopefully you have time to create the PR. If not I'll have a look when I get some time :)

All the best Mark @mcrummett

Jan1503 commented 6 months ago

👋 Yeah, still waiting for the PR but no pressure..

Have a nice day!

mcrummett commented 6 months ago

Oh. Did my original PR not work?

Mark Crummett


From: Jan Wrage @.> Sent: Friday, December 15, 2023 12:51:15 PM To: diyhue/diyHue @.> Cc: mcrummett @.>; Mention @.> Subject: Re: [diyhue/diyHue] Brightness value set to "null" causes DiyHue to fail to start (Issue #948)

👋 Yeah, still waiting for the PR but no pressure..

Have a nice day!

— Reply to this email directly, view it on GitHubhttps://github.com/diyhue/diyHue/issues/948#issuecomment-1857835928, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD35N6QW5EAFQ4JIUINQIMTYJRBUHAVCNFSM6AAAAAA7BRHTLOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJXHAZTKOJSHA. You are receiving this because you were mentioned.Message ID: @.***>

u20p17 commented 5 months ago

seems to be related to https://github.com/diyhue/diyHue/issues/961

mariusmotea commented 5 months ago

New commit was made to fix this issue.