Syntax in sun event trigger?

Hi guys,
While teaching myself to setup automations via examples here and elsewhere I noticed in the offset: part of sun triggers that sometimes authors used " " around the trigger offset time, and sometimes used ’ ', and other times nothing at all. Which is the correct way " or ’ or nothing ?

platform: sun
event: sunset
offset: “-00:45:00”

The correct way is the way that works :smiley:

Quotes are generally needed when enclosing spaces, or other characters that might be misinterpreted by the underlying software. In general they don’t do any harm, so people add them anyway. AFAIK, there is no difference between ’ and " in yaml.

However, there are some cases where enclosing in quotes actually means something different. For instance, in a json paylaod true is a boolean but “true” is a string.

Right OK thanks.
My automation to set a mqtt switch via event sunset is not working at all in either case, so my trouble is something else now I guess…

You have probably seen the sun trigger documentation.

I can’t tell if your code matches exactly as you haven’t enclosed it in “```” to indent it correctly, but it could also be that the command is wrong.

Hey if I might bug you for another tip, can you tell me if I need to restart HA when I add or modify an automation ?
I’ve now tried to get a an event: time to work on a working switch (i.e. that works fine via the HA GUI switch) and it’s not working either. I’m missing something fundamental I think and I can’t see it.
(PS. My HA is on Raspberry Pi).

Re sun trigger documentation, yes I’ve studied it as well as other examples. Actually I’m using the Automation GUI in HA and then checking what it’s done in the automation.yaml.

I’m afraid you do. That’s one of the main reasons I switched to using Appdaemon for my automations. But you need to learn some Python for that, so it might not be suitable for you.

I have never used the automation gui, so I can’t help there.

If you post what you have, and a description of what doesn’t work, someone here will certainly have some idea.

This is what the GUI builds in automations.yaml below, for my testing…
I’ll restart now though, that’s probably what is wrong, I must have missed that instruction someplace.
The syntax seems a bit backwards to my inexperienced eyes, with stuff like platform listed last…

  • action:
    • data:
      entity_id: switch.sonoff_switch2
      service: switch.turn_on
      alias: Xmas lights on Switch2
      condition: []
      id: ‘1512654474153’
    • event: sunset
      offset: 03:00:00
      platform: sun
  • action:
    • data:
      entity_id: switch.sonoff_switch1
      service: script.turn_on
      alias: Test Switch1
      condition: []
      id: ‘1512733207204’
    • at: ‘22:25:00’
      platform: time