basnijholt / adaptive-lighting

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

Lights still change by A.L. #2

Closed poudenes closed 3 years ago

poudenes commented 3 years ago

Hi Bas,

I read all the info and maybe I don't it understand what you mean. Here full example how I config 1 light for testings:

adaptive lighting config:

- name: "Diningroom"
  lights:
    - light.dressoir_all
    - light.dressoir_1
    - light.dressoir_2
    - light.dressoir_3
  sleep_brightness: 20
  min_brightness: 70
  only_once: true
  max_color_temp: 3800
  min_color_temp: 2000
  interval: 30
  prefer_rgb_color: false
  take_over_control: true
  detect_non_ha_changes: true

automation to turn on 1 bulb with color red:

- alias: "TEST - Adaptive LIght"
  trigger:

    - platform: state
      entity_id: switch.newkaku_014e5906_a
      to: "on"

  action:
    - service: light.turn_on
      data:
        entity_id: light.dressoir_1
        color_name: "red"
        brightness_pct: 100

When the switch is on, light.dressoir_1 goes on into red. directly after it light.dressoir_1 turn into kelvin color by A.L.

Maybe I truly don't understand the way how it work?

basnijholt commented 3 years ago

But that is exactly how it is designed to work.

If the lights are off and something/someone turns on the lights, then it is adapted (also if you call light.turn_on(color_name='red')).

Only a change after that moment will lead to AL stopping.

poudenes commented 3 years ago

Then I understand you all the time :). And its lots of programming to add a feature like:

ignore_color: true

I can imagine that more people use colors in their house and some bulbs normal kelvin colors. If you can add a line to ignore the turn_on when there is a color involved that will be very useful.

Now I'm using the sensor of circadian and use the colortemp attribute in all scripts for lights that not use color at that moment. Only thing now I can't turn it off. because its read the attribute all the time.

basnijholt commented 3 years ago

And its lots of programming to add a feature like

Yes, it is a lot of work because there are many ways to specify a color.

Now I'm using the sensor of circadian and use the colortemp attribute in all scripts for lights that not use color at that moment. Only thing now I can't turn it off. because its read the attribute all the time.

Those sensor values are also available as attributes to the Adaptive Lighting switch!

You can also create an Adaptive Lighting switch with no lights at all and always leave it on. Then you can use the new service adaptive_lighting.apply to apply the settings to some lights (you need to update to the latest code to use it ;).

poudenes commented 3 years ago

Thanks for this info. I will create a switch leave it on. And will do some tests with the new service. Thanks for all the patient !

basnijholt commented 3 years ago

Great! Let me know how it works :)

poudenes commented 3 years ago

The adaptive_lighting.apply will only apply once to the light at that moment i guess?

basnijholt commented 3 years ago

That is correct 👍

Jeltel commented 3 years ago

I can imagine that more people use colors in their house and some bulbs normal kelvin colors. If you can add a line to ignore the turn_on when there is a color involved that will be very useful.

I'm not completely following. But I suspected just as @poudenes that when you turn on the light, and use something to specify the colour, colourtemperature or brightness, that Adaptive Lighting would ignore the light, (turning off the switch.adaptive_lighting_name) and only would restart the adaptive lighting, when the light was turned off (and then on again, without light settings). But If I'm correct, that's not what it does. How would I go around configuring a specific colour scheme, without Adaptive Lighting changing it?

  1. Turn off adaptive lighting switch, before turning the light to a specific setting?
  2. Do two light.turn_on. One to let adaptive lighting do it's thing and then to set the colour?

Both include an action that is not intuitive to me as a user.

basnijholt commented 3 years ago

Do two light.turn_on. One to let adaptive lighting do it's thing and then to set the colour?

I would do this.

It's like this because of implementation details.

There are many keywords to the light.turn_on service? I only want to implement behaviors that are consistent and that one can reason about why it happens. It quite complicated already.

For example, what you are proposing could never work for lights that are controlled outside of HA.

