Unable to get HA to switch light on when aqara/lumi sensor activates

Hi, noob here. First time trying to consolidate my various widgets around HA running on RPi with Sonoff zigbee dongle. Thought I would start small and get a light to switch on when walk into a room. Using an Aqara motion/illuminance sensor and either Tradfri outlet with lamp or Tradfri gu10 bulb. Cannot get either option to light the lamp/switch on the outlet. I can run the automation from the gui and the lights will switch off/on, and I can see the log registering motion detected and motion stopped, but I cannot get my automation to work when triggering the sensor. Baffled. Any pointers much appreciated. Will hopefully paste the yaml below

alias: Turn on office light
description: when aqara/lumi motion detector activated
trigger:
  - type: motion
    platform: device
    device_id: 1620702e36c36c4e9e957048dd67abb4
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_iaszone
    domain: binary_sensor
condition:
  - condition: device
    type: is_off
    device_id: ba615192237aed779c3cb409adb84c78
    entity_id: switch.ikea_of_sweden_tradfri_control_outlet_switch
    domain: switch
action:
  - type: turn_on
    device_id: 502615b8e47bb6081c4173e92705f6d5
    entity_id: light.ikea_of_sweden_tradfribulbgu10ws345lm_light_2
    domain: light
    flash: long
mode: single
alias: Turn off office light
description: when motion stops
trigger:
  - type: no_motion
    platform: device
    device_id: 1620702e36c36c4e9e957048dd67abb4
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_iaszone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - type: turn_off
    device_id: 502615b8e47bb6081c4173e92705f6d5
    entity_id: light.ikea_of_sweden_tradfribulbgu10ws345lm_light_2
    domain: light
mode: single

I tried trashing and rebuilding, rebooting RPi but with no joy. Feel a bit foolish reaching out. Not really got a programming mind. Any help much appreciated.

Things to try:

  1. Run the actions to make sure they are correct. Go to Settings → Automations, click on the three dot icon to the right of your automation. Select RUN. This skips the triggers and conditions and just checks the actions.

  2. Check the automation trace to see what is happening with the conditions. Troubleshooting Automations - Home Assistant this will only be available if the trigger has occurred (the manual run wont help here).

  3. Check for relevant errors in Settings → logs

  4. Not using device automations. Use state triggers, conditions and service calls (in the actions). e.g.

alias: Turn on office light
description: when aqara/lumi motion detector activated
trigger:
  - platform: state
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_iaszone
    from: 'off'
    to: 'on'
condition:
  - condition: state
    entity_id: switch.ikea_of_sweden_tradfri_control_outlet_switch
    state: 'off'
action:
  - service: light.turn_on
    target:
      entity_id: light.ikea_of_sweden_tradfribulbgu10ws345lm_light_2
    data:
      effect: flash_long ### check this is correct in your light more-info pop-up when the light is on
mode: single
alias: Turn off office light
description: when motion stops
trigger:
  - platform: state
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_iaszone
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: light.turn_off
    target:
      entity_id: light.ikea_of_sweden_tradfribulbgu10ws345lm_light_2
mode: single

Regarding the light effect, check it is in the list of available effects by clicking on your light, turn it on and look in the effect dropdown list:

Thank you so much for that Tom. Woke up this morning, walked into the pit and the light came on. And then off when no motion. I have no idea why. Is it possible there is some sort of delay in HASS adopting a new automation? I seriously thought I was going mad, when maybe I just neded to go to bed!

Your code seems much more elegant. I copied it and now have two successful automations going. Thank you so much. Is there a different “entry point” to start using this approach? Other than “Settings =>Automations & Scenes”?
Thanks again

Nope. It should work after you save it in the UI automation editor.

The entry point I use is the VSCode editor and YAML. :slight_smile: