Simple light on / light off not working :(

I have a really simple config to turn a light on and off at certain times of the day. I want to add more lights later, at the moment I have just one. My config:

# cat /home/homeassistant/.homeassistant/automations.yaml 
- id: lights1
  alias: lights on at dawn
  trigger:
  - at: 06:40
    platform: time
  condition: []
  action:
  - data: {}
    entity_id: lightsgroup.living_room_lights
    service: living_room_lights.turn_on
- id: lights2
  alias: lights off before work
  trigger:
  - at: 08:30:00
    platform: time
  action:
  - entity_id: lightsgroup.living_room_lights
    service: living_room_lights.turn_off
  condition: []
- id: lights3
  alias: lights on at dusk
  trigger:
  - event: sunset
    offset: -01:00:00
    platform: sun
  action:
  - entity_id: lightsgroup.living_room_lights
    service: living_room_lights.turn_on
- id: lights4
  alias: lights off late
  trigger:
  - at: '23:00:00'
    platform: time
  action:
  - entity_id: lightsgroup.living_room_lights
    service: living_room_lights.turn_off
  condition: []

I hope I am making a stupid mistake!

- service: light.turn_on
  entity_id: group.living_room_lights

If your lights are grouped in a group called living_room_lights. Otherwise you will have to specify the lights individually. I believe you also have to provide light data such as brightness.

Also, anything with a time or time offset (triggers/conditions) need the full time data (eg. '00:06:40') and must include the single quotes.

For the automations that don’t have any conditions, you can remove the line condition: []

Thanks @squirtbrnr I used the web gui to make the yaml file, should I edit it manually?

I should have included the rest of my configuration:

 # tail -n 10 /home/homeassistant/.homeassistant/configuration.yaml 

switch:
  - name: living_room_reading_light
    platform: tplink
    host: 192.168.1.11

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

# cat /home/homeassistant/.homeassistant/groups.yaml 

living_room_lights:
    - switch.living_room_reading_light

I figured that was from the frontend. I’ve never used the frontend editor and personally I think it causes more confusion than is helpful. I always edit my files from a text editor.

From the rest of your configuration it looks like you have a switch not a light, so change your light. references in the automation to switch.. Then you don’t need to provide light data. also I’m not sure how the last part of your configuration works. does that manually define a group? Just for simplicity, I would try editing your automation and just call the switch directly since all you have is one right now. then once you add others, you can create a group and switch them all on/off.

So groups don’t work like that? This is what I have now:

switch:
  - name: living_room_reading_light
    platform: tplink
    host: 192.168.1.11

group:
  living_room_lights:
    - switch.living_room_reading_light

automation:
- id: lights4
  alias: lights off late
  trigger:
  - at: 23:00
    platform: time
  action:
  - entity_id: group.living_room_lights
    service: switch.turn_off
  condition: []

(I am trying your suggestion without groups brb)

@squirtbrnr you were right about quoting the time, just lost 30 minutes because of that…

If you do use a group, then it would be:

- service: group.turn_off
  entity_id: group.living_room_lights

If you define a group you have to define it under the group: component. Take a look at the docs for groups.

EDIT: under your group living_room_lights: you’re missing the entity_id: in front of the switch entity.

EDIT 2: I realized I screwed up initially. The service will always reflect the entity type. So if you want to turn on a group it’s:

- service: group.turn_on
  entity_id: group.living_room_lights

If it’s a switch then it’s:

- service: switch.turn_on
  entity_id: switch.living_room_light
1 Like

One correction: there is no turn_on and turn_off service for groups. You need to use the services homeassistant.turn_on and homeassistant.turn_off instead.

1 Like

Thanks @squirtbrnr

@marthocoo The configuration validator doesn’t catch that :frowning: