Light Automation using the Sun

Hey :slight_smile:

I have been using Home Assistant for a few weeks now and am in the process of setting up my first lights.

Specifically, I want to switch on two lights using a motion detector. This should happen when the sun is behind the horizon and also up to two hours after sunrise and one hour before sunset.

I have already tried a few things with the help of the documentation, but always failed miserably and was always - either in the morning or in the evening - in the dark. It’s a pity that there is no preview “When will be triggered” for the conditions in the frontend.

Could someone please help me? The Wife Acceptance Factor is slowly but surely sinking… :slight_smile:

Kind regards

1 Like

You need to have a crack at this yourself and show what you tried. Then we can help correct an error. Teaching you to fish…

1 Like

Sorry :slight_smile:

This is my automation for now, which isn‘t triggered at / hours before sunrise.

You need it “before: sunset”

Thanks, will try :slight_smile:

after_offset: '02:00:00' is nevertheless correct?

Sorry other way round after: sunset and before:sunrise

The reason it was not working was you had them both after sunrise/sunset

Not working :-/ The lights stay off… Sunrise was about 20min ago.

image

I don’t see anywhere you have defined a trigger so it will never trigger

The shutter works :wink: When I take out the conditions, the light comes on.

I ask not without reason only for the condition. The conditions at sunrise and sunset are only apparently, as we see, a bit complex to understand, otherwise it would already work after the nice help.

But with pleasure I also publish the whole automation…

alias: Trigger lamps when sun goes down or up
description: 'Lorem Ipsum'
trigger:
  - type: motion
    platform: device
    device_id: 1e7764fa12a988118c0c2ad13d2411a5
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    domain: binary_sensor
condition:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
        after_offset: '-01:00:00'
      - condition: sun
        before: sunrise
        after_offset: '02:00:00'
  - condition: state
    entity_id: input_boolean.vacation
    state: 'off'
action:
  - service: light.turn_on
    entity_id: light.flurlampen_zha_group_0x0002
    data: {}
mode: single

@Remko, I know you said you’re new so welcome to the community, but for the love of God please stop dishing out advice until you know what you are talking about.

In the last 2 hours you’ve posted this

trigger:
  - platform: state
    entity_id: binary_sensor.sensor_bewegung_flur
    from: 'false'
    to: 'true'

Which will never work as the states for binary sensors are the strings ‘on’ and ‘off’.

And also this

  - condition: sun
    before: sunrise
    after: sunset

Which will never work because it cannot be both before sunrise and after sunset in the same day, its impossible.

I admire your enthusiasm and desire to help, but all you’re doing is adding confusion.

OP - your second Sun condition is before sunrise, but you’re using an after offset.

Thank you for your help. I will test and come back to you. :slight_smile: Merry Xmas!

1 Like

Excuse me. I indeed was trying to help to keep it simple. Start with one simple rule and I made a small mistake with the on/off or true/false. That is my mind still saying a Boolean variable is true or false and not on or off.

If it is any better I can refrain from trying to help in the future and just ask questions if I have issues myself.

Again sorry for creating confusion. I have removed my posts

I found it easier to create two automations, one for turning on around sunset, and another for turning off around sunrise (each with an offset.) They have no conditions, just triggers. Keeping it simple makes troubleshooting easier, as well as understanding what I did when I come back to it later.

One of my automations looks like this:

- id: lamp_sunset
  alias: Lamp On Sunset
  trigger:
  - event: sunset
    platform: sun
    offset: -00:15:00
  action:
  - data:
      entity_id:
      - switch.my_smart_plug_name
    service: switch.turn_on
  initial_state: 'false'
  mode: single

Hey, the automation works now! Thank you for your input :slight_smile: Have a great 2021!

1 Like