Works then doesn't

Hi all

I was hoping someone may be able to help me fix my home assistant DiyHue addon.

I get all working, the bridge added to the Hue App, lights imported from HA and visible in Hue App, controllable etc. However then it’ll start showing as not available/disconnected then online in the hue app and stop working. If i then restart the add on it fails and says it failed to load the config file.

I’ve excluded all lights that i know of that may not work or be relevant but still no luck.

this is the error i seem to get when running the python. Which seems to suggest a brightness value coming back as null is causing an issue as it expects a float?

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’

Okay if i manually go into the lights.yaml and ensure all brightness values are not null, it starts perfectly. So the brightness needs to be 0 instead of null but not sure how to get that in

resolved by changing

        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
            }

and

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"] = {}

some of my bulbs report brightness as null when off i believe. the above changed let DiyHue factor that in and change a null value go 1 instead. That may need to be 0 but seems to work as 1 (looking through the values seemed to need to be 1-254.

just a security engineer who dabbles in Python so take my ideas with a pinch of salt but working for me :slight_smile: