Dim lights based on the sun's elevation

You’ll find it in the developer tools

Interesting…

I wonder why it doesn’t add the kökslampa to the array… I’ll think a bit and see what I can find.

I figured out why it doesn’t update.

Have you manually changed the brightness (or have any other automation that update the brightness) of the light between updates of the sun elevation?

As soon at the value does not match the previous value, it will stop updating the light.

As you can see the current brightness is 138 but calculating the brightness from the previous elevation of the sun isär ahould have been 115.

If you turn off and then on the lamp again it should set the brightness again.

I did change the brightness manually because the automation didn’t. I removed the other automations aswell.
When i turn off and on the lamp it takes the new value from the automation, but it still don’t change the brightness automaticaly?
I can see that the automation works but it do not affect the lamp.

Can you turn on the light, send the debug output then wait for 30 minutes without doing anything to the light and send the debug output for the last 30 minutes?

Start:

2021-02-17 09:18:09 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 10.33 (-8, 18)

new brightness: 131

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘off’, ‘brightness’: None}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: [‘light.lampa_koksfonster’]

turn_off_entities: []

Triggered by: event

entity_id: light.lampa_koksfonster

service_data_length: 1

complete event data: {‘domain’: ‘light’, ‘service’: ‘turn_on’, ‘service_data’: {‘entity_id’: ‘light.lampa_koksfonster’}}

2021-02-17 09:18:10 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: True

affected_entities: []

elevation: 10.33 (-8, 18)

new brightness: 131

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘off’, ‘brightness’: None}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: event

entity_id: [‘light.lampa_koksfonster’]

service_data_length: 3

complete event data: {‘domain’: ‘light’, ‘service’: ‘turn_on’, ‘service_data’: {‘entity_id’: [‘light.lampa_koksfonster’], ‘brightness’: 131, ‘transition’: 1}}

End:

2021-02-17 09:18:09 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 10.33 (-8, 18)

new brightness: 131

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘off’, ‘brightness’: None}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: [‘light.lampa_koksfonster’]

turn_off_entities: []

Triggered by: event

entity_id: light.lampa_koksfonster

service_data_length: 1

complete event data: {‘domain’: ‘light’, ‘service’: ‘turn_on’, ‘service_data’: {‘entity_id’: ‘light.lampa_koksfonster’}}

2021-02-17 09:18:10 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: True

affected_entities: []

elevation: 10.33 (-8, 18)

new brightness: 131

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘off’, ‘brightness’: None}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: event

entity_id: [‘light.lampa_koksfonster’]

service_data_length: 3

complete event data: {‘domain’: ‘light’, ‘service’: ‘turn_on’, ‘service_data’: {‘entity_id’: [‘light.lampa_koksfonster’], ‘brightness’: 131, ‘transition’: 1}}

2021-02-17 09:21:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 10.71 (-8, 18)

last elevation: 10.33

new brightness: 133

last brightness: 131

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 10.33, azimuth: 133.02)

to: (elevation: 10.71, azimuth: 133.94)

2021-02-17 09:25:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 11.09 (-8, 18)

last elevation: 10.71

new brightness: 134

last brightness: 133

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 10.71, azimuth: 133.94)

to: (elevation: 11.09, azimuth: 134.86)

2021-02-17 09:29:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 11.46 (-8, 18)

last elevation: 11.09

new brightness: 136

last brightness: 134

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 11.09, azimuth: 134.86)

to: (elevation: 11.46, azimuth: 135.78)

2021-02-17 09:33:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 11.82 (-8, 18)

last elevation: 11.46

new brightness: 137

last brightness: 136

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 11.46, azimuth: 135.78)

to: (elevation: 11.82, azimuth: 136.7)

2021-02-17 09:37:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 12.18 (-8, 18)

last elevation: 11.82

new brightness: 139

last brightness: 137

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 11.82, azimuth: 136.7)

to: (elevation: 12.18, azimuth: 137.64)

2021-02-17 09:41:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 12.53 (-8, 18)

last elevation: 12.18

new brightness: 141

last brightness: 139

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 12.18, azimuth: 137.64)

to: (elevation: 12.53, azimuth: 138.57)

2021-02-17 09:45:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 12.88 (-8, 18)

last elevation: 12.53

new brightness: 142

last brightness: 141

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 12.53, azimuth: 138.57)

