How to Add an Aqara Motion sensor into Home Assistant


What you will need to do this project

A working version of home assistant, I use a VM on a Qnap NAS but a common solution is to purchase a raspberry pi and flash an SD Card, if you need help with this step follow this video:

2) A conbee II stick with Deconz Add-on, you can install this from the supervisor tab in home assistant.

Adding to Home Assistant

In the video below I detail the steps necessary, but this is a summary:

Go to the Deconz Integration, navigate to sensors and click add a new sensor.

Now on your Aqara motion sensor press the sync button for around three seconds, this will flash and the pairing process is complete.

 

Automation Code

In this section I’m going to create two automations, the first automation will turn on a Philips Hue Lightstrip to red with a brightness of 255 (maximum) when motion is triggered and the light sensor is below 100.

My automation are under a folder called “automation” and I have a file for each automation, in order to achieve this split you would need to add the following to configuration.yaml

automation: !include automations.yaml
automation split: !include_dir_list ./automations/

The first line of code you should have already, keep it in there as this will allow you to slowly migrate your existing automation in automation.yaml to new files.

turn_on_lightstrip.yaml

alias: Turn on light strip when there is motion in the kitchen

trigger:
  platform: state
  entity_id: binary_sensor.kitchen_motion_sensor
  to: 'on'
condition:
    condition: numeric_state
    entity_id: sensor.kitchen_motion_light_level
    below: 100
action:
  service: light.turn_on
  entity_id: light.kitchen_lightstrip
  data:
      color_name: red
      brightness: 255
      entity_id: light.kitchen_lightstrip

 

turn_off_lightstrip.yaml

The second automation will turn off the light after a certain amount of time whereby there was no motion.

alias: Turn off kitchen light 10 minutes after last movement

trigger:
  platform: state
  entity_id: binary_sensor.kitchen_motion_sensor
  to: 'off'
  for:
    #minutes: 10
    seconds: 1
action:
  service: light.turn_off
  entity_id: light.kitchen_lightstrip

Gio

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts