home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.67k stars 30.42k forks source link

Wrong color and brightness when switching on the bulb with a scene #82210

Closed Kevguy91 closed 1 year ago

Kevguy91 commented 1 year ago

The problem

When I turn on an extinguished light bulb by calling a scene, the bulb starts with the last color temperature and brightness used. Example, a bulb lit in cold white will at 100% restart in cold at 100% white before switching to warm white at 50%.

I don't have this problem when calling scenes from zigbee2mqtt.

What version of Home Assistant Core has the issue?

2022.11.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

MQTT

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mqtt

Diagnostics information

config_entry-mqtt-80f6617a63b604b40e047885fc47505a.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @emontnemery, mind taking a look at this issue as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `mqtt` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign mqtt` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


mqtt documentation mqtt source (message by IssueLinks)

jbouwh commented 1 year ago

What integration is providing the scenes? You can find this out by opening the settings and then the related tab.

Kevguy91 commented 1 year ago

Sorry, I didn't understand your question.

My scenes are created in Home Assistant, the bulbs are managed by Zigbee2MQTT (installed with the addon in Home Assistant) . I guess the integration is therefore MQTT.

jbouwh commented 1 year ago

I see what you mean. It seems the state is loaded but the commands are not published.

Kevguy91 commented 1 year ago

I see what you mean too. Do you want specific logs?

I just remembered that in the beginning I was using ZHA and I had the same problem.

jbouwh commented 1 year ago

Well it seems scenes can be integration specific or generic. I assume some how servicecalls to the the integrations of the entities should be made. This is not initiated from from MQTT. The MQTT scène is not doing that, it needs an actor where it can publish the command to activate a scene, e.g. a bridge like zigbee2mqtt. That type of scheme is not initiated from the ha GUI. I need to understand first what is happening when scenes are used with MQTT items and if there is a bug of a missing feature. @emontnemery do you know how generic scenes are supposed to work with MQTT items?

jbouwh commented 1 year ago

As I am debugging I see that

https://github.com/home-assistant/core/blob/dev/homeassistant/components/light/reproduce_state.py

should call the correct services to allow the integration to perform the correct actions. It would help to known what state is actually requested through the scene.

home-assistant[bot] commented 1 year ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (light) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `light` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign light` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


light documentation light source (message by IssueLinks)

Kevguy91 commented 1 year ago

How can I help you to know the requested state through the scene? I'm not very familiar with Home Assistant, I do simple things, especially via the UI.

jbouwh commented 1 year ago

You can get the state using the UI via developer tools. It would be nice to have a wanted state and what you are experiencing that happens when that setting is in a scene and activated.

Kevguy91 commented 1 year ago

I found this, tell me if this is not the information you need.

