Motion Lights, please help

Hi All,

New to home assistant.

I can’t get this automation working. I have a shelly switch and the aqara motion sensor. I think its something to do with the YAML as the switch and sensor work independently. Any ideas. Photos attached.

I wrote the script written but when I saved it changed automatically.

Script in at the moment is

triggers:
  - entity_id: binary_sensor.0x54ef441000b6309c_occupancy
    to: "on"
    trigger: state
  - entity_id: binary_sensor.0x54ef441000b6309c_occupancy
    to: "off"
    for:
      minutes: 2
    trigger: state
actions:
  - target:
      entity_id: switch.en_suite_light_switch_0
    action: light.turn_{{ trigger.to_state.state }}
mode: single

Please read this from How to help us help you - or How to ask a good question11 Format it properly

Sorry about that Nick,

Just updated now

Thanks in advance

Did you check the traces of the automation?

Also, I would advice you to give your devices/entities a much more meaningful name then
0x54ef441000b6309c to make things easier to recognize/read/troubleshoot.

In the automation I can see when I move infront of the sensor it triggers.

Its just the action (Then do) that isn’t working

Is the entity_id correct?
Also: put double quotes around it.

entity_id is correct and double quotes didn’t help.

The error i’m getting when trying to run the action is this

“Error rendering service name template: UndefinedError: ‘trigger’ is undefined”

Sadly not.

This is the code

triggers:
  - entity_id: binary_sensor.0x54ef441000b6309c_occupancy
    to: "on"
    trigger: state
  - entity_id:
      - binary_sensor.0x54ef441000b6309c_occupancy
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 1
    trigger: state
actions:
  - target:
      entity_id: switch.en_suite_light_switch_0
    action: light.turn_{{ "trigger.to_state.state" }}
mode: single

and get the error “Template rendered invalid service: light.turn_trigger.to_state.state”

Sorry if this an easy fix but this is all new to me haha

Changed to one second at the moment for troubleshooting

Shouldn’t that be

switch.turn_{{ "trigger.to_state.state" }}

No joy with that.

with this

target:
  entity_id: switch.en_suite_light_switch_0
action: turn.switch_{{ trigger.to_state.state }}

getting this error when trying to run action “Error rendering service name template: UndefinedError: ‘trigger’ is undefined”

Of course: you have to give both triggers an ID: click on the dots and name them on & off

Yeah this was it.

Thanks for your help