Aeotec by Aeon Labs ZW096 Smart Switch, Small, White
Hi All,
I want to create a simple automation where an Aeon Labs ZW096 Smart Switch is turned on when the sunsets and turned off 5 hours later.
How I accomplish this is still a bit fuzzy in my mind despite the examples that have been provided here.
What I have come up with is:
automation:
alias: "Christmas lights turn on at sunset and turn off five hours later."
trigger:
platform: sun
event: sunset
action:
service:
entity_id:
I am not clear on the following:
How do I determine the service to use?
How do I determine the entity_id to use? There is an old entity_id and new entity_id when I look at the switch in the HA frontend.
How do I add the command to turn off the light switch five hours after it came on?
This is my first attempt at writing an automation. I appreciate any suggestions to help me get started in this area!
The service is related to the device you are turning on. For a switch it’s switch.turn_on for a light it is light.turn_on. homeassistant.turn_on works for a lot of devices also.
I would use the new entity id
Two options. Add a delay after the first action and the turn the light off. Second option is just a separate automation to turn off the switch at a set time.
I’m pretty sure with the delay option if you restart HA or there was a power outage the switch would not turn off after 5 hours as all the automations get reset. Just as a heads up.
See below for the delay syntax. About half way down the page.
Use a service for the domain the entity is in. In this case, switch, so you’ll want switch.turn_on. To see all of the services for a domain, in the lower left corner on the front end under developer tools select services. On that page, you’ll be able to select a domain and see all of its services (e.g. turn_on, turn_on, toggle). The documentation pages are in general very helpful, but the page for switch is a bit different. For some good examples take a look at the page for light, which is a bit more thorough. Switch behaves similar to light, but just with less options. https://home-assistant.io/components/light/
Almost certainly use the new one. The new and old is a hangover from an old breaking change. This depends on what version you’re running. If it’s anything remotely recent it uses the new one.
I don’t think I wrote the YAML correctly since the YAML Lint is highlighting “action” as it is used twice. Below is what I came up with based on your feedback:
automation:
alias: "Christmas lights turn on at sunset and turn off five hours later."
trigger:
platform: sun
event: sunset
action:
service: switch.turn_on
entity_id: sensor.aeotec_zw096_smart_switch_6_power
delay: 05:00:00
action:
service: switch.turn_off
entity_id: sensor.aeotec_zw096_smart_switch_6_power
Edit: Actually, I think there’s more wrong than just that. I don’t have the device so I can’t confirm, but I’d wager this might work. Note that I changed the entity id (the name, not just the “switch.” part).
If you’re going to have multiple actions in an automation, you need to use the list format with “-” as shown in the automation 2 example on this page.
But, I recommend making this two separate automatons, with the second one triggering on sunset but with a five hour offset.