my wife wants to have an automation in Home Assistant, that switches a single light.
The conditions for switching on are:
automation is enabled
I have added a boolean helper:
input_boolean.automation_moodlight_kitchenwindow_activation
the light shall be switched on depending the value of a list:
sundown -2 hours
sundown -1 hour
sundown
sundown +1 hour
sundown + 2 hours
5 PM
6 PM
7 PM
8 PM
9 PM
10 PM
I have added a dropdown helper with the values.
Name of the entity:
input_select.automation_moodlight_kitchenwindow_activation_on
For example:
activation is enabled, 6 PM is selected → kitchenwindow moodllight shall be switched on at 6 PM
Duration shall be selected from another list:
1 hour
2 hours
3 hours
4 hours
5 hours
6 hours
I have added a dropdown helper with the values.
Name of the entity:
input_select.automation_moodlight_kitchenwindow_activation_off
The kitchenwindow moodllight shall be switched off after the selected value.
How do I get this working?
I have set up a card in the right dashboard with a condition:
when input_boolean.automation_moodlight_kitchenwindow_activation is on, the two dropdown list with the conditions are shown.
I have tried to set up an automation, but I dont get it managed.
From what you have described, one way to approach it is to have individual triggers for each of the item from the first list. Set the ID of each trigger to match the values in the Input Select, so a simple template condition can reject non-selected triggers:
I have tried to create an automation, but I got no result that seems to be close to a solution. Thats why I dont had something to show except the card in the dashboard. But I think, that this is uninteresting.
I know, that there are not all triggers inside and the duration is missing. I will add that when the triggers are right. Are they ok?
I dont think so. Automation will switch on the light if ist is 5 PM or if it is sunset -1 hour.
I want to have it it 5 PM when 5 PM is selected from the list.
That is the purpose of the Template condition I posted above… it only allows the actions to be executed if the Trigger ID matches the state of the input… i.e. “5 PM when 5 PM is selected”
Regarding the delay, I would add an action after you turn the light on to set a Timer. Use a second automation that turns the light “off” when the timer finishes (there are examples in the link that show how to use an Event trigger to listen for the timer_finished event).
You are right. I was confusing it. This is my first time with trigger IDs.
With your help, I got the automation for switching on working.
Switching off is missing now.
Do I have to add 6 automations:
If trigger ID is “1 hour” then set duration to 1 hour
If triffer ID is “two hours” then set duration to 2 hours
The switching on automation doesnt work correctly.
It switches on at 4 PM, 5 PM, 6 PM, 7 PM, 8 PM 9 PM, 10 PM, 2 hours before sunset, 1 hour before sunset, at sunset, 1 hour after sunset and 2 hours after sunset.
I havent worked with the triggers so I cannot judge, if it is the right way.
I want the light to switch on at the time that is set in the dropdown and not at every time that is possible to choose from the dropdown.
Do the trigger IDs you have assigned exactly match the options available in the Input Select? For example 5PM is not the same as 5 PM and sundown -1 hour is not the same as Sundown -1 Hour… make sure they match.
No.
Don’t use delays, they don’t survive restart or reloading automations… use a Timer. I would also avoid using toggle unless that the actual action you want to happen every time. What if someone turned the light off manually at some point during the 6 hour delay? Do you really want it to turn on?
switched on by automation
automation_moodlight_kitchenwindow_activation sunset with offset
15:10:42 - 3 hours ago
Sundown was at 17.11.
That means, that the automation was activated by this part of the automation:
- id: 2 hours before sundown
trigger: sun
event: sunset
offset: "-02:00:00"
The helper is called “2 hours before sundown”.
Does the sequence matter?
In the automation, it is
4 PM
5 PM
6 PM
7 PM
8 PM
9 PM
10 PM
2 hours before sundown
1 hour before sundown
sundown
1 hour after sundown
2 hours after sundown
In the helper list, it is:
2 hours before sundown
1 hour before sundown
sundown
1 hour after sundown
2 hours after sundown
4 PM
5 PM
6 PM
7 PM
8 PM
9 PM
10 PM
When switching on works correclty, I will look for switching of like you said.