adaptive-lighting icon indicating copy to clipboard operation
adaptive-lighting copied to clipboard

Zigbee2mqtt to fast for adapt

Open R3Cardoso opened this issue 1 year ago • 23 comments

Hi, this is not a bug, but I wasn't sure where to put my question.

I have Philips Hue devices on my HA working prefect with AL. But I decided to change my devices to zigbee2mqtt and noticed a improve on response time, for exemple when I click on a light switch and the light turns on. But this come with a problem. AL seems to not be able to adapt lights before they turn on. With Philips Hue intregation it works fine, but it take a 1 second to respond to the click.

Is there any setting on AL or zigbee2mqtt that resolve this?

R3Cardoso avatar May 13 '24 21:05 R3Cardoso

https://github.com/basnijholt/adaptive-lighting/discussions/501

th3w1zard1 avatar May 14 '24 02:05 th3w1zard1

I think i have the same issue so i'll add the required info as i'm interested if there is a solution to this as well.

For me the best example of this is this:

  • I have some motion activated hue lights, these change color temperature and brightness as set by AL.
  • AL Sleep mode is automatically activated at 22:30
  • If the motion activated light turns off before 22:30 and is activated after 22:30 in the evening or in the night it will blind you before adjusting to the sleep mode brightness which usually takes about 1 second.

The lamps used for the example are https://www.zigbee2mqtt.io/devices/9290022169.html

z2m configuration.yaml

homeassistant:
  legacy_entity_attributes: true
advanced:
  network_key:
    - 98
    - 146
    - 27
    - 216
    - 99
    - 152
    - 158
    - 208
    - 145
    - 36
    - 33
    - 19
    - 122
    - 31
    - 53
    - 223
  pan_id: 30227
  ext_pan_id:
    - 245
    - 248
    - 22
    - 74
    - 178
    - 205
    - 141
    - 150
  homeassistant_legacy_entity_attributes: false
  legacy_api: false
  legacy_availability_payload: false
  cache_state: true
  cache_state_persistent: true
  cache_state_send_on_startup: false
  report: true
mqtt:
  server: mqtt://core-mosquitto:1883
  user: addons
  password: -
  force_disable_retain: false
frontend:
  port: 8099
serial:
  port: >-
    /dev/serial/by-id/usb-Silicon_Labs_slae.sh_cc2652rb_stick_-_slaesh_s_iot_stuff_00_12_4B_00_23_90_B8_CA-if00-port0
device_options:
  legacy: false
  disabled: false
  homeassistant: true
  optimistic: true
  filtered_cache:
    - brightness
    - rgb_color
    - hs_color
    - xy_color
    - color_temp_kelvin
    - color_temp
    - color
    - color_mode
devices:
  '0x0017880102b0a892':
    friendly_name: ambiance_lamp
    transition: 1
  '0x001788010b7ed23f':
    friendly_name: couch_ceiling_light
    transition: 1
  '0x001788010b05f506':
    friendly_name: dining_table_ceiling_light
    transition: 1
  '0x001788010b553f41':
    friendly_name: kitchen_ceiling_light_1A
    transition: 1
  '0x001788010b501c7c':
    friendly_name: kitchen_ceiling_light_1B
    transition: 1
  '0x001788010901438e':
    friendly_name: bedroom_ceiling_light
    transition: 1
  '0x00178801062eeb48':
    friendly_name: passage_ceiling_light_1A
    transition: 1
  '0x0017880103282dea':
    friendly_name: hallway_motion_sensor
  '0x00178801062f06b9':
    friendly_name: passage_ceiling_light_1B
    transition: 1
  '0x0017880104876af2':
    friendly_name: Colour bulb 1
    transition: 1
  '0x00178801061d77b1':
    friendly_name: tv_light
    transition: 1
  '0x0017880106a07530':
    friendly_name: Colour bulb 3
    transition: 1
  '0x54ef441000a8c602':
    friendly_name: kitchen_motion_sensor
    occupancy_timeout: 60
  '0x0017880108c232a9':
    friendly_name: backyard_lamp
  '0x0017880108c23366':
    friendly_name: frontdoor_lamp
  '0xa4c138026f9adda5':
    friendly_name: kitchen_countertop_light
    transition: 1
  '0x001788010df5a852':
    friendly_name: passage_motion_sensor
  '0x187a3efffe6dabbb':
    friendly_name: '0x187a3efffe6dabbb'
    humidity_calibration: 0
    temperature_calibration: 0
    pm25_calibration: 0
  '0x001788010d7b6acc':
    friendly_name: hallway_ceiling_lamp
    transition: 1
  '0x54ef441000a12b7d':
    friendly_name: Supply Closet Door Sensor
  '0x8cf681fffe504b8d':
    friendly_name: Mailbox Sensor
    occupancy_timeout: 60
  '0x0017880104f3f003':
    friendly_name: '0x0017880104f3f003'
  '0x00178801062eecaf':
    friendly_name: office_ceiling_light
