#how to turn light on at sunset and off at sunrise with a single automation
1 messages · Page 1 of 1 (latest)
You can set two triggers (sunrise & sunset) and allocate IDs to them (lookup trigger ids).
Then use the Choose action with conditions 'triggered by' the ids
Something like this:
triggers:
- trigger: sun
event: sunrise
offset: 0
id: sunrise
- trigger: sun
event: sunset
offset: 0
id: sunset
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- sunrise
sequence:
- type: turn_off
device_id: xxxx
- conditions:
- condition: trigger
id:
- sunset
sequence:
- type: turn_on
device_id: xxxx
Or in the UI:
thank you for writing out that template for me, I will likely end up using it
hmm is it possible an incorrect device_id could cause this error message?
hmm no the device id is correct
yeah - you will need to put your own devices in there. Delete that bit and do it from the interface if it's easier
any idea what's wrong with the syntax? it's still giving the error with the correct device id
If you're using a device action you likely need domain: light
it's actually a smart outlet, do I put switch?
Message malformed: Unknown device 'switch.xmas_lights_switch'
are there any docs with examples to follow for this?
sorry, my bad. I removed the domain: line from the config to try and keep it short.
Yes, likely to also need "domain: switch"
If you still haven't got it working, try doing it from the user interface rather than yaml. It will do most of the config for you
Device triggers, device conditions, and device actions are intended to be created through the UI. If you want to manipulate the YAML then you should be using the other options. In your case, the action switch.turn_on
ah interesting
i always prefer code to GUIs when possible
but I'm ready to attempt this with the gui
what is the trigger menu button?
oh I see - triggers don't have IDs by default
yeah, in the gui you have to open the
menu and select "Edit ID" to see the ID field
okay I managed to input it through the gui, thanks
I guess my issue was I was trying to set device_id to a human-readable name and it only accepts a hex string
i wonder if there's a reason why that lookup can't happen automatically
I think you’re confusing entity_id with device_id
You can use the UI to choose switch.turn_on and use the UI to also select the entity
There’s really no need to use device_id for anything, ever
oh
what's the difference between
sequence:
- action: switch.turn_off
target:
device_id: 634a01cf778e0c67ea93b927cff7ba10
versus
sequence:
- action: switch.turn_off
target:
entity_id: switch.my_switch
The one with entity_id is human-readable, and if you change your device later, you can keep the same entity_id. In other words, using device_id has drawbacks and no benefits