Need help for automation for automation

Im trying to get automation working and just using basic example from net but it is never triggered so can you guys help me.

- id: '1540229509690'
  alias: kokeilu
  trigger:
platform: sun
event: sunset
offset: 00:45:00
  action:
service: switch.turn_on
entity_id: switch.tahtilamppu

when i press trigger button switch will work but never by self

switch is sonoff basic with latest tasmota

You need to format your code properly, use the blue link at the top of the post. Edit your original post. Do not copy from your original post and paste into a new post. The original formatting from your yaml will be lost if you do.

Should be

service: switch.turn_on # does what it says

or

service: switch.toggle # i.e. swap switch state from off to on, or on to off.

But it should work when sun is setting?

Not the way you currently have it indented (this is why pertro asked you to format it correctly). Also your offset time needs to be in quotes. Like this:

- id: '1540229509690'
  alias: kokeilu
  trigger:
    platform: sun
    event: sunset
    offset: "+00:45:00"
  action:
    service: switch.turn_on
    entity_id: switch.tahtilamppu

This will turn on the switch 45 minutes after sunset.

Doesn’t the time need a plus / minus in it to tell it which way to offset too?

I assumed + was implied by there not being a ‘-’. You could be right.

Only with a negative offset.

EDIT:
Oops you’re right it does need a plus as well :slight_smile:

Code updated. Thanks @anon43302295.

@anon43302295, @tom_l

I can tell you it does not need a plus sign for positive offsets. It doesn’t hurt to add it, but it’s not necessary.

1 Like

Thank you, now it works but dont know how to paste code quote as tom but hopefully i will learn that

like this:

1 Like