`- id: '1669837339893' name: Chambre Charlie - Nuit entities: light.chambre_charlie_lumiere_applique_gauche: min_color_temp_kelvin: 2202 max_color_temp_kelvin: 6535 min_mireds: 153 max_mireds: 454 effect_list:

jbouwh commented 1 year ago

Translates from your data attribute data I can see one light state set:

  min_color_temp_kelvin: 2202
  max_color_temp_kelvin: 6535
  min_mireds: 153
  max_mireds: 454
  effect_list:
   - blink
   - breathe
   - okay
   - channel_change
   - finish_effect
   - stop_effect
  supported_color_modes:
   - color_temp
  hue_power_on_behavior: recover
  last_seen: '2022-11-30T20:58:28+01:00'
  linkquality: 87
  update:
  state: idle
  update_available:
  friendly_name: Chambre Charlie / Lumière applique gauche
  supported_features: 44
  color_mode: color_temp
  brightness: 102
  color_temp_kelvin: 2202
  color_temp: 454
  hs_color:
   - 29.79
   - 84.553
  rgb_color:
   - 255
   - 146
   - 39
  xy_color:
   - 0.579
   - 0.388
  state: 'on'

So if you switch this using the scene could you have a look at the lights state? (use the developer tools).

Like:

afbeelding

Interesting is if the state reported here is the same as set in the scene.

Kevguy91 commented 1 year ago

Yes on this scene I only have one light bulb, on other scene there are several.

After turning on the bulb by activating the scene I get this state :

Capture d’écran 2022-12-03 191746

jbouwh commented 1 year ago

The state seems to be set correctly, I'll need some time to find out what commands would be executed with this state, and if they are correct with the given state.

Kevguy91 commented 1 year ago

No problem, I stay tuned if you need more information.

jbouwh commented 1 year ago

I have tried to reproduce your state. With color_temp as supported color_modes. The light integration will call the service light.turn_on with: brightness=102 and hs_color=(29.79, 84.553). So it actually ignores the other state attributes. So what I guess is that is behavior could be caused by zigbee2mqtt (not a part of Home Assistant) that is setting the wrong color_mode. What you can try is do this service_call manually using the developers tools, and see your self if that is the same behavior setting the scene causes.

jbouwh commented 1 year ago

As far as I can see this not an issue with MQTT or scene, the state is restored correctly. The reported color modes indicate only color temp is supported. It can be that the the lights configuration is not correctly. It is a bit weird that also rgb and xy colors are part of the state while the light does not seem to support those modes. What integration is generating the light issues that you have trouble with? Are you using Zigbee2MQTT?

Kevguy91 commented 1 year ago

Sorry to answer so late, my son has just been born, I did not take the time to start the PC.

Most of the time I trigger the scenes with automations managed by HA. However, I also use Adaptive Lighting (installed from HACS) when I don't need a particular scene.

Whether with Adaptive Lighting or with scenes, the problem remains the same.

And I already had this problem before Adaptive Lighting. I even had the problem with ZHA before switching to Z2M. Z2M which is installed with an add-on in HA.

My bulbs are from the Hue and Tradfri range, the firmware is up to date.

jbouwh commented 1 year ago

Well I do not think the issue is MQTT specific. From the states saved in the scene a service request light ON will be called. Somehow the captured scene state in not reproduced correctly. For what I can see the called services are correct. So it might be the lights are not reporting the correct state. Zigbee2Mqtt might have it owns scene functionality. MQTT only passed though the commands to Zigbee2Mqtt.

Did you try calling the Light ON service manually using the developer tools as I suggested above?

Kevguy91 commented 1 year ago

Indeed, during my tests with Z2M scenes, I don't have this problem, so yes the problem must come from the light on service, but I don't understand why. My bulbs are all configured like this in Z2M (see the screen print) Capture d’écran 2022-12-26 221525 Capture d’écran 2022-12-26 221305

I did some tests with the development tools and I have the same problem, with the light on and scene on service.

jbouwh commented 1 year ago

I have been testing myself, but I can not find out what could be wrong. It would help to have a step-by-step instruction of to reproduce this issue. Also include information about the lights and type you set-up.

jbouwh commented 1 year ago

What can go wrong if the light is created through MQTT discovery and the brightness configuration flag is not set (default is false). If so, when restoring the brightness attribute will not be set, causing it to restore the brightness to the last value set. To know if that could be the issue, you could examine the MQTT discovery payload. If it has not set the brightness config flag to true, then that could be the issue.

Kevguy91 commented 1 year ago

If you want, you can take control of my PC with Team Viewer to find all the information you need, maybe it will be easier?

jbouwh commented 1 year ago

That won't be needed. I see that supported_features == 44. With that we can determine the capabilities of the light.

Kevguy91 commented 1 year ago

Where do you find the supported_features detail by number?

jbouwh commented 1 year ago

You can find that here:

https://github.com/home-assistant/core/blob/0c7eb431e6e6fc3ca45ed397a33d078436c22af6/homeassistant/components/light/__init__.py#L44-L59

But I believe I should have a closer look at this. Perhaps the use of support brightness should be deprecated and be linked to color_mode.

jbouwh commented 1 year ago

Not sure that this will fix it: https://github.com/home-assistant/core/pull/84708

But al least this will ensure that a restored brighness attribute is set if the light is in color_temp mode. Strictly the brightness flag should be set to true, but if the light also supports rgb mode then brightness is not mandatory set.

Kevguy91 commented 1 year ago

And this bug fix will also allow you to have the right color temperature at startup, in addition to the right brightness?

jbouwh commented 1 year ago

It will respect the brightness attribute even if the brightness config flag is not set

home-assistant[bot] commented 1 year ago

mqtt documentation mqtt source

Kevguy91 commented 1 year ago

Ok, I'm waiting for the Home Assistant update and I'll come back to the topic to tell you what's going on.

emontnemery commented 1 year ago

Well it seems scenes can be integration specific or generic. I assume some how servicecalls to the the integrations of the entities should be made. This is not initiated from from MQTT. The MQTT scène is not doing that, it needs an actor where it can publish the command to activate a scene, e.g. a bridge like zigbee2mqtt. That type of scheme is not initiated from the ha GUI. I need to understand first what is happening when scenes are used with MQTT items and if there is a bug of a missing feature.

In this case, the state restore is handled by light/reproduce_state.py, which will translate the scene's stored light state to a light.turn_on call - there's no need for MQTT light to have specific support.

The light integration will call the service light.turn_on with: brightness=102 and hs_color=(29.79, 84.553). So it actually ignores the other state attributes.

That's exactly right, the main reason for adding the color mode concept to light was to be able to restore states.

It is a bit weird that also rgb and xy colors are part of the state while the light does not seem to support those modes.

A color temperature will be converted to the closest hs, rgb and xy color too. That's done to help groups etc. better represent the combined state of several bulbs, and also to help frontend with the light icon color. Restore state will ignore this though, and only consider the color temperature and brightness.

It is indeed weird that the scene stores redundant data, but that's how it's implemented - filtering of the data happens when the scene is restored, not when it's created.

jbouwh commented 1 year ago

@Kevguy91 could you enable debug logging on homeassistant.core and homeassistant.components.mqtt as suggested below and supply us a log on the part where the scene is activated and is not restoring correctly?

logger:                                  
  default: info                          
  logs:                                 
    homeassistant.core: debug           
    homeassistant.components.mqtt: debug

For more information about debug logging see: https://www.home-assistant.io/integrations/logger/

Kevguy91 commented 1 year ago

Here is the file with the logs home-assistant.log

jbouwh commented 1 year ago

From your log I see that the lights are configured correctly:

2023-01-06 09:36:44.202 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on homeassistant/light/0x00178801093ce37e/light/config: b'{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"},{"topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 02/availability","value_template":"{{ value_json.state }}"}],"availability_mode":"all","brightness":true,"brightness_scale":254,"color_mode":true,"command_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 02/set","device":{"identifiers":["zigbee2mqtt_0x00178801093ce37e"],"manufacturer":"Philips","model":"Hue white ambiance E27 with Bluetooth (9290022169)","name":"Cuisine / Lumi\xc3\xa8re 02","sw_version":"1.93.11"},"effect":true,"effect_list":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"json_attributes_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 02","max_mireds":500,"min_mireds":150,"name":"Cuisine / Lumi\xc3\xa8re 02","schema":"json","state_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 02","supported_color_modes":["color_temp"],"unique_id":"0x00178801093ce37e_light_zigbee2mqtt"}'
2023-01-06 09:36:44.202 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on homeassistant/light/0x0017880109dfdad5/light/config: b'{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"},{"topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 06/availability","value_template":"{{ value_json.state }}"}],"availability_mode":"all","brightness":true,"brightness_scale":254,"color_mode":true,"command_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 06/set","device":{"identifiers":["zigbee2mqtt_0x0017880109dfdad5"],"manufacturer":"Philips","model":"Hue white ambiance GU10 with Bluetooth (929001953301)","name":"Cuisine / Lumi\xc3\xa8re 06","sw_version":"1.93.11"},"effect":true,"effect_list":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"json_attributes_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 06","max_mireds":454,"min_mireds":153,"name":"Cuisine / Lumi\xc3\xa8re 06","schema":"json","state_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 06","supported_color_modes":["color_temp"],"unique_id":"0x0017880109dfdad5_light_zigbee2mqtt"}'
2023-01-06 09:36:44.203 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on homeassistant/light/0x0017880109d7c6cf/light/config: b'{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"},{"topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 07/availability","value_template":"{{ value_json.state }}"}],"availability_mode":"all","brightness":true,"brightness_scale":254,"color_mode":true,"command_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 07/set","device":{"identifiers":["zigbee2mqtt_0x0017880109d7c6cf"],"manufacturer":"Philips","model":"Hue white ambiance GU10 with Bluetooth (929001953301)","name":"Cuisine / Lumi\xc3\xa8re 07","sw_version":"1.93.11"},"effect":true,"effect_list":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"json_attributes_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 07","max_mireds":454,"min_mireds":153,"name":"Cuisine / Lumi\xc3\xa8re 07","schema":"json","state_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 07","supported_color_modes":["color_temp"],"unique_id":"0x0017880109d7c6cf_light_zigbee2mqtt"}'
2023-01-06 09:36:44.203 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on homeassistant/light/0x0017880109e2f5bc/light/config: b'{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"},{"topic":"zigbee2mqtt/Entr\xc3\xa9e / Lumi\xc3\xa8re 01/availability","value_template":"{{ value_json.state }}"}],"availability_mode":"all","brightness":true,"brightness_scale":254,"color_mode":true,"command_topic":"zigbee2mqtt/Entr\xc3\xa9e / Lumi\xc3\xa8re 01/set","device":{"identifiers":["zigbee2mqtt_0x0017880109e2f5bc"],"manufacturer":"Philips","model":"Hue white ambiance GU10 with Bluetooth (929001953301)","name":"Entr\xc3\xa9e / Lumi\xc3\xa8re 01","sw_version":"1.93.11"},"effect":true,"effect_list":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"json_attributes_topic":"zigbee2mqtt/Entr\xc3\xa9e / Lumi\xc3\xa8re 01","max_mireds":454,"min_mireds":153,"name":"Entr\xc3\xa9e / Lumi\xc3\xa8re 01","schema":"json","state_topic":"zigbee2mqtt/Entr\xc3\xa9e / Lumi\xc3\xa8re 01","supported_color_modes":["color_temp"],"unique_id":"0x0017880109e2f5bc_light_zigbee2mqtt"}'
2023-01-06 09:36:44.203 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received retained message on homeassistant/light/0x0017880109b02a3b/light/config: b'{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"},{"topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 04/availability","value_template":"{{ value_json.state }}"}],"availability_mode":"all","brightness":true,"brightness_scale":254,"color_mode":true,"command_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 04/set","device":{"identifiers":["zigbee2mqtt_0x0017880109b02a3b"],"manufacturer":"Philips","model":"Hue white ambiance E27 with Bluetooth (9290022169)","name":"Cuisine / Lumi\xc3\xa8re 04","sw_version":"1.93.11"},"effect":true,"effect_list":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"json_attributes_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 04","max_mireds":500,"min_mireds":150,"name":"Cuisine / Lumi\xc3\xa8re 04","schema":"json","state_topic":"zigbee2mqtt/Cuisine / Lumi\xc3\xa8re 04","supported_color_modes":["color_temp"],"unique_id":"0x0017880109b02a3b_light_zigbee2mqtt"}'

The brightness option is set on all lights.

I cannot see any issues here. What is needed further is a sample config of a scene that is stored. We need to have the entity names linked together with the config and the scene data to be able to reproduce what data is send to Zigbee2MQTT. In reproducing state state

The first config (taken from the debug log shows):

{
   "availability":[
      {
         "topic":"zigbee2mqtt/bridge/state",
         "value_template":"{{ value_json.state }}"
      },
      {
         "topic":"zigbee2mqtt/Cuisine / Lumi\\xc3\\xa8re 09/availability",
         "value_template":"{{ value_json.state }}"
      }
   ],
   "availability_mode":"all",
   "brightness":true,
   "brightness_scale":254,
   "color_mode":true,
   "command_topic":"zigbee2mqtt/Cuisine / Lumi\\xc3\\xa8re 09/set",
   "device":{
      "identifiers":[
         "zigbee2mqtt_0x0017880109dfdcdc"
      ],
      "manufacturer":"Philips",
      "model":"Hue white ambiance GU10 with Bluetooth (929001953301)",
      "name":"Cuisine / Lumi\\xc3\\xa8re 09",
      "sw_version":"1.93.11"
   },
   "effect":true,
   "effect_list":[
      "blink",
      "breathe",
      "okay",
      "channel_change",
      "finish_effect",
      "stop_effect"
   ],
   "json_attributes_topic":"zigbee2mqtt/Cuisine / Lumi\\xc3\\xa8re 09",
   "max_mireds":454,
   "min_mireds":153,
   "name":"Cuisine / Lumi\\xc3\\xa8re 09",
   "schema":"json",
   "state_topic":"zigbee2mqtt/Cuisine / Lumi\\xc3\\xa8re 09",
   "supported_color_modes":[
      "color_temp"
   ],
   "unique_id":"0x0017880109dfdcdc_light_zigbee2mqtt"
}

What command is published for the light depends on the state that is to reproduced taken from the scene.

emontnemery commented 1 year ago

I'm closing this since there has been no response from the issue author for two months. @Kevguy91 Please open another issue and refer to this one if you still have the problem 👍