However, I will look into implementing this.

Jeltel commented 3 years ago

Ok, then it should work like I have it now.

I do a triple switch which sets a scene on all the lights in the living room. After a short while, adaptive lighting changes the light to the colour and brightness of that time of day. That's expected then. I would expect if I do the triple switch again, the lights remain in the set scene. However, the tradfri lights are changed by adaptive lighting. The Hue lights stay in the set scene.

Would that be a bug?

poudenes commented 3 years ago

Ok, then it should work like I have it now.

I do a triple switch which sets a scene on all the lights in the living room. After a short while, adaptive lighting changes the light to the colour and brightness of that time of day. That's expected then. I would expect if I do the triple switch again, the lights remain in the set scene. However, the tradfri lights are changed by adaptive lighting. The Hue lights stay in the set scene.

Would that be a bug?

That is a option. Not a nice one. First lights goto Adaptive lighting and then second action it give the light a color. If it was possible for Bas to implement something that Adaptive Lighting ignored the turn_on when there is a color set for the light.

What I did now as workaround: 1) Create a Adaptive Switch without lights in it:

- name: "Sensor"
  sleep_brightness: 20
  min_brightness: 70
  only_once: true
  max_color_temp: 3800
  min_color_temp: 2000
  interval: 30
  prefer_rgb_color: false
  take_over_control: true
  detect_non_ha_changes: true

2) Some code in automations to use the values for lights that need to use Adaptive Lighting For example here my full automation "Scene Evening". Here you see a set of holiday scenes based on conditions. Now my lights change directly to right color without problem.

###########################################################################################
# SCENE EVENING WHEN SUN IS BELOW HORIZON AND NO TV OF MOVIE IS PLAYING
###########################################################################################

- alias: "Scene - Evening"
  trigger:

    - platform: time_pattern
      minutes: 1

    - platform: state
      entity_id: sun.sun

    - platform: state
      entity_id: binary_sensor.sensor_manual_family_home

    - platform: state
      entity_id: switch.scene_goodnight

    - platform: state
      entity_id: sensor.harmony
      to: "off"

  condition:
    - condition: state
      entity_id: sun.sun
      state: "below_horizon"

    - condition: state
      entity_id:
        - switch.scene_evening
        - switch.scene_goodnight
        - sensor.harmony
      state: "off"

    - condition: state
      entity_id: binary_sensor.sensor_manual_family_home
      state: "on"

  action:
    - service: script.engine_say
      data:
        media_player: media_player.this_device
        call_scene_evening: 1

    - service: input_number.set_value
      data:
        entity_id: input_number.fullykiosk_brightness_slider
        value: 50

    - service: switch.turn_on
      entity_id: switch.scene_evening

    - service: switch.turn_off
      data:
        entity_id:
          - switch.scene_appletv
          - switch.scene_cooking
          - switch.scene_daytime
          - switch.scene_disco
          - switch.scene_goodnight
          - switch.scene_kodi
          - switch.scene_sexy
          - switch.scene_sleeping
          - switch.scene_tv
          - switch.lux_low

    - service: light.turn_on
      data:
        entity_id: light.nanoleaf
        brightness_pct: 30
        effect: >-
          {% if states('sensor.holiday') == 'Christmas' %} Christmas
          {% elif states('sensor.holiday') == 'Halloween' %} Halloween
          {% elif states('sensor.holiday') == 'Kingsday' %} Kingsday
          {% elif states('sensor.holiday') == 'Birthday' %} Kingsday
          {% else %} Kay
          {% endif %}

    - service: homeassistant.turn_on
      data:
        entity_id: light.newkaku_01401eb6_a
        brightness_pct: >-
          {% if states('binary_sensor.neo_diningroomdoor_custom_sensor') == 'on' and states('switch.kay_learning') == 'on' %} 100
          {% elif states('binary_sensor.neo_diningroomdoor_custom_sensor') == 'on' and states('switch.kay_learning') == 'off' %} 0
          {% elif states('binary_sensor.neo_diningroomdoor_custom_sensor') == 'off' and states('switch.kay_learning') == 'on' %} 100
          {% else %} 50
          {% endif %}

    - choose:
