🌇 Activating Lights At Sunset

Can now confirm that with the latest version and no offset this seems to behave as expected. Thanks for your help!

A

1 Like

Great, glad it’s working as expected!

Hello @CyanAutomation ,
Thanks for the automation, but it’s not working for me with following error:

Logger: homeassistant.components.automation.giardino_lights_on_at_sunset
Source: components/homekit_controller/__init__.py:95
Integration: Automation (documentation, issues)
First occurred: 6:16:05 PM (6 occurrences)
Last logged: 10:02:15 PM

Giardino - Lights On At Sunset: Error executing script. Unexpected error for call_service at pos 1: '00000008-0000-1000-8000-0026BB765291'
While executing automation automation.giardino_lights_on_at_sunset
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 262, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1488, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1523, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 642, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 681, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 679, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 235, in async_handle_light_on_service
    await light.async_turn_on(**params)
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/light.py", line 116, in async_turn_on
    await self.async_put_characteristics(characteristics)
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/__init__.py", line 95, in async_put_characteristics
    payload = self.service.build_update(characteristics)
  File "/usr/local/lib/python3.8/site-packages/aiohomekit/model/services/service.py", line 137, in build_update
    char = self[char_type]
  File "/usr/local/lib/python3.8/site-packages/aiohomekit/model/services/service.py", line 118, in __getitem__
    return self.characteristics_by_type[key]
KeyError: '00000008-0000-1000-8000-0026BB765291'

Ideas why?

Thanks!

Simon

Hello, no ideas? Sad that for me it’s not working :’(

I’ve made (yet) another version of this:

this removes the entity selector and uses homeassistant.turn_on instead of “light” or “switch” . turn_on

this makes both (binary) lights and switches selectable in the same automation

(sorry, no idea how to link the blueprint thingie properly)

1 Like

Hi Simon

From your logs, it looks like your HomeKit integration is not happy with the structure of the automation. I don’t know why - but it’s likely specific to your implementation. Are you able to try it with other sets of lights that aren’t connected or controlled via HomeKit?

Hello @CyanAutomation , oh, yes it seems the root cause.
Actually I’ve no other lights than those handled via HomeKit. Strange is, that trying to create a simply automation that checks only the sun.sun position and if it’s in sunset it turns on the light, that works without problems. It does the same like yours, only in a simple version. What should I exactly choose between device or entity? Mine was added in your automation as a device.
I’ve no ideas which difference is in there. @Feyr your solution works different?
Thanks, Simon

If you have it working in your own automation- that’s great and then no need to use this blueprint.

If you want to continue troubleshooting, it’s worth trying controlling your lights via selecting them as an entity, instead. Alternatively, have you tried creating a Light Group, and selecting that?

silly question, do you have a blueprint for Sunset?

can you please add more offset, i have mine at +3 right now and i would like to turn on lights aprox 1hour earlier, it was pretty “dark” when they came on tonight.

Hi great work!!! Is it possible to add a condition like home of not??

1 Like

+1 for adding a condition

2 Likes

+1 for off at Sunset. I usually have a night-mode trigger to turn outside lights off but I would like to make sure they don’t run all day if that doesn’t happen for some reason. Is there a similar Blueprint that includes this?

Maybe this? Dim lights based on the sun's elevation - #67 by sophof

I added this tonight and had to wait for it to trigger my lights. Unfortunately it only triggered one of my 2 selected lights. Their both sonoff lights, one is a bulb located on the ceiling and the other is a RGB led strip locate under the tv cabinet.

I tried removing and adding the entity again but this didn’t work unfortunately.

I tested a bit more and i think it has to do with the brightness value. I tried making a normal automation, and the led strip didn’t want to turn on when i set the brightness to 50%. When i removed the brightness value it turned on when activating. It is a bit strange since the led strip is dimable.

Hi, thanks for creating this blueprint.
I works great, but it there also a blueprint for switch light off at sunrise? I’m using your blueprint to turn on some lights in the garden. No i also want them turn off automatically.

4 Likes

In trying to setup a complimentary blueprint/automation to turn my lights off at sunrise, I discovered that the rising state variable of sun is also convenient to use to prevent these automations from occurring both in the morning and evening when the sun is at its elevation offset. I had originally tried to use after: sunset similar to what the your blueprint does with after:sunrise, but saw this note in the sun conditions documentation:

Note that if only before key is used, the condition will be true from midnight until sunrise/sunset. If only after key is used, the condition will be true from sunset/sunrise until midnight.

So, my condition was not true anymore after midnight. I ended up using this condition, which is true from midnight to noon and false from noon to midnight:

condition:
  - condition: template
    value_template: '{{state_attr("sun.sun", "rising") == true}}'

~Dan

How can I add a condition to this blueprint? I only want it to execute if we are home.

1 Like

What is miss that i can choose which colour the light goes on.

1 Like

to make this work for sunrise would i just change these:

below: !input elevation_shift

to

above: !input elevation_shift

and

after: sunrise

to

after: sunset

my attempt at reversing this to work at sunrise

EDIT… I’m thinking about what i want here.

turning lights off at sunrise should only be done if they are turned on automatic, why? becuase if they are turned on by a human lets say 10 minutes before sunrise, you might end up having a hot morning shower in darkness, spec in winter time

for turning the lights on at sunset, i would say its safe to only do so if they are off, if they are on they might be set to a higher brightness and you might be cooking the dinner, and if the automation is set to turn on at 10% and you have it set to 70% you loose a lot of light