#how to turn light on at sunset and off at sunrise with a single automation

1 messages · Page 1 of 1 (latest)

mortal river
#

.

timber pilot
#

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:

mortal river
#

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

timber pilot
#

yeah - you will need to put your own devices in there. Delete that bit and do it from the interface if it's easier

mortal river
#

any idea what's wrong with the syntax? it's still giving the error with the correct device id

faint crystal
#

If you're using a device action you likely need domain: light

mortal river
#

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?

timber pilot
#

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

sly lance
mortal river
#

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

nimble shore
#

yeah, in the gui you have to open the dotsvertical menu and select "Edit ID" to see the ID field

mortal river
#

okay I managed to input it through the gui, thanks

mortal river
#

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

sly lance
#

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

mortal river
#

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
sly lance
#

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