Automations.yaml prevents HAss restarting

Weird issue, with my automations.yaml file in place and with rules, when i restart HAss (systemctl restart hass), the system doesn’t restart, the log file has a message in there about automations is taking more than 10 seconds to set up but it never completes.

Having a blank file and then starting the system, it all works, i can then copy the blank file to a backup file and restore my original file with the detail in it, reload automations from the config menu and it all loads fine and works perfectly.

Any ideas?

sounds like one of your automations is not working correctly.
Can you post your automations here?

So this is the yaml file, i have tried commenting out each item in turn and no difference, hass does not get to a running state with text in this file, BTW this is an included file, as per the general setup instructions suggests.

The yaml checker is all happy with it, i did find an extra - in the final automation action entity_id but everything was firing off ok, i removed it and still have the same issue.

- id: '1'
  alias: Turn on sensor when sun sets
  trigger:
    platform: sun
    event: sunset
  action:
    service: switch.turn_on
    entity_id: switch.hall_sensor_light
- id: '2'
  alias: Turn off sensor when sun rises
  trigger:
    platform: sun
    event: sunrise
  action:
    service: switch.turn_off
    entity_id: switch.hall_sensor_light

- id: '3'
  alias: Turn on the tree lights at sunset
  trigger:
    platform: sun
    event: sunset
  action:
    service: switch.turn_on
    entity_id: switch.dining_outlet_1
- id: '4'
  alias: Turn off the tree lights at midnight
  trigger:
    platform: time
    at: 00:00:00
  action:
    service: switch.turn_off
    entity_id: switch.dining_outlet_1

- id: '5'
  alias: Turn on the front Xmas lights at sunset
  trigger:
    platform: sun
    event: sunset
  action:
    service: switch.turn_on
    entity_id: switch.front_xmas_lights
- id: '6'
  alias: Turn off the front Xmas lights at midnight
  trigger:
    platform: time
    at: 00:00:00
  action:
    entity_id: switch.front_xmas_lights
    service: switch.turn_off

- id: '7'
  alias: Turn on all cameras when alarm is armed
  trigger:
    platform: state
    entity_id: switch.alarm_state
    from: 'off'
    to: 'on'
  action:
    service: switch.turn_on
    entity_id: group.cctv_switches
- id: '8'
  alias: Turn off all cameras when alarm is disarmed
  trigger:
    platform: state
    entity_id: switch.alarm_state
    from: 'on'
    to: 'off'
  action:
    service: switch.turn_off
    entity_id: group.cctv_switches

@Radebe2k

I think you have your single quote marks in the wrong place.

try:

- id: 1
  alias: 'example'
  etc....

I think you need to put your time in single brackets in your triggers:

trigger:
    platform: time
    at: '00:00:00'

ok so taking the ’ from the ID threw errors all over the place, the two other sets for the alias and time make no difference

- id: '4'
  alias: 'Turn off the tree lights at midnight'
  trigger:
    platform: time
    at: '00:00:00'
  action:
    service: switch.turn_off
    entity_id: switch.dining_outlet_1

What do you see when you use 'systemctl status hass -l ’ after the restart command?

I normally get a hint in which line of my confg files the error is.

This is what I had to do to make my automations work properly.

No joy there, i just re-created the file entirely to rule out nay weird non printing characters but i’ve only used VI to edit them so that shouldn’t be an issue, my tiles are in single quotes now but the issue remains, the systemctl command above only shows errors with sensor values and this is to do with the calculation of a power cost per day as it hasn’t received and update from mqtt for what the daily consumption has been (Sonoff POW with Tasmota firmware).

No hint of any issues with the automation file, i have changed the mode to 777 and checked the owner and that all matches up but still no change, like i said if i load a blank file to start with and then copy the one with rules in it over the top once the system is running and reload the automation subsystem then all the rules work and the yaml checker doesn’t complain.

What happens if you take the lines out of ID 7 and 8 that start with ‘from’.

I think the syntax there changed a few versions ago.

I see where you are coming from but the issue was there before i put those lines in, plus i wanted to ensure that the on and off states were matched between the cameras being activated and the state of the alarm system.

The to and from conditions are still valid, just optional and need to be in single quotes to avoid them being interpreted as boolean values according the the published docco.

State Triggers

Your yaml validates so it’s not an issue with spacing or yaml formatting. When you launch HA with your automation file in place and HA fails to load, it will create a homeassistant.log. the last few lines will point to what it is getting hung up on and even tell you the line of the file it doesn’t like. if for some reason it is just telling you it doesn’t like your automations file and doesn’t provide specifics, you will need to go one by one and restart HA with one automation added at a time. do this until you find the automation (or automations) that doesn’t allow HA to launch. My guess is you are trying to use a component, entity, etc that doesn’t exist in your states tab of HA or there’s a spelling error and it’s getting hung up on that.

I’m not actually that confident in the configuration validator.

I’ve had HA hang up on mistakes in my config files and the config check said it was “Valid!”.

It has caught mistakes that I’ve made but it has also not caught them as well.

I’ve had that happen too. The validator mostly catches YAML errors and that’s about it. I’ve had the occasional spelling error slip past it and still report “Valid!” I use an external YAML Lint to validate before I reload in HA. I threw the config posted above into it and it spit out valid syntax at least.

I have mine as setup by the front end graphical editor. It looks a little different.

Here is one of mine for the sunset with an offset. Might help.

- action:
  - data:
      brightness_pct: 75
      effect: white
      entity_id: light.lounge
    service: light.turn_on
  alias: Turn Lounge Light On 1:50 before Sunset
  condition: []
  id: '1505977024303'
  trigger:
  - entity_id: light.lounge
    from: 'off'
    platform: state
    to: 'on'
  - event: sunset
    offset: -01:50:00
    platform: sun

Weirdly i’ve switched to a Pi and just straight copied the config files over and it all works, every time.