Emulated_hue with switches works, sort of

I have set up the emulated_hue component to expose the domain switch to alexa. I ran into several problems that i’d like to discuss in a new topic since i don’t want to hijack the other emulated_hue thread of @Antasp3136 when my problem is increasingly different. It’s basically twofold:

  1. The first problem after getting the echo discovery to work, was that alexa always executed my switches but immediately switched back and giving a speech about “this value is outside the range of the device”. Doing a diff to older versions of emulated_hue.py i realized that there were some additions about brightness in the file and while searching for the alexa speech i ended up finding references to tasmota errors on github that had the same problem. I then got on my master coding gloves and tried applying that to the hue file (yeah, i really just winged it because i don’t speak python).
    In this commit i found i had to replace the line 456 in hue_api.py:
    data[STATE_BRIGHTNESS] = entity.attributes.get(ATTR_BRIGHTNESS, 0)
    data[STATE_BRIGHTNESS] = entity.attributes.get(ATTR_BRIGHTNESS, 254)

That made alexa execute the switching just fine, although i have seen that the json sent to alexa behaves strange. But so far so good i thought.

  1. Now the next (or possible resulting) error is a message in the logs about AttributeError: ‘NoneType’ object has no attribute ‘lower’. Full traceback:
    File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start resp = await task File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle resp = await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl return await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/real_ip.py", line 33, in real_ip_middleware return await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/view.py", line 112, in handle result = handler(request, **request.match_info) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/emulated_hue/hue_api.py", line 172, in get entity = hass.states.get(entity_id) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py", line 838, in get return self._states.get(entity_id.lower()) AttributeError: 'NoneType' object has no attribute 'lower'

Trying to hunt down the cause of this problem led me nowhere. I tried explicitly naming the entities to exclude possible corrupted entities, rebuilding the switches, renaming the switches, even removing the lower() method from core.py, but to no avail. I would raise an issue if i knew what I was asking for. All i have is i made a change that made it half-work and now i have another problem. Doesn’t sound really like a good description. Any ideas?

For lost souls wandering into this thread: the problem was a caching issue on the gen3 echo dot. A factory reset solved the problem of phantom entities referenced. See github.