I have reviewed and tried many recommendations via the forum and discord channel.
I setup an automation to turn off/on a group of lights at sunrise/sunset. Please see my automation.yaml below:
- id: '1556851964160'
initial_state: true
alias: Turn on outside lights at sunset
trigger:
platform: sun
event: sunset
action:
service: switch.turn_on
entity_id: group.outside_lights
- id: '1556852038870'
initial_state: true
alias: Turn off outside lights at sunrise
trigger:
platform: sun
event: sunrise
action:
service: switch.turn_off
entity_id: group.outside_lights
This was working, although I have fiddled with it to try and get it working so this may not be representative of how it was originally configured. When I attempt to manually trigger it by changing the state of the sun.sun entity. Nothing happens. I see “Sun has risen” and “Sun has set” messages in the logbook but the automation never fires. Is there something I am missing here? TIA
Have you tried homeassistant.turn_on rather than switch.turn_on ? I always try to match the service call to what is being acted on. When a direct match is not available, homeassistant.turn_on can work.
I tried adjusting that. When I click on the event in the logbook I see entries for “Turn on outside light at sunset turned off” and “Turn off outside light at sunrise turned off”. If I click on them (depending on the current state) and click trigger. It works, however when changing the sun.sun entitity state, which I assume should also cause them to trigger, nothing happens.
That automation seems perfectly fine. To troubleshoot you can execute the automation from the frontend. Find the automation on your dashboard, click it then click Execute. If the lights turn on, the problem is with the trigger. If they don’t, the problem is with the action part.
@Emphyrio This is similar to what you suggested, I just went through the logbook entry versus the way you suggested. It looks like the action is fine. It is just not triggering as it should off a change in the sun.sun entity state.
To give a little more clarity on how I am attempting to troubleshoot, I am clicking <> (states) under developer tools in the left hand pane. I then set the entity to sun.sun and state to below_horizon (it is presently day time here) . My understanding is this will trigger sunset, which is reflected in the logbook but the trigger for the automation is never fired.
@petro Thanks for the info, I used this technique because it was suggested in another forum post. Is there a way to test this from end-to-end without waiting for the next sunrise/sunset?
not if you use platform: sun. If you use platform: state and call out the state of sun.sun, that will work. But to be quite honest, what’s the point of testing it? It’s going to work. If it doesn’t work, then your system time is wrong in some way shape or form.