Turn on light directly without flashing on/off

As is too common, debug logging is terribly difficult. Debug logging from homeassistant.components.hue is basically useless. Even enabling debug logging on EVERYTHING, doesn’t seem to show me any requests sent to the Hue bridge.

Here’s a sequence of first calling “turn_on” (which toggles three times; off -> on -> off -> on), followed by “turn_off” a few seconds later (which toggles once; on -> off).

2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752943992] Received {'type': 'call_service', 'domain': 'light', 'service': 'turn_on', 'service_data': {'entity_id': 'light.on_off_light_1'}, 'id': 39}
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=light, service=turn_on, service_data=entity_id=light.on_off_light_1>
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.components.hue.light] Finished fetching light data in 0.030 seconds
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:21.196857+09:00>, new_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>>
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1730885976] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:21.196857+09:00>, new_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>>}
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752943992] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:21.196857+09:00>, new_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>>}
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752111616] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:21.196857+09:00>, new_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>>}
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1753774496] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:21.196857+09:00>, new_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>>}
2021-02-16 13:28:24 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752943992] Sending {'id': 39, 'type': 'result', 'success': True, 'result': {'context': Context(user_id='<UUID_1>', parent_id=None, id='<UUID_2>')}}
2021-02-16 13:28:26 DEBUG (MainThread) [homeassistant.components.hue.sensor_base] Finished fetching sensor data in 0.021 seconds
2021-02-16 13:28:28 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752943992] Received {'type': 'call_service', 'domain': 'light', 'service': 'turn_off', 'service_data': {'entity_id': 'light.on_off_light_1'}, 'id': 40}
2021-02-16 13:28:28 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=light, service=turn_off, service_data=entity_id=light.on_off_light_1>
2021-02-16 13:28:28 DEBUG (MainThread) [homeassistant.components.hue.light] Finished fetching light data in 0.022 seconds
2021-02-16 13:28:28 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>, new_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:28.980475+09:00>>
2021-02-16 13:28:28 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1730885976] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>, new_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:28.980475+09:00>>}
2021-02-16 13:28:28 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752943992] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>, new_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:28.980475+09:00>>}
2021-02-16 13:28:28 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752111616] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>, new_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:28.980475+09:00>>}
2021-02-16 13:28:29 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1753774496] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=light.on_off_light_1, old_state=<state light.on_off_light_1=on; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:24.889646+09:00>, new_state=<state light.on_off_light_1=off; min_mireds=153, max_mireds=500, effect_list=['colorloop', 'random'], friendly_name=OnOffPlug, supported_features=0 @ 2021-02-16T13:28:28.980475+09:00>>}
2021-02-16 13:28:29 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.1752943992] Sending {'id': 40, 'type': 'result', 'success': True, 'result': {'context': Context(user_id='<UUID_1>', parent_id=None, id='<UUID_3>')}}

There seem to be no additional logging available from the Hue or Light integrations, nor the underlying aiohue package. I upgraded to the latest HA Core, but this did not help. There is not any change in on/off switch behavior.

I added some logging to the aiohue lights.py set_state function.

There is only one request sent to the Hue Bridge, and it is a simple one. It contains a key difference vs what I tried myself: “alert”.

This “alert” : “none” is the culprit causing the additional “on + off” flashing when sending an “on” : True request. It does not flash with an “on” : False request.

Seems like this is also happening with other third party lights (LIDL light strips) via the Hue bridge.

And the Hue integration already has a workaround for lights from manufacturer “Innr” in the code, which needs expanding.

Modified temporarily myself.

# diff light.py.original light.py
--- light.py.original
+++ light.py
@@ -213,12 +213,14 @@
             self.is_osram = False
             self.is_philips = False
             self.is_innr = False
+            self.is_ewelink = False
             self.gamut_typ = GAMUT_TYPE_UNAVAILABLE
             self.gamut = None
         else:
             self.is_osram = light.manufacturername == "OSRAM"
             self.is_philips = light.manufacturername == "Philips"
             self.is_innr = light.manufacturername == "innr"
+            self.is_ewelink = light.manufacturername == "eWeLink"
             self.gamut_typ = self.light.colorgamuttype
             self.gamut = self.light.colorgamut
             _LOGGER.debug("Color gamut of %s: %s", self.name, str(self.gamut))
@@ -402,7 +404,7 @@
         elif flash == FLASH_SHORT:
             command["alert"] = "select"
             del command["on"]
-        elif not self.is_innr:
+        elif not (self.is_innr or self.is_ewelink):
             command["alert"] = "none"

         if ATTR_EFFECT in kwargs:

After this change, the on/off switches works as expected. No more “flashing” when turning on.

1 Like

I raised an issue towards the home-assistant core project and the Hue integration on GitHub.

2 Likes

Well done. Can you PR your changes?

This feels like a quick and dirty fix, and if multiple manufacturer devices behave this way, I would prefer some more robust way to handle and even customize or modify the “alert” behavior.

Ok, wanted to make sure this wasn’t the behavior I see with my Z-Wave dimmers where the UI element switches back to the previous state after I actuate it, until the update is reported back from the dimmer…

the folders “/config/custom_components/hue/light.py” do not appear in my home assistant,
do I have to create it?
Do I have to edit something in the “configuration.yaml”?
What steps do I have to follow to apply the solution?
Thank you

Hue is an included component, not custom. For me I find it here:

/usr/src/homeassistant/homeassistant/components/hue/light.py

I open the address of my raspberry pi with the samba share addon and the folders that appear are (addon, backup, config, media, share and ssl), usr or src I can’t find them, sorry but I’m new to home assistants and I’m a little green and I’m Spanish and I’m translating the same thing, I express myself a little badly

I am wondering if it makes sense to raise a Feature Request to have the chance to change the default behaviour of turn off light to set brightness to 0. This way when turning on also the selected brightness and color is correct from the start.

have asked that question also in another topic

I use the debug access for HassOS. Not sure if it’s possible to reach these files directly any other way.

Answered on another thread: