Hey everyone, I wanted to share my experience setting up a sunset automation in Home Assistant. At first, I was a bit confused because I thought it would be straightforward, but there were a few bumps along the way. Let me walk you through how I made it work!
So, I started by using the Home Assistant UI to create a simple automation that would turn on a TP-Link smart plug at sunset. The YAML code looked correct, but nothing happened when the sun set. I was a bit frustrated because replacing the sunset trigger with a specific time worked perfectly, but the sunset trigger itself didn’t seem to register.
After some research, I realized that the issue might be related to how the Sun entity works in Home Assistant. I checked the logs and noticed that the Sun entity was correctly calculating sunrise and sunset times, so that wasn’t the problem. I also verified that the TP-Link plug was working properly with other automations.
The breakthrough came when I stumbled upon a forum post suggesting that the sunset trigger might need a small offset to work reliably. I added an offset of 1 minute to the trigger, and voilà! It worked like a charm. I was so happy that I decided to share my automation setup with the community in case others were struggling with the same issue.
Here’s the YAML code that finally worked for me:
yaml
alias: Sunset Automation
trigger:
- platform: sun
event: sunset
offset: ‘00:01:00’
condition:
action: - service: switch.turn_on
data:
entity_id: switch.tp_link_smart_plug_1331
I hope this helps someone else who’s trying to set up a sunset automation. It’s amazing how a small tweak can make everything work perfectly! If anyone has tips or tricks for optimizing automations, I’d love to hear them. Happy automating! ![]()
![]()