Light turn off event automation

I want to respond to a light turn off event. But my automation doesn’t trigger. I copied the layout from an event listener, but perhaps my formatting is wrong?

alias: Adaptive Lighting Auto Off - Dining Room
description: ''
trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: light
      service: turn_off
      servce_data:
        entity_id: light.dining_room_zha_group
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.adaptive_lighting_bedroom_lamps
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.adaptive_lighting_bedroom_lamps
mode: single

The event itself

{
    "event_type": "call_service",
    "data": {
        "domain": "light",
        "service": "turn_off",
        "service_data": {
            "entity_id": [
                "light.living_room",
                "light.dining_room_zha_group"
            ]
        }
    },
    "origin": "LOCAL",
    "time_fired": "2022-05-06T19:33:50.375132+00:00",
    "context": {
        "id": "01809add36a0b2da2c5edb12e19ae7f3",
        "parent_id": "01809add3698de3666cde5041aaf37b2",
        "user_id": null
    }
}
service_data

Looks like a simple typing error

Thank you! I guess it took a second pair of eyes

There is another problem i missed:

trigger:
  - platform: event
    event_type: call_service
    event_data:
      domain: light
      service: turn_off
      servce_data:
        entity_id: light.dining_room_zha_group

the entity line should be in brackets

entity_id: [light.dining_room_zha_group]

Interesting. When I added brackets it stopped working. But I did notice that if I called two lights at once detection stopped. If I specifically added two lights to the event trigger it worked. I guess adding [ ] will allow event detection work even multiple lights are in the service call.
So I must have got the [ ] formatting wrong.

If I type this into the automation:

domain: light
service: turn_off
service_data:
  entity_id: [light.dining_room_zha_group]

It saves as this:

domain: light
service: turn_off
service_data:
  entity_id:
    - light.dining_room_zha_group

Which does not work

I’m not sure, but isn’t listening to the device state change much safer? I’m thinking this will not fire if e.g. the generic homeassistant.turn_off is called, or the light is turned off by another means (from the device itself). Unless of couse it is your intention to listen to explicit service calls and not the rest.

1 Like

I agree with @Edwin_D, unless you want to monitor the service itself, it would be much easier to just use the state change as a trigger:

platform: state
entity_id:
  - light.dining_room_zha_group
  - light.another_room_zha_group
to: 'off'
from: 'on'

Thanks guys, you are right. I’m over thinking this and a simple state trigger is the thing to do.

1 Like