to: (elevation: 12.88, azimuth: 139.51)

2021-02-17 09:49:20 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

affected_entities: [‘light.lampa_koksfonster’]

elevation: 13.22 (-8, 18)

last elevation: 12.88

new brightness: 144

last brightness: 142

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 128}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 12.88, azimuth: 139.51)

to: (elevation: 13.22, azimuth: 140.45)

Here is the problem…

For some reason the brightness is set to 128 by something, or the brightness resolution is just not high enough in this particular lamp.

If you set the brightness in developer tools manually to say 131 then click again on the entity and check if it stays at 131 or if it is set to 128 again.

But that is the problem, it is changed by something or due to not having as many brightness steps or something.

When we have figured out why this happen, I can add an option in the blueprint to work around it.

I changed the value in the developer tools (tried many different), but when I click on my lamp icon it takes the value “165” all the time. My lamp icon in Lovelace shows that it’s dimmed, but the light source it self does not dim. It only does when I dim in Lovelace.
I have double checked all my apps and there is nothing else than Home Assistant that changes this lamp.

It is a Qubino flush dimmer connected to the lamp.

I’ll implement a slider to allow updating the light of the value has been changed less than defined by the slider.

I’ll post it here when it’s ready

@mattiasfoto I have pushed a new version to GitHub. You can get it from here

After you have updated the blueprint, set the new allowance value in the automation to 100% and see if it works.

Nice! I have updated my blueprint now. I will post updates later :slight_smile:

YES! it works now! :smiley: Thank you so much! :slight_smile: Do you want to see the logs again?

Yes but only for curiousity

I added this automation for two more light strips as you can see in the log, works perfectly :slight_smile:

2021-02-17 20:26:06 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: True

allowance_value: 254.0

affected_entities: []

elevation: -25.21 (6, -25)

new brightness: 50

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 56}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: event

entity_id: [‘light.device_68’, ‘light.device_69’]

service_data_length: 3

complete event data: {‘domain’: ‘light’, ‘service’: ‘turn_on’, ‘service_data’: {‘entity_id’: [‘light.device_68’, ‘light.device_69’], ‘brightness’: 45, ‘transition’: 0}}

2021-02-17 20:26:06 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: True

allowance_value: 254.0

affected_entities: []

elevation: -25.21 (6, -25)

new brightness: 50

current_states: [{‘entity_id’: ‘light.lampa_koksfonster’, ‘state’: ‘on’, ‘brightness’: 56}]

force_turn_on: False

force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: event

entity_id: [‘light.lampa_koksfonster’]

service_data_length: 3

complete event data: {‘domain’: ‘light’, ‘service’: ‘turn_on’, ‘service_data’: {‘entity_id’: [‘light.lampa_koksfonster’], ‘brightness’: 50, ‘transition’: 0}}

Hi, i tried to use your automation for my needs but i think it works the opposite of what i need.
my requirement is that the light turns on at sunset increasing the brightness as the sun sets, and that when the sun rises it gradually turns off.
is it possible to set your automation to do what i need?
Thanks

Yes, I’m planning on implementing that

I just pushed an updated version where I’ve added a switch called “Reversed” which if active will reverse the dim/bright direction.

Please test it out HERE

I’ve been running this the past few days, but it hasn’t been working. My log is full of the following warning:

  • Template variable warning: ‘dict object’ has no attribute ‘entity_id’ when rendering ‘{%- if target_lights.entity_id is string -%} {{ [target_lights.entity_id] }} {%- else -%} {{ target_lights.entity_id }} {%- endif -%}’
  • Template variable warning: ‘dict object’ has no attribute ‘command’ when rendering ‘{{ trigger.event.data.command }}’
  • Template variable warning: ‘dict object’ has no attribute ‘cluster_id’ when rendering ‘{{ trigger.event.data.cluster_id }}’
  • Template variable warning: ‘dict object’ has no attribute ‘endpoint_id’ when rendering ‘{{ trigger.event.data.endpoint_id }}’
  • Template variable warning: ‘force_brightness_day’ is undefined when rendering ‘{{ force_brightness_day }}’

[edit] the cause of the warnings appeared to be picking a device_id, now that I picked an entity_id the warnings are gone. I set the allowance to 100% and it now appears to work. When is the allowance ‘reset’?

2 Likes