Yes, thats included as well as the lat/lon for my location. I just changed the sun condition to a luminance (which I get from the same sensor) condition. That seemed to work.
I will try the offset as you suggested. Who knows. maybe other factors prevented the light from coming on last night
Sorry for being a thread necromancer, but I figured out a solution for HASS 0.44.1 and wanted to post it here in case anyone else was wondering in the future:
I got an automation working for my own purposes with the following OR statement:
# Turn on porch light when I arrive if it's dark outside
- alias: 'Lit porch on arrival'
trigger:
- platform: state
entity_id: device_tracker.xxxxxxxxxxxxx
state: 'home'
condition:
#You can test your automations before and after sunrise by setting your lat/long under "homeassistant:" for an area that is about to have sunrise or sunset (civil twilight). Go to https://in-the-sky.org to learn of an area about to undergo civil twilight, place a marker on the map at this link ( https://in-the-sky.org/location.php? ), then read the lat/long coordinates. Add the coordinates to homeassitant: , then restart HomeAssistant. Clicking on the Sun badge in HomeAssistant will tell you how long until "sunrise" or "sunset." Test your automations now.
#OR statement looks strange but is correct https://home-assistant.io/docs/scripts/conditions/#or-condition
#Using "before: sunset" and "after: sunrise" causes light to come on when arriving during the day.
#"after_offset:" appears to have to be used with "after:" and "before_offset:" appears to have to be used with "before:" since the trigger doesn't fire correctly using "after: ... before_offset: ..." or "before: ... after_offset: ..." in my experience. Positive or negative offset values only seem to matter on the after_offset (but produce the same outcomes for the before_offset).
condition: or
conditions:
#Condition beginning 30 min before sunset (and including after sunset): https://home-assistant.io/docs/scripts/conditions/#sun-condition
- condition: sun
after: sunset
after_offset: "-0:30:00"
#Condition ending 30 min after sunrise (and including before sunrise)
- condition: sun
before: sunrise
before_offset: "-0:30:00"
action:
service: switch.turn_on
entity_id: switch.porch_light
Edits: I attempted to fine-tune this condition, but ended up using the code I posted originally anyway. I have, however, annotated the things I learned about the sun condition in the code’s comments.
Bonus info about testing automations / simulating sunrise/sunset:
Add those coordinates to your configration.yaml 's homeassitant: area, then restart HomeAssistant (Developer Tools > Services > homeassistant , restart > Call Service).
Clicking on the Sun badge in HomeAssistant will tell you how long until the next “sunrise” or “sunset.”
Pretend to be “home” or “not_home” by setting those states for your device tracker (Developer Tools > States > device_tracker.###### > Set State). HASS detects the change in state, so simulate coming home by switching “home” to “not_home”, then switch back to “home”.
- alias: Turn ON Dany's lamp when movement
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d00015a8786
to: 'on'
condition:
condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
service: homeassistant.turn_on
entity_id: switch.dannys_night_light__jackson1
- alias: Turn OFF Dany's lamp after last movement
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d00015a8786
to: 'off'
for:
minutes: 15
action:
service: homeassistant.turn_off
entity_id: switch.dannys_night_light__jackson1
This works perfectly. There seems to be a bug when using the built in automation editor when selecting (after sunset and before sunrise at the same time) I’m guessing that it’s using an AND to check between sunset and sunrise rather than an OR
Im trying to get my lights to turn on at sunset and turn off at sunrise.
But the turn on condition i would like to get it to work with the hue motion/light sensor (lux). Is this going to work?
I think you’re missing a few lines in there, two automations have merged into one? And you might want to check some other examples from the forum as you seem to have indentations wrong. These are vitally important in YAML (eg the conditions in your example).
Take a look at my example below:
- alias: "Switch on kitchen lights at sunset if somone is home"
trigger:
- platform: sun
event: sunset
offset: "-00:30:00"
condition:
condition: and
conditions:
- condition: state #if smart lighting automations are enabled via the frontend
entity_id: input_boolean.smart_lighting
state: 'on'
- condition: state #if someone is actually home
entity_id: group.all_devices
state: 'home'
action:
- entity_id: light.piano_lamp
service: homeassistant.turn_on
- entity_id: light.kitchen_corner
service: homeassistant.turn_on
I include it more for my own benefit… I’m often checking my own work months later to figure out why a complex automation is doing something the way it is and this helps me out