Motion sensor lights aren't anything new but with the advent of IOT devices they are a lot smarter, easier to configure, cost less money, completely wireless, and use a lot less power. In this post I will share how I use these devices to automate my lights I have paired with Home Assistant.

What you need

  • Node-RED installed (you could re-create this in YAML but I wouldn't recommend that) along with the node-red-contrib-home-assistant-websocket package
  • Home Assistant
  • Motion sensor setup in HA (you can build your own or buy one such as the Hue Motion Sensor)
  • Light setup in HA (I am using Hue bulbs because I rent but there are some really nice cheap bulbs on the market)

The automation flow

This flow turns on the light when motion is detected and then turns it off 60 seconds after the last motion event. This will also turn the light back off after a set time if it was manually turned on (so lights don't get stuck on after a power outage or if someone accidentally turns it on).

Automation flow example
[{"id":"1eae55a0.def48a","type":"server-state-changed","z":"ff717302.0c688","name":"Motion Laundry Room","server":"233a9c63.e2baf4","entityidfilter":"binary_sensor.motion_laundry_room","entityidfiltertype":"exact","haltifstate":"","outputs":1,"x":400,"y":1740,"wires":[["20e71e7.43434e2"]]},{"id":"20e71e7.43434e2","type":"switch","z":"ff717302.0c688","name":"switch on/off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":1740,"wires":[["6fdd0759.c2af58","2dfe8f66.76b6c"],["2dfe8f66.76b6c"]]},{"id":"6fdd0759.c2af58","type":"api-call-service","z":"ff717302.0c688","name":"Laundry Room Light On","server":"233a9c63.e2baf4","service_domain":"light","service":"turn_on","data":"{ \"entity_id\": \"light.laundry_room_light\" }","mergecontext":"","x":970,"y":1740,"wires":[[]]},{"id":"f0f19d3a.54c94","type":"api-call-service","z":"ff717302.0c688","name":"Laundry Room Light OFF","server":"233a9c63.e2baf4","service_domain":"light","service":"turn_off","data":"{ \"entity_id\": \"light.laundry_room_light\" }","mergecontext":"","x":1361,"y":1788,"wires":[[]]},{"id":"2dfe8f66.76b6c","type":"trigger","z":"ff717302.0c688","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"60","extend":false,"units":"s","reset":"on","bytopic":"all","name":"","x":930,"y":1788,"wires":[["d48f05b9.40cc48"]]},{"id":"cb2dde2c.7a181","type":"server-state-changed","z":"ff717302.0c688","name":"","server":"233a9c63.e2baf4","entityidfilter":"light.laundry_room_light","entityidfiltertype":"substring","haltifstate":"off","outputs":1,"x":670,"y":1780,"wires":[["2dfe8f66.76b6c"]]},{"id":"d48f05b9.40cc48","type":"api-current-state","z":"ff717302.0c688","name":"light.laundry_room ON","server":"233a9c63.e2baf4","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.laundry_room","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1120,"y":1788,"wires":[["f0f19d3a.54c94"],[]]},{"id":"c8b939ce.0df798","type":"comment","z":"ff717302.0c688","name":"Motion Light","info":"","x":730,"y":1700,"wires":[]},{"id":"233a9c63.e2baf4","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Use the import option from the Node-RED hamburger menu to import the above snippet after copying it.

Feedback

I hope you enjoy this flow and if you have any tips, suggestions, or comments leave them below.