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

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

Open
mcrummett opened this issue Nov 7, 2023 · 15 comments
Open

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

mcrummett opened this issue Nov 7, 2023 · 15 comments

Comments

@mcrummett
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Member

Hi,

Can you create a PR with your changes?

@mcrummett
Copy link
Contributor Author

mcrummett commented Nov 9, 2023 via email

@mariusmotea
Copy link
Member

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
Copy link
Contributor Author

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

@Jan1503
Copy link

Jan1503 commented Nov 16, 2023

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

@mcrummett
Copy link
Contributor Author

mcrummett commented Nov 16, 2023 via email

@sini180
Copy link

sini180 commented Dec 15, 2023

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
Copy link
Contributor Author

mcrummett commented Dec 15, 2023 via email

@sini180
Copy link

sini180 commented Dec 15, 2023

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
Copy link

Jan1503 commented Dec 15, 2023

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

Have a nice day!

@mcrummett
Copy link
Contributor Author

mcrummett commented Dec 15, 2023 via email

@u20p17
Copy link

u20p17 commented Jan 18, 2024

seems to be related to #961

@mariusmotea
Copy link
Member

New commit was made to fix this issue.

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

5 participants