basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.71k stars 128 forks source link

adaptive_lighting.change_switch_settings changes not being applied, although logs say they are #785

Closed tinnetju closed 10 months ago

tinnetju commented 10 months ago

Home Assistant Adaptive Lighting Issue Template

Bug Reports

If you need help with using or configuring Adaptive Lighting, please open a Q&A discussion thread here instead.

Before submitting a bug report, please follow these troubleshooting steps:

Please confirm that you have completed the following steps:

Required information for bug reports:

Please include the following information in your issue.

Issues missing this information may not be addressed.

  1. Debug logs captured while the issue occurred. See here for instructions on enabling debug logging:
2023-09-03 22:38:43.848 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: Set switch settings for lights '['light.woonkamer_plafonniere_1', 'light.woonkamer_plafonniere_2']'. now using data: '{'lights': ['light.woonkamer_plafondlamp'], 'interval': datetime.timedelta(seconds=90), 'transition': 5.0, 'initial_transition': 1.0, 'min_brightness': 5, 'max_brightness': 50, 'min_color_temp': 1000, 'max_color_temp': 1500, 'prefer_rgb_color': False, 'sleep_brightness': 1, 'sleep_rgb_or_color_temp': 'color_temp', 'sleep_color_temp': 1000, 'sleep_rgb_color': [255, 56, 0], 'sleep_transition': 1.0, 'transition_until_sleep': False, 'sunrise_time': datetime.time(6, 57, 10), 'min_sunrise_time': None, 'max_sunrise_time': None, 'sunrise_offset': datetime.timedelta(0), 'sunset_time': datetime.time(20, 20, 46), 'min_sunset_time': None, 'max_sunset_time': None, 'sunset_offset': datetime.timedelta(0), 'brightness_mode': 'default', 'brightness_mode_time_dark': datetime.timedelta(seconds=900), 'brightness_mode_time_light': datetime.timedelta(seconds=3600), 'take_over_control': True, 'detect_non_ha_changes': False, 'autoreset_control_seconds': 28800, 'only_once': False, 'adapt_only_on_bare_turn_on': False, 'separate_turn_on_commands': False, 'send_split_delay': 0, 'adapt_delay': 0.0, 'skip_redundant_commands': True, 'intercept': True, 'multi_light_intercept': True, 'include_config_in_attributes': False, 'name': 'Woonkamer plafondlamp'}'
2023-09-03 22:38:43.849 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Called 'adaptive_lighting.change_switch_settings' service with '{'entity_id': ['switch.adaptive_lighting_woonkamer_plafondlamp'], 'sunrise_time': '06:57:10', 'sunset_time': '20:20:46', 'use_defaults': 'current'}'
2023-09-03 22:38:43.849 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: '_update_attrs_and_maybe_adapt_lights' called with context.id='01H9EC9TW9:al:K5XW:srvc:01' lights: '['light.woonkamer_plafonniere_1', 'light.woonkamer_plafonniere_2']', transition: '1.0', force: 'True'
2023-09-03 22:38:43.850 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: filtered_lights: '['light.woonkamer_plafonniere_1', 'light.woonkamer_plafonniere_2']'
2023-09-03 22:38:43.850 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01H9EC9237:al:K5XW:trn_:00'
2023-09-03 22:38:43.850 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: Calling _adapt_light from _update_attrs_and_maybe_adapt_lights: 'light.woonkamer_plafonniere_1' with transition 1.0 and context.id=01H9EC9TW9:al:K5XW:srvc:01
2023-09-03 22:38:43.851 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] is_proactively_adapting_context='False', context_id='01H9EC9237:al:K5XW:trn_:00'
2023-09-03 22:38:43.851 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: Calling _adapt_light from _update_attrs_and_maybe_adapt_lights: 'light.woonkamer_plafonniere_2' with transition 1.0 and context.id=01H9EC9TW9:al:K5XW:srvc:01
2023-09-03 22:38:43.854 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: Setting color_temp of light light.woonkamer_plafonniere_1
2023-09-03 22:38:43.854 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.woonkamer_plafonniere_1 with service data {'entity_id': 'light.woonkamer_plafonniere_1', 'transition': 1.0, 'brightness': 50, 'color_temp_kelvin': 2702}
2023-09-03 22:38:43.854 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.woonkamer_plafonniere_1, context_id=01H9EC9TW9:al:K5XW:srvc:01, sleep_time=1.0, force=True, max_length=1, which=both, initial_sleep=False)
2023-09-03 22:38:43.854 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: Setting color_temp of light light.woonkamer_plafonniere_2
2023-09-03 22:38:43.854 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.woonkamer_plafonniere_2 with service data {'entity_id': 'light.woonkamer_plafonniere_2', 'transition': 1.0, 'brightness': 50, 'color_temp_kelvin': 2702}
2023-09-03 22:38:43.854 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.woonkamer_plafonniere_2, context_id=01H9EC9TW9:al:K5XW:srvc:01, sleep_time=1.0, force=True, max_length=1, which=both, initial_sleep=False)
2023-09-03 22:38:43.855 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: Scheduling 'light.turn_on' with the following 'service_data': {'entity_id': 'light.woonkamer_plafonniere_1', 'transition': 1.0, 'brightness': 50} with context.id='01H9EC9TW9:al:K5XW:srvc:01'
2023-09-03 22:38:43.855 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer plafondlamp: Scheduling 'light.turn_on' with the following 'service_data': {'entity_id': 'light.woonkamer_plafonniere_2', 'transition': 1.0, 'brightness': 50} with context.id='01H9EC9TW9:al:K5XW:srvc:01'
2023-09-03 22:38:43.855 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.woonkamer_plafonniere_1']')' event with context.id='01H9EC9TW9:al:K5XW:srvc:01'
2023-09-03 22:38:43.855 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01H9EC9TW9:al:K5XW:srvc:01', is_skipped_hash='False'
2023-09-03 22:38:43.856 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.woonkamer_plafonniere_2']')' event with context.id='01H9EC9TW9:al:K5XW:srvc:01'
2023-09-03 22:38:43.856 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01H9EC9TW9:al:K5XW:srvc:01', is_skipped_hash='False'
2023-09-03 22:38:53.780 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Woonkamer: '_update_attrs_and_maybe_adapt_lights' called with context.id='01H9ECA4JM:al:K5XW:ntrv:0B' lights: 'None', transition: '5.0', force: 'False'
  1. Your Adaptive Lighting configuration:
{
        "entry_id": "680509b85ef234863e96f494a436cb19",
        "version": 1,
        "domain": "adaptive_lighting",
        "title": "Woonkamer plafondlamp",
        "data": {
          "name": "Woonkamer plafondlamp"
        },
        "options": {
          "lights": [
            "light.woonkamer_plafondlamp"
          ],
          "interval": 90,
          "transition": 5.0,
          "initial_transition": 1.0,
          "min_brightness": 5,
          "max_brightness": 50,
          "min_color_temp": 1000,
          "max_color_temp": 1500,
          "prefer_rgb_color": false,
          "sleep_brightness": 1,
          "sleep_rgb_or_color_temp": "color_temp",
          "sleep_color_temp": 1000,
          "sleep_rgb_color": [
            255,
            56,
            0
          ],
          "sleep_transition": 1.0,
          "transition_until_sleep": false,
          "sunrise_time": "08:00:00",
          "min_sunrise_time": "None",
          "max_sunrise_time": "None",
          "sunrise_offset": 0,
          "sunset_time": "21:00:00",
          "min_sunset_time": "None",
          "max_sunset_time": "None",
          "sunset_offset": 0,
          "brightness_mode": "default",
          "brightness_mode_time_dark": 900,
          "brightness_mode_time_light": 3600,
          "take_over_control": true,
          "detect_non_ha_changes": false,
          "autoreset_control_seconds": 28800,
          "only_once": false,
          "adapt_only_on_bare_turn_on": false,
          "separate_turn_on_commands": false,
          "send_split_delay": 0,
          "adapt_delay": 0.0,
          "skip_redundant_commands": true,
          "intercept": true,
          "multi_light_intercept": true,
          "include_config_in_attributes": false
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "Woonkamer plafondlamp",
        "disabled_by": null
      },
  1. (If using Zigbee2MQTT), provide your configuration files (remove all personal information before posting):

    • devices.yaml
    • groups.yaml
    • configuration.yaml ⚠️; Warning REMOVE ALL of the PERSONAL INFORMATION BELOW before posting ⚠️;
      • mqtt: server:
      • mqtt: user:
      • mqtt: password:
      • advanced: pan_id:
      • advanced: network_key:
      • anything in log_syslog if you use this
    • Brand and model number of problematic light(s)
      Not relevant, although I can provide them if necassery.
  2. Describe the bug and how to reproduce it: I have created an automation that takes the next_rising and next_setting values of the sun integration, parses them, and attempts to update them using the adaptive_lighting.change_switch_settings service. The values are correct (i can copy and paste them in the adaptive lightning configuration) and the logs state they are accepted and applied. However, when reviewing the values of the configs (in the UI and in the config entries) the new values have not been applied.

Little sidenote, i'm relatively new in the HA-world so excuse me if it's a fault on my end. Also, feel free to use this automation as I think it might be a valuable addition to the change_settings service.

  1. Steps to reproduce the behavior: Run the automation
    - id: '1693652994815'
    alias: 'Adaptive lighting: Automatically set sunrise- and sunset times'
    description: Automatically sets actual sunrise- and sunset times every morning
    trigger:
    - platform: sun
    event: sunrise
    offset: 0
    condition: []
    action:
    - service: adaptive_lighting.change_switch_settings
    data:
      entity_id: switch.adaptive_lighting_woonkamer_plafondlamp
      sunrise_time: '{{ as_timestamp(state_attr(''sun.sun'', ''next_rising'')) | timestamp_custom(''%H:%M:%S'',
        true) }}'
      sunset_time: '{{ as_timestamp(state_attr(''sun.sun'', ''next_setting'')) | timestamp_custom(''%H:%M:%S'',
        true) }}'
basnijholt commented 10 months ago

The config will not reflect your changes it will only be set temporarily (they will be reset when restarting HA). You can see the settings in your switch's attributes.

BTW, I do not understand why you have this automation because by default it will use the current sunset and sunrise.

basnijholt commented 10 months ago

I added a note here https://github.com/basnijholt/adaptive-lighting/pull/786.

tinnetju commented 10 months ago

I had no idea the sunrise and sunset times were automatic by default, makes so much more sense haha. The settings being temporary also explain a lot. Thanks for the quick solution, you are awesome!