# Works then doesn't

**URL:** <https://diyhue.discourse.group/t/works-then-doesnt/651>\
**Category:** Support\
**Created:** [November 6, 2023, 6:20pm UTC](https://diyhue.discourse.group/t/works-then-doesnt/651 "2023-11-06T18:20:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![markyc](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@markyc](https://diyhue.discourse.group/u/markyc)\
**Post date:** [November 6, 2023, 6:20pm UTC](https://diyhue.discourse.group/t/works-then-doesnt/651/1 "2023-11-06T18:20:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![markyc](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@markyc](https://diyhue.discourse.group/u/markyc)\
**Post date:** [November 7, 2023, 4:42pm UTC](https://diyhue.discourse.group/t/works-then-doesnt/651/2 "2023-11-07T16:42:57Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![markyc](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@markyc](https://diyhue.discourse.group/u/markyc)\
**Post date:** [November 7, 2023, 4:49pm UTC](https://diyhue.discourse.group/t/works-then-doesnt/651/3 "2023-11-07T16:49:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![markyc](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@markyc](https://diyhue.discourse.group/u/markyc)\
**Post date:** [November 8, 2023, 7:19pm UTC](https://diyhue.discourse.group/t/works-then-doesnt/651/4 "2023-11-08T19:19:18Z")

</div>

resolved by changing

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

```

to

```auto
        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

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

```

to

```auto
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 🙂
