Dim lights based on the sun's elevation

Hello!

I have used this automation for about a year now and it has been working great! But for some weeks ago something has happen with my automation. It is triggered by call_service but does not longer dim the lights. I have 2 automations on different lights and it acts just the same on both.
I tried to remove the blueprint and installed it again, but got the same problem. I have restart all units aswell.

I use a Pi 4 and Telldus Znet.

// Mattias

Have you tried turning on debug and checked the logs?

Yes I had debug on. But I don’t really understand the logs. Unfortunately my logs from yesterday is lost since I updated the host today. I can try and copy the logs tomorrow. In Telldus history it sets dimming “failed” as a message.
Can this be a problem with the “sun” entity?

This appears in the log file every second:

2022-07-07 20:21:18 WARNING (SyncWorker_2) [tellduslive] Failed request: HTTPSConnectionPool(host=‘pa-api.telldus.com’, port=443): Max retries exceeded with url: /json/device/dim?level=203&id=5418195 (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0xa33a83e8>: Failed to establish a new connection: [Errno 101] Network unreachable’))
2022-07-07 20:21:18 WARNING (SyncWorker_0) [tellduslive] Failed request: HTTPSConnectionPool(host=‘pa-api.telldus.com’, port=443): Max retries exceeded with url: /json/device/dim?level=203&id=5418195 (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0x6ae2d6b8>: Failed to establish a new connection: [Errno 101] Network unreachable’))
2022-07-07 20:21:18 WARNING (SyncWorker_7) [tellduslive] Failed request: HTTPSConnectionPool(host=‘pa-api.telldus.com’, port=443): Max retries exceeded with url: /json/device/dim?level=203&id=5418195 (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0x90a6ad90>: Failed to establish a new connection: [Errno 101] Network unreachable’))
2022-07-07 20:21:18 WARNING (SyncWorker_5) [tellduslive] Failed request: HTTPSConnectionPool(host=‘pa-api.telldus.com’, port=443): Max retries exceeded with url: /json/device/dim?level=203&id=5418195 (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0x6ae2d160>: Failed to establish a new connection: [Errno 101] Network unreachable’))
2022-07-07 20:21:18 WARNING (SyncWorker_9) [tellduslive] Failed request: HTTPSConnectionPool(host=‘pa-api.telldus.com’, port=443): Max retries exceeded with url: /json/device/dim?level=203&id=5418195 (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0x9d77d538>: Failed to establish a new connection: [Errno 101] Network unreachable’))
2022-07-07 20:21:18 WARNING (SyncWorker_2) [tellduslive] Failed request: HTTPSConnectionPool(host=‘pa-api.telldus.com’, port=443): Max retries exceeded with url: /json/device/dim?level=203&id=5418195 (Caused by NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0xa2415d18>: Failed to establish a new connection: [Errno 101] Network unreachable’))

Seems like HA is unable to communicate with the Telldus cloud API.

When i have my automation enabled HA is quite slow, it looks like the automation is sending information every second and i am not able to turn the light on/off or even dim. Not even in the Telldus app. When i disable the automation and restart HA it works flawless to dim and turn on/off via HA and Telldus. So a problem with the API seems to me strange.

This message appear in the log file several times every second:

¨¨ 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’]}}
2022-07-11 20:08:15 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:
skip_event: False
allowance_value: 254.0
affected_entities: [‘light.lampa_koksfonster’]

elevation: 12.61 (13, -7)
last elevation: 12.61
new brightness: 103
last brightness: 103

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

force_turn_on: True
force_turn_off: False

entities: [‘light.lampa_koksfonster’]

turn_on_entities: [‘light.lampa_koksfonster’]

dim_entities: [‘light.lampa_koksfonster’]

turn_off_entities: []

For some reason this blueprint is not dimming my devices. I’ve tried with multiple devices (and as entities). I set the change allowance to 100% just in case and I’ve tried reversing the brightness, creating a fresh new automation, etc. Here’s a sample log entry:

2022-07-14 15:04:25 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

allowance_value: 254.0

affected_entities: ['light.scene_capable_plug_in_dimmer']

elevation: -1.55 (0, -30)

last elevation: -1.0

new brightness: 241

last brightness: 245

current_states: [{'entity_id': 'light.scene_capable_plug_in_dimmer', 'state': 'on', 'brightness': 129}]

force_turn_on: False

force_turn_off: False

entities: ['light.scene_capable_plug_in_dimmer']

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: -1.0, azimuth: 309.15)

to: (elevation: -1.55, azimuth: 309.95)

Maybe it’s time for a complete rewrite of this blueprint since home assistant have got many new features since this was written…

2 Likes

I’ve never been able to coax this blueprint into actually dimming a light. I tried light as entity, device, and room, and on completely different dimmable devices. Does this blueprint function in the most recent versions of HA? Here are some sample logs:

2022-08-07 09:46:03.731 WARNING (MainThread) [homeassistant.helpers.template] 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 -%}'

2022-08-07 09:46:03.744 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

allowance_value: 254.0

affected_entities:

elevation: 41.35 (-5.5, 5)

last elevation: 41.35