# CHRISTMAS
        - conditions:
            - condition: state
              entity_id: sensor.holiday
              state: "Christmas"
          sequence:
            - service: switch.turn_on
              entity_id:
                - switch.node_8_switch # Bank
                - switch.node_2_switch # iMac

            - service: light.turn_on
              data:
                entity_id: light.livingroom_all
                brightness_pct: 100
                kelvin: "{{ states.switch.adaptive_lighting_sensor.attributes.color_temp_kelvin | round(0)}}"

            - service: light.turn_on
              data:
                entity_id: light.dressoir_all
                color_name: "blue"
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.dressoir_2
                color_temp: 153
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.balcony
                brightness_pct: 100
                effect: 0

# HALLOWEEN
        - conditions:
            - condition: state
              entity_id: sensor.holiday
              state: "Halloween"
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.livingroom_all
                brightness_pct: 100
                kelvin: "{{ states.switch.adaptive_lighting_sensor.attributes.color_temp_kelvin | round(0)}}"

            - service: light.turn_on
              data:
                entity_id: light.dressoir_all
                color_name: "blue"
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.dressoir_2
                color_name: "purple"
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.balcony
                brightness_pct: 100
                effect: 0

# KINGSDAY
        - conditions:
            - condition: state
              entity_id: sensor.holiday
              state: "Kingsday"
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.livingroom_all
                brightness_pct: 100
                kelvin: "{{ states.switch.adaptive_lighting_sensor.attributes.color_temp_kelvin | round(0)}}"

            - service: light.turn_on
              data:
                entity_id: light.dressoir_1
                color_name: "red"
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.dressoir_2
                color_temp: 153
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.dressoir_3
                color_name: "blue"
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.balcony
                brightness_pct: 100
                effect: 0

# BITHRDAY
        - conditions:
            - condition: state
              entity_id: sensor.holiday
              state: "Birthday"
          sequence:
            - service: light.turn_on
              data:
                entity_id: light.livingroom_all
                brightness_pct: 100
                kelvin: "{{ states.switch.adaptive_lighting_sensor.attributes.color_temp_kelvin | round(0)}}"

            - service: light.turn_on
              data:
                entity_id:
                  - light.dressoir_1
                  - light.dressoir_2
                  - light.dressoir_3
                effect: 0
                brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"

            - service: light.turn_on
              data:
                entity_id: light.balcony
                brightness_pct: 100
                effect: 0

# DEFAULT
      default:
        - service: light.turn_on
          data:
            entity_id: light.livingroom_all
            brightness_pct: 100
            kelvin: "{{ states.switch.adaptive_lighting_sensor.attributes.color_temp_kelvin | round(0)}}"

        - service: light.turn_on
          data:
            entity_id: light.balcony
            brightness_pct: 100
            effect: 0

        - service: light.turn_on
          data:
            entity_id: light.dressoir_all
            brightness_pct: "{{ 0 if is_state('binary_sensor.neo_diningroomdoor_custom_sensor', 'on') else 100 }}"
Jeltel commented 3 years ago

Ok, that might work. But it's even less intuitive than my suggestion and would take up more configuration.

But I think that at least the Tradfri Lights aren't ignored after a second light.turn_on action. As that's what I've done here at home. I'll make a bug report for that.

basnijholt commented 3 years ago

I would expect if I do the triple switch again, the lights remain in the set scene. However, the tradfri lights are changed by adaptive lighting. The Hue lights stay in the set scene.

Would that be a bug?

Yes, that sounds like it! Could you create an issue and attach the log?

Jeltel commented 3 years ago

@basnijholt #5

poudenes commented 3 years ago

Thanks for all the support. I think we can close this.... thank for the A.L Intergration!!