Automation not working with script

Hi there,

I’m trying to rebuild my Home Assistant from a very old version to the newest one. So there are like codes that don’t really work and I’m trying to redo and fix those things.

At the moment, I have entities in groups.yaml, scripts.yaml, and automations.yaml. I have lights configured to turn on minutes before sunset, but somehow the automation is not triggering the scripts. I tested the scripts, and they seem to work ok (but please double check if there are any changes I need to do).

Here are my current codes for the automations.yaml:

#automation:

#Turn on the Home Lights at sunset.
- alias: "Home Lights Automation"
  description: "Turn on all lights. Triggers home_lights_script."
  trigger:
    platform: sun
    event: sunset
    offset: '-00:05:00'
  action:
    data:
      entity_id: home_lights_script
    service: script.turn_on

#Dim and eventually turn off lights.
#Front Home Lights
- alias: "Dim Front Home Lights"
  description: "Gradually dims light as the night goes, then eventually turn off lights. Triggers dim_front_home_lights_script."
  trigger:
    platform: time
    at: '00:00'
  condition:
    condition: state
    state: 'on'
    entity_id: group.front_home_lights
  action:
    data:
      entity_id: script.dim_front_home_lights_script
    service: script.turn_on

#Living Room Lights
- alias: "Dim Living Room Lights"
  description: "Gradually dims light as the night goes, then eventually turn off lights. Triggers dim_front_home_lights_script."
  trigger:
    platform: time
    at: '00:00'
  condition:
    condition: state
    state: 'on'
    entity_id: group.living_room_lights
  action:
    data:
      entity_id: script.dim_living_room_lights_script
    service: script.turn_on

#Bedroom Lights
- alias: "Dim Bedroom Lights"
  description: "Gradually dims light as the night goes, then eventually turn off lights. Triggers dim_front_home_lights_script."
  trigger:
    platform: time
    at: '22:00'
  condition:
    condition: state
    state: 'on'
    entity_id: group.bedroom_lights
  action:
    data:
      entity_id: script.dim_bedroom_lights_script
    service: script.turn_on

#Upstairs Lights
- alias: "Dim Upstairs Lights"
  description: "Gradually dims light as the night goes, then eventually turn off lights. Triggers dim_front_home_lights_script."
  trigger:
    platform: sun
    event: sunrise
    offset: '-01:00:00'
  condition:
    condition: state
    state: 'on'
    entity_id: group.upstairs_lights
  action:
    data:
      entity_id: script.dim_upstairs_lights_script
    service: script.turn_on

This is the scripst.yaml:

#Turn on all lights.
home_lights_script:
  alias: Home Lights Script
  description: "Turn on all lights 30 minutes before sunset."
  mode: single
  sequence:
    - service: light.turn_on
      data:
        entity_id: group.entryway_lights
        transition: '3600'
        kelvin: '2700'
        brightness_pct: '65'
    - service: light.turn_on
      data:
        entity_id: group.balcony_lights
        transition: '3600'
        kelvin: '3000'
        brightness_pct: '75'
    - service: light.turn_on
      data:
        entity_id: group.living_room_lights
        transition: '1800'
        kelvin: '2800'
        brightness_pct: '65'
    - service: light.turn_on
      data:
        entity_id: group.bedroom_lights
        transition: '3600'
        kelvin: '3500'
        brightness_pct: '75'
    - service: light.turn_on
      data:
        entity_id: group.upstairs_lights
        transition: '3600'
        kelvin: '2500'
        brightness_pct: '75'


#Gradually dim lights, then turn off.
dim_front_home_lights_script:
  alias: Dim Front Home Lights Script
  description: "Gradually dims light as the night goes, then eventually turn off lights."
  mode: single
  sequence:
  - service: light.turn_on
    data:
      entity_id: group.front_home_lights
      transition: '3600'
      kelvin: '2700'
      brightness_pct: '25'
  - delay: '01:30:00'
  - service: light.turn_on
    data:
      entity_id: group.front_home_lights
      transition: '1800'
      brightness_pct: '10'
  - delay: '01:00:00'
  - service: light.turn_off
    data:
      entity_id: group.living_room_lights

dim_living_room_lights_script:
  alias: Dim Living Room Lights Script
  description: "Gradually dims light as the night goes, then eventually turn off lights."
  mode: single
  sequence:
  - service: light.turn_on
    data:
      entity_id: group.living_room_lights
      transition: '3600'
      kelvin: '2700'
      brightness_pct: '25'
  - delay: '02:00:00'
  - service: light.turn_on
    data:
      entity_id: group.living_room_lights
      transition: '3600'
      brightness_pct: '15'
  - delay: '01:25:00'
  - service: light.turn_on
    data:
      entity_id: group.living_room_lights
      transition: '1800'
      brightness_pct: '5'
  - delay: '00:35:00'
  - service: light.turn_off
    data:
      entity_id: group.living_room_lights

dim_bedroom_lights_script:
  alias: Dim Bedroom Lights Script
  description: "Gradually dims light as the night goes, then eventually turn off lights."
  mode: single
  sequence:
  - service: light.turn_on
    data:
      entity_id: group.bedroom_lights
      transition: '1800'
      kelvin: '2700'
      brightness_pct: '10'
  - delay: '00:35:00'
  - service: light.turn_on
    data:
      entity_id: group.bedroom_lights
      transition: '900'
      brightness_pct: '5'
  - delay: '00:25:00'
  - service: light.turn_off
    data:
      entity_id: group.bedroom_lights

dim_upstairs_lights_script:
  alias: Dim Upstairs Lights Script
  description: "Gradually dims light as the night goes, then eventually turn off lights."
  mode: single
  sequence:
  - service: light.turn_on
    data:
      entity_id: group.upstairs_lights
      transition: '1800'
      kelvin: '2700'
      brightness_pct: '10'
  - delay: '00:35:00'
  - service: light.turn_on
    data:
      entity_id: group.upstairs_lights
      transition: '900'
      brightness_pct: '5'
  - delay: '00:25:00'
  - service: light.turn_off
    data:
      entity_id: group.upstairs_lights

and also the groups.yaml:

#group:
  balcony_lights:
    name: Balcony Lights
    entities:
      - light.balcony_right_light
      - light.balcony_left_light
  entryway_lights:
    name: Entryway Lights
    entities:
      - light.front_door_light
  living_room_lights:
    name: Living Room Lights
    entities:
      - light.orb_light
  bedroom_lights:
    name: Bedroom Lights
    entities:
      - light.bedroom_light
  upstairs_lights:
    name: Upstairs Lights
    entities:
      - light.god_light

Thanks in advanced.

  action:
    data:
      entity_id: home_lights_script # <- should be script.home_lights_script
    service: script.turn_on
1 Like

I honestly, stupidly, completely missed that part when copy pasting.

Anyway, I also changed the codes as:

#Turn on the Home Lights at sunset.
- alias: "Home Lights Automation"
  description: "Turn on all lights. Triggers home_lights_script."
  trigger:
  - platform: sun
    event: sunset
    offset: '-00:30:00'
  condition: []
  action:
  - service: script.home_lights_script
    data: {}
  mode: single

Thanks for the quick fix!