I have several automations in my automations.yaml file, which all work fine. I have added an automation to switch on some lights in a small random window of time before sunset, and switch them off during a larger random window of time later in the evening, hoping this will fool possible criminals while I am away on holiday.
I have reloaded automations, I have rebooted, but the new automation does not load (is not at all visible in the frontend, not at configuration>automations, not at developer tools tools>states, all other automations are visible. I searched the web, this forum and more and do not know anymore. Your help is much appreciated.
The automation:
Thanks for the help. I did use āconfiguration checkā but that gave no errors. When I add the hyphens like you suggested, āconfiguration checkā gives this error:
Error loading /config/configuration.yaml: while scanning for the next token
found character ā%ā that cannot start any token
in ā/config/automations.yamlā, line 93, column 8
Line 93 is the line with {% if trigger.platform == āsunā %}.
BTW, your advise is spot on: as a relative HA newbie, I think I know now when to indent, but when to use a hyphen is stil a kind of mistery to me (it seems there is a lot of variation in online examples?).
No, that was a lost ā0ā, from a previous version of the automation. I solved the ācheck configurationā error by also adding an hyphen before entity_id: group.holiday_lights, and with an extra indent step for the if ā¦ endif block, which I forgot. So the ācheck configurationā error is gone, but the automation still does not load ā¦
Thanx! I can see the automation now. First I removed the () and int from the range function, but that did not seem to help, then I copied your final suggestion with all the compacted code (I did not know you can do that to code!), and now I can see the automation. Letās see if this works this evening!
Came here to say the same thing. Itās a clever workaround for the inability of templating the offset option.
Also came here to streamline the template but Petro already took care of that (plus I didnāt think of using the inline ifwithin the range function; I had intended to use a variable).
After you tested and confirmed it works, be sure to mark the post with the Solution tag. This will automatically place a check-mark next to the topicās title which signals to others that this topic has an accepted solution. It will also place a link beneath your first post that leads to the Solution post. All of this helps other users find answers to similar questions.
Yesterday I confirmed the automation loaded and was visible in HA, last evening it all worked perfectly as expected. Here is the final version of the automation, for reference purposes:
- id: '00007'
alias: holiday lights
trigger:
- platform: sun
event: sunset
offset: '-00:30:00'
- platform: time
at: '23:55:00'
condition:
condition: state
entity_id: input_select.home_or_away
state: 'holiday'
action:
- delay:
minutes: "{{ range(1, 25 if trigger.platform == 'sun' else 120) | random }}"
- service_template: "homeassistant.turn_{{ 'on' if trigger.platform == 'sun' else 'off' }}"
entity_id: group.holiday_lights