Hi everyone, I’ve been experimenting with automations in Home Assistant and stumbled upon an interesting challenge. I wanted to create a dynamic sunset trigger where the offset time could be adjusted via input_number entities. This would allow me to fine-tune the automation based on seasonal changes or specific needs without manually editing the configuration each time.
I started by referencing the official documentation, which provided a great starting point for using input_number entities in automations. However, when I tried to implement a similar approach with a sunset trigger, I encountered an error related to the offset format. The error message indicated that the offset needed to be in a specific time format, which my initial setup wasn’t adhering to.
After some trial and error, I realized the issue was with how the offset was being constructed. I needed to ensure that the input values were properly formatted into a valid time string. I decided to use a template to dynamically generate the offset based on the input_number values. Here’s the solution I came up with:
yaml
alias: Sunset Light Automation
trigger:
- platform: sun
event: sunset
offset: “{{ states(‘input_number.sunset_offset_hours’) | int }}:{{ states(‘input_number.sunset_offset_minutes’) | int }}:{{ states(‘input_number.sunset_offset_seconds’) | int }}”
condition:
action: - service: light.turn_on
target:
entity_id: light.living_room
This setup allows me to adjust the sunset trigger offset in hours, minutes, and seconds using separate input_number entities. It’s incredibly flexible and eliminates the need for manual configuration changes. I’m really happy with how this turned out and it’s been working perfectly in my setup!
If anyone has any questions or suggestions for improvement, I’d be happy to discuss further. It’s amazing how the community resources and documentation can help solve even the trickiest problems. Thanks to everyone who contributes to making Home Assistant so versatile and user-friendly!