Automation.yaml not working help required

Fairly new to all of this but have a lot figured out, however, I am scratching my head over an automation I have made.
Basically I want to turn on a switch at a given time and run for xx minutes then switch off.
I have a spa_pool_automation.yaml file in the Automations folder and have configuration.yaml with
automation: !include automations.yaml

The spa_pool_automation.yaml file consists of the following

- alias: Set Spa Pool Automation
  id: spa_pool_timer
  trigger:
  - platform: time
    at: '10:30:00'
  action:
  - service: switch.turn_on
    entity_id: switch.ty45043874840d8e46cd8c
  - delay: 4:00:00
  - service: switch.turn_off
    entity_id: switch.ty45043874840d8e46cd8c

I have cleared my cache and restarted Home Assistant
Can anyone tell me what I am missing please?

In your configuration.yaml-

automation: !include automations.yaml
automation split: !include_dir_list automations

In your spa_pool_automation.yaml inside automations folder, change the format to-

alias: Set Spa Pool Automation
id: 757382747382772
trigger:
  - platform: time
    at: '10:30:00'
    id: 'on'
  - platform: time
    at: '14:30:00'
    id: 'off'
action:
  - service: >-
      switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.ty45043874840d8e46cd8c

OR

alias: Set Spa Pool Automation
id: 64827472828
trigger:
  - platform: time
    at:
      - '10:30'
      - '14:30'
  - platform: homeassistant
    event: start
action:
  - service: >-
      switch.turn_{{'on' if (10,30) <= (now().hour,now().minute) < (14,30) else 'off'}}
    target:
      entity_id: switch.ty45043874840d8e46cd8c

See here for more info-

Hi ardysusilo, thanks for the input.
Have tried all of that and set it to start in 10 minutes after I rebooted HA.
Didnt trigger the switch at the time though?
The only thing I can think of is the {{trigger id}}, am i supposed to change that to something.

Appreciate your help.

What did you see from the debug trace?

Thanks once again.
I have no automation showing up in the configuration- automations, is this due to being created in yaml?
Read through your link and cant figure out how to access a log to see what is happening?
Feeling dumb!

  1. What did you put inside configuration.yaml?
  2. What is the name of the automations folder?
  3. Copy again the content of your spa_pool_automation.yaml

Hi ardysusilo
In configurations.yaml i have

automation: !include automations.yaml
automation split: !include_dir_list automation

Automations folder is named automations and the files are in that folder.

Content in the file spa_pool_automation.yaml is

alias: Set Spa Pool Automation
id: spa_pool_timer
trigger:
  - platform: time
    at: '11:59:00'
    id: 'on'
  - platform: time
    at: '14:30:00'
    id: 'off'
action: 
  - service: >-
      switch.turn_{{ trigger.id }}
    target:
      entity_id: switch.ty45043874840d8e46cd8c

You are missing a s in the automations. It should be-
automation split: !include_dir_list automations

After that, restart HA.

Lastly, you might want to check the alternative YAML that I posted above. The last alternative can survive HA restart/crashes should it happen during 10:30 OR 14:30.

mine is set up basically like yours (‘automations’ folder and all my yaml automations contained in it) and I use “!include_dir_merge_list” and you might need a ‘/’ at the end of your directory name. all of my !include directories do but I’m not 100% sure it’ necessary.

so…

automation split: !include_dir_merge_list automations/

OK, so done all that

automation: !include automations.yaml
automation split: !include_dir_list automations

and in spa_pool_automation.yaml

alias: Set Spa Pool Automation
id: 64827472828
trigger:
  - platform: time
    at:
      - '10:30'
      - '14:30'
  - platform: homeassistant
    event: start
action:
  - service: >-
      switch.turn_{{'on' if (10,30) <= (now().hour,now().minute) < (14,30) else 'off'}}
    target:
      entity_id: switch.ty45043874840d8e46cd8c

Now I get a notification
The following integrations and platforms could not be set up:

  • automation
    Looking in the log I have

Logger: homeassistant.config
Source: config.py:464
First occurred: 7:53:42 (2 occurrences)
Last logged: 7:58:12

Invalid config for [automation]: expected str for dictionary value @ data[‘id’]. Got None. (See /config/configuration.yaml, line 3).

Setup of automation is taking over 10 seconds.

Try removing the id line first to check-

alias: 'Set Spa Pool Automation'

trigger:
  - platform: time
    at:
      - '10:30'
      - '14:30'
  - platform: homeassistant
    event: start

action:
  - service: >-
      switch.turn_{{'on' if (10,30) <= (now().hour,now().minute) < (14,30) else 'off'}}
    target:
      entity_id: switch.ty45043874840d8e46cd8c

If it works, try adding the id again like this-
id: '748292747282'

That worked, great stuff ardysusilo!

Now it is working but not turning the switch on?
Have screen shot the details from the automation area if someone could please help.
So close to getting this sorted.

Hmm. That’s weird because the specified time in the trigger is '10:30' and '14:30'. But from your log, it is triggered at '00:30'. As it is outside the time range, the automation is sending switch.turn_off command.

Actually, think it might be fixed now, just found the time zone was incorrect, have fixed that and tested on another date and its working.
Thanks for all the help.

Excellent! You can consider closing the thread by marking my post above as solution.

Sorry, one more thing. If it is going to be a time in the morning say 8am till 9am would that be written 08:00 or 8:00, so

switch.turn_{{'on' if (08,00) <= (now().hour,now().minute) < (09,00) else 'off'}}

Try pasting this in Developer Tools → Template, when it is 8 AM in the morning-
{{ (now().hour,now().minute) }}
The code that you put in your automation must match the result from Developer Tools → Template

If you dont need the minutes, you can just use-
switch.turn_{{'on' if 8 <= now().hour < 9 else 'off'}}

OK, got it.
Thanks for your fast replies mate and all the best…
I will close this now.