groups:
  '1':
    friendly_name: kitchen_ceiling_light
    devices:
      - 0x001788010b553f41/11
      - 0x001788010b501c7c/11
  '2':
    friendly_name: passage_ceiling_light
    devices:
      - 0x00178801062eeb48/11
      - 0x00178801062f06b9/11

Kuchiru avatar Jul 18 '24 13:07 Kuchiru

Hi there, I cannot make out if you are talking about AL not adapting the color or the brightness of your lights. If it's color adaptation, do try if the combination of execute_if_off and setting the color_temp before turning on the lights will solve your issue (https://github.com/basnijholt/adaptive-lighting/issues/1022#issuecomment-2218830648). Also check if you might have set adapt_delay in your AL configuration, if you want AL to adapt as quickly as possible, make sure that switch.adaptive_lighting_<name>, switch.adaptive_lighting_adapt_brightness_<name> and switch.adaptive_lighting_adapt_color_<name> are on, manual_control is off and the adapt_delay is set to '0'. Fiddling with intercept and multi_light_intercept might also work for you, as that tries to put all the settings you want in the light.turn_on (also take only_once and adapt_only_on_bare_turn_on into account) call from HASS. Groetjes,

djurny avatar Sep 25 '24 17:09 djurny

Hi there, Copied the reply from https://github.com/basnijholt/adaptive-lighting/discussions/506#top here, as it seems your question originated from this issue thread.

If your issue is that the color temperature of your lights is not changing immediately after turning on your bulb, this reply is for you.

In order to understand your issue better, the following information will help:

  • what method of switching off and switching on the light are you using? e.g. using 'empty' light.turn_on or a light.turn_on with brightness, color_temp or other option.
  • what do you expect to see and what is your observation? e.g. brightness does not change/transition after power on? or color/color_temp not change/transition? or brightness/color does change, but only after a few seconds or after a full interval as specified in the adaptive_lighting entity?

Any detail helps.

Thanks for the help, but I wasn't able to resolve anything. I'm not sure where I need to put the code? should be on all automations? //snip - repeat: for_each: '{{ state_attr(entity_light, "entity_id") }}' sequence: - service: mqtt.publish data_template: topic: 'zigbee2mqtt/{{state_attr(repeat.item, "friendly_name")}}/set/color_options' payload: | { "execute_if_off": "true" } - service: mqtt.publish data_template: topic: 'zigbee2mqtt/{{state_attr(repeat.item, "friendly_name")}}/set' payload: | { "color_temp": "{{turn_on_quirk_color_temp_mired_current}}", "transition": "0" } //snip

About transition I got 0 on zigbee2mqtt and adapt_delay, on initial_transition got 1 because it helps disguise the change.

To 'prime' the color_temp of your lights, which means set them to the wanted color_temp before you turn them on, you would have to make a script in homeassistant. You can read up here on what that entails.

As an basic example, your script would look as follows (this is a dry example, have not tested it whatsoever):

script:
  some_script_name_that_makes_sense:
    variables:
      ## change these to suit your situation
      name_light: 'kitchen'
      name_adaptive_lighting: 'kitchen'
      transition: '1'
      ## 
      entity_id_light: 'light.{{name_adaptive_lighting}}'
      entity_id_adaptive_lighting: 'adaptive_lighting.{{name_adaptive_lighting}}'
      mqtt_topic: 'zigbee2mqtt/{{name_light}}/set'
    sequence:
    - action: mqtt.publish
      data_template:
        payload: |-
            {
              "color_temp": "{{state_attr(entity_id_adaptive_lighting, 'color_temp_mired')}}"
            }
        topic: '{{mqtt_topic}}'
    - delay:
        hours: 0
        minutes: 0
        seconds: 0
        milliseconds: 250
    - light.turn_on
      data:
        transition: '{{transition}}'
      target:
        entity_id: '{{entity_id_light}}'

Note that for the script to work:

  • Your light should be a device/entity and not a group in home assistant. To make the script work for light groups, some additional YAML is required, but I wanted to make the example as short and easy as it can be.
  • Your light's name in home assistant should be the same as the friendly_name in zigbee2mqtt.
  • The adaptive lighting entity must have the same name as your light's name.
  • The switch entity switch.adaptive_lighting_kitchen switch must be enabled. (Normally speaking this is enabled unless you deliberately have turned it off.)
  • The switch entity switch.adaptive_lighting_adapt_color_kitchen must be enabled. (Normally speaking this is enabled unless you deliberately have turned it off.)
  • The switch entity switch.adaptive_lighting_adapt_brightness_kitchen must be enabled. (Normally speaking this is enabled unless you deliberately have turned it off.)

There is no simpler way to do this a.f.a.i.k.

Hope that helps, Groetjes,

djurny avatar Sep 26 '24 18:09 djurny