new brightness: 25

last brightness: 25

current_states: []

force_turn_on: False

force_turn_off: False

entities:

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: None

2022-08-07 09:46:09.005 WARNING (MainThread) [homeassistant.helpers.template] 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 -%}'

2022-08-07 09:46:09.022 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

allowance_value: 254.0

affected_entities: []

elevation: 41.35 (-5.5, 5)

last elevation: 41.35

new brightness: 25

last brightness: 25

current_states: []

force_turn_on: False

force_turn_off: False

entities:

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: event

entity_id: light.dining_room_lamp

service_data_length: 1

complete event data: {'domain': 'light', 'service': 'turn_on', 'service_data': {'entity_id': 'light.dining_room_lamp'}}

2022-08-07 09:46:39.933 WARNING (MainThread) [homeassistant.helpers.template] 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 -%}'

2022-08-07 09:46:39.967 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

allowance_value: 254.0

affected_entities:

elevation: 42.06 (-5.5, 5)

last elevation: 41.35

new brightness: 25

last brightness: 25

current_states: []

force_turn_on: False

force_turn_off: False

entities:

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: state

from: (elevation: 41.35, azimuth: 106.87)

to: (elevation: 42.06, azimuth: 107.73)

2022-08-07 09:47:56.112 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

allowance_value: 220.98

affected_entities: ['light.scene_capable_plug_in_dimmer']

elevation: 42.06 (-5.5, 5)

last elevation: 42.06

new brightness: 2

last brightness: 2

current_states: [{'entity_id': 'light.scene_capable_plug_in_dimmer', 'state': 'on', 'brightness': 139}]

force_turn_on: False

force_turn_off: False

entities: ['light.scene_capable_plug_in_dimmer']

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: None

2022-08-07 09:48:10.889 DEBUG (MainThread) [homeassistant.components.blueprint.dim_lights_based_on_sun_elevation] DEBUG:

skip_event: False

allowance_value: 220.98

affected_entities: ['light.scene_capable_plug_in_dimmer']

elevation: 42.06 (-5.5, 5)

last elevation: 42.06

new brightness: 2

last brightness: 2

current_states: [{'entity_id': 'light.scene_capable_plug_in_dimmer', 'state': 'on', 'brightness': 139}]

force_turn_on: False

force_turn_off: False

entities: ['light.scene_capable_plug_in_dimmer']

turn_on_entities: []

dim_entities: []

turn_off_entities: []

Triggered by: None

I made one that does a similar thing but with color temperature rather than brightness: Automatic circadian lighting - match your lights' color temperature to the sun!

1 Like

I’ve been using it for at least the last six months and keep my HA install fairly up to date. I use it to dim an LED strip located inside my chicken coop. I didn’t want a light that would all of a sudden turn off and leave my girls stranded off their perch, so I dim it slowly and that seems to work. My only issue was getting it to turn off. So I use this blueprint to dim it to 1% and then another to actually turn it off.

For some of my settings to get it to work. I did choose an entity over a device. 75% and then 1% for the max and min brightness levels. change allowance is set to 100%, turn on automatically is checked. Next two boxes are 6 degrees and -6 degrees. turn off lights automatically is NOT checked. Next three are -8, 6 and 0. Debug is off.
Then I use a basic automation to turn the LED strip off 45 minutes after sunset.

Hi Magnus,

Just to start with, I’m a little confused why one would want to dim lights at sunset? I would have thought one would have wanted to brighten lights at sunset.

I have outside lights on my house (Standard Chinese ESP32 dimmer modules) at the moment I’m turning them on using an Alexa Routine. All is working fine as I’m gradually increasing the brightness step by step in the Routine, 30% wait 20 seconds - 40% wait 20 seconds +++.up to 100%.

Having found your BluePrint I’m fascinated as I would like to, over time, gradually increase the brightness of the outside light with this BluePrint and I’m assuming there would be no perceived jump in brightness, as is the case using Alexa Routines, but just a slow increase up to maximum 100%.

You have put a button in the code to reverse the dimming to brightening. Can one assume that the description on the other sliders are also reversed ie: “dim” now equals “brighten”?

One or two more questions: See my YAML code below…

alias: Dim lights based on sun elevation
description: "Test dining table light "
use_blueprint:
path: EvTheFuture/dim_lights_based_on_sun_elevation.yaml
input:
target_lights:
entity_id: light.dining_table_light_light
turn_on: true
debugging: true
turn_off: false
min_brightness: 10
allowance: 20
end_elevation_setting: -5
transition_time: 0.25
reverse: true
start_elevation_setting: 6

Will this start to turn on my lights (I’m using a dimmable inside light to test) close to sunset?

If it works then I can adjust it to get it to how I would like it.

I did run a version of this and the light did come on but, unfortunately, it didn’t start to brighten!

How can one adjust the brightening interval, is this the “Transition time in seconds between brightness values” slider?

I did spend about two hours going through the above, some I understood and some I did not. I’m quite new to Home Assistant and some explanations can be a little too technical when one doesn’t understand most of the terms.

Thanks in advance for any help you can give.

Bob…