Issue with an Automation

Would someone be kind enough to look over this automaiton?

The lights come on, some on at the requested brightness, others at full. The double plug switch option never comes on. The lights do not turn off after any amount of time, I have to manually turn them off.

- id: '1640321742258'
  alias: Front Door Triggered Lights
  description: Turn on most lights after 2045
  trigger:
  - type: opened
    platform: device
    device_id: 67c71e4256c239940d1ce93d2dea9cba
    entity_id: binary_sensor.front_door
    domain: binary_sensor
  condition:
  - condition: time
    after: '20:45:00'
  action:
  - service: light.turn_on
    target:
      entity_id:
      - light.hallway
      - light.livingroom
      - light.pc
    data:
      brightness_pct: 30
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    target:
      entity_id:
      - light.hallway
      - light.livingroom
      - light.pc
  - service: switch.turn_on
    target:
      entity_id: switch.double_plug_left
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    target:
      entity_id: switch.double_plug_left
  mode: single

I don’t see anything wrong with the automation as such. You say the lights always turn on so your trigger is working as you want.

My experience of switching several (I assume zigbee bulbs?) at the same time is it is unreliable, you may benefit from creating a zigbee light group so the automation can send one command to the group rather than several to each device.

You say the plug never turns on, not teaching you to suck eggs but have you confirmed the plug turns on and off correctly by using the same command in developer tools, service? Just to rule out any issues independently of the automation.

also you can use “homeassistant.turn_on”

this will turn on lights and switch in a list

service: homeassistant.turn_on
data: {}
target:
  entity_id:
    - switch.alysha_lamp
    - light.kids_room

Are you sure that all the lights support brightness_pct? Some smart bulbs require you to use a brightness value (1-255).

Are you like me and tend to mess around with your automations in the evening? Every time you edit and save any automation it will reload all autoamtions and any waits or delays will stop. With an automation like this, I would set multiple triggers and use a choose action.

- id: '1640321742258'
  alias: Front Door Triggered Lights
  description: Turn on most lights after 2045
  trigger:
  - id: Door Open
    type: opened
    platform: device
    device_id: 67c71e4256c239940d1ce93d2dea9cba
    entity_id: binary_sensor.front_door
    domain: binary_sensor
  - id: Door Closed 5
    platform: state
    entity_id: binary_sensor.front_door
    to: "off"
    for: "00:05:00"
  - id: Door Closed 8
    platform: state
    entity_id: binary_sensor.front_door
    to: "off"
    for: "00:08:00"
  condition:
  - condition: time
    after: '20:45:00'
  action:
  - choose
    - conditions:
        condition: trigger
        id: Door Open
      sequence:
        - service: light.turn_on
          target:
            entity_id:
              - light.hallway
              - light.livingroom
              - light.pc
          data:
            brightness: 75
    - conditions:
        condition: trigger
        id: Door Closed 5
      sequence:
        - service: light.turn_off
          target:
            entity_id:
              - light.hallway
              - light.livingroom
              - light.pc
        - service: switch.turn_on
          target:
            entity_id: switch.double_plug_left
    - conditions:
        condition: trigger
        id: Door Closed 8
      sequence:
        - service: switch.turn_off
          target:
            entity_id: switch.double_plug_left
    default: {}
mode: restart

Yep, zigbee bulbs. I’ll look up the light group and see if that changes anything.

The plug will turn on fine in developer and in other automations, just not this one…

Does this just help reduce the amount of code, or what is the purpose of using this service?

Ya, 1 of the 3 GE bulbs goes to the correct brightness, the other two do not.

I mess with the automations before 2045, so I didn’t think the delays would be in effect yet?

light.turn_on will not turn on a switch

long way
light on

service: light.turn_on
data: {}
target:
  entity_id: light.kids_room

switch on

service: switch.turn_on
data: {}
target:
  entity_id: switch.alysha_lamp

if you use homeassistant.turn_on
done in one service call

service: homeassistant.turn_on
data: {}
target:
  entity_id:
    - switch.alysha_lamp
    - light.kids_room
1 Like

That appears to have done the trick in my testing anyway.
Is there a way to set the brightness of the lights using this method?

- id: '1640728263983'
  alias: Lights after 2045 Front Door
  description: ''
  trigger:
  - type: opened
    platform: device
    device_id: 67c71e4256c239940d1ce93d2dea9cba
    entity_id: binary_sensor.front_door
    domain: binary_sensor
  condition: []
  action:
  - service: homeassistant.turn_on
    target:
      entity_id:
      - light.hallway
      - light.livingroom
      - light.pc
      - switch.double_plug_left
      - switch.stairway_lights
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: homeassistant.turn_off
    target:
      entity_id:
      - light.hallway
      - light.livingroom
      - light.pc
      - switch.double_plug_left
      - switch.stairway_lights
  mode: single
1 Like