Motion sensor not triggering automation

Hi all!

I have an Ikea Tradfri motion sensor set up via Zigbee2MQTT and a Hue bulb I am trying to automate. My automation runs as expected when I click “trigger actions” manually, and my motion sensor is reporting state changes when I look via Developer Tools. However, the motion sensor state change doesn’t seem to be triggering the automation and I am a bit confused as to why. It’s my first time with motion sensors so hopefully, it’s just something easy I have missed.

The overall aim is the following:

  • Motion sensor occupancy state changes from off to on (main trigger)
  • Call service “scene.create” to snapshot a hue bulbs state “light.hue_ambiance_lamp_1” save as scene name “stairsbefore”
  • Call service “light.turn_on” to set “light.hue_ambiance_lamp_1” to 366 mireds colour temp and 150 brightness
  • Delay for 3 mins
  • Return “light.hue_ambiance_lamp_1” to previous state by call service “scene.turn_on” scene name “stairsbefore”

I also want to add some time conditions (only activate between 11 pm and 5 am) but I have removed these and will add them at the end to make debugging easier.

My YAML so far is this:

alias: MotionSensor - Turn lights on at night
description: >-
  When motion is triggered downstairs, turn the landing light on brighter then
  reset to its previous state after 3 mins.
trigger:
  - platform: state
    entity_id: binary_sensor.hallwaymotion_sensor_occupancy
    attribute: occupancy
    from: 'off'
    to: 'on'
condition: []
action:
  - service: scene.create
    data:
      scene_id: stairsbefore
      snapshot_entities: light.hue_ambiance_lamp_1
  - service: light.turn_on
    target:
      entity_id:
        - light.hue_ambiance_lamp_1
    data:
      brightness: 150
      color_temp: 366
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - service: scene.turn_on
    target:
      entity_id: scene.stairsbefore
mode: single

The motion sensor shows the following data in the Developer Tools section if this is of help:

battery: 100
linkquality: 114
occupancy: false
requested_brightness_level: null
requested_brightness_percent: null
friendly_name: HallwayMotion Sensor occupancy
device_class: motion

The only thing that changes (other than the battery and linkquality of course) is occupancy that toggles between false & true. I have tried changing the trigger part of the automation to use false and true instead of off and on but this doesn’t seem to make any difference either.

Any help is appreciated! Thanks!

Sorry to double post but I’ve fixed this - so I wanted to post the solution if it comes up on Google for someone else!

It seems that the “Attribute” option should have been left blank. So the final working YAML is this:

alias: MotionSensor - Turn lights on at night
description: >-
  When motion is triggered downstairs, turn the landing light on brighter then
  reset to its previous state after 3 mins.
trigger:
  - platform: state
    entity_id: binary_sensor.hallwaymotion_sensor_occupancy
    to: 'on'
condition: []
action:
  - service: scene.create
    data:
      scene_id: stairsbefore
      snapshot_entities: light.hue_ambiance_lamp_1
  - service: light.turn_on
    target:
      entity_id:
        - light.hue_ambiance_lamp_1
    data:
      brightness: 150
      color_temp: 366
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - service: scene.turn_on
    target:
      entity_id: scene.stairsbefore
mode: single

Hi! Could you tell me where to find those informations? I was kind of vague to me and I couldn’t find in Developer Tools. Thanks.

Developer tools —> States

Scroll to your entity or search for it using the filter.

The entity attributes will be listed in the right-most column. Or click the entity hyperlink and the states will be in the top area where you can change them temporarily.

1 Like