Turn on light directly without flashing on/off

What happens if you use the local API of the hue bridge?

I believe both Google and Hue uses the web API. But HA uses the local API.

Hue is centered around lights, and they do have their own switches which I suspect behave similarly, if not identical. The switches I bought work just fine with Hue, only the Hue integration in HA is quirky. Also in the Hue app they show up as lights, it’s really the only way. It let me choose an icon, and they have “plug” as an option.

Does anyone have experience with how official Philips on/off switches, or the IKEA switches, from the Hue bridge show up in HA via the Hue integration?

There doesn’t seem to be anything other than lights (besides motion sensors and remote controls) supported by this integration. Perhaps it, or the underlying light type, makes assumptions that do not align with this type of “light”.

Local API PUT request to change state works as I expect. I send “on” : true, and it turns on. No “flashing” behavior.

That was unexpected.
Have you tried to reboot HA and the bridge?

Ha reboot, yes. Not bridge, can’t see the point.

HA is behaving very oddly, and the behavior of the turn_on action with various parameters is even more strange. Hilarious, almost. I’ll try to compile a little list to show what it does.

I’ve tried to add a customizer entry to change the supported_features parameter from its default 63, to 0. The GUI seems to be the only component affected by this. It doesn’t show brightness or color picker any longer. But behavior is the same, and I can still change parameters related to these features when calling turn_on, and still get the same slightly different results. This tells me that the turn_on action doesn’t actually care about supported_features.

Perhaps they would work better with a real zigbee gateway.

Does the actual switch toggle on, off and then on again, or is it just the Lovelace UI display element that toggles like you describe?

1 Like

The physical switch toggles three times: off -> on -> off -> on. In the HA GUI it looks like a single “switched on” event is logged.

Turning it off via HA works properly and only toggles it once, 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: