Flow for automatic light control using movement, luminance sensors and scheduler to regulate brightness

#Introduction This flow allows automatic dimmed light control using movement and ambient light sensitivity sensors. Light turns on when movement detected and if it is dark outside (threshold can be changed). It turns off after configurable delay. The required light brightness also selected depending on time - e.g if it is late in the night the light turns on with minimum brightness only - to act like a backlight. In the morning the brightness is restored to normal.

The flow has only standard nodes and doesn't have any dependencies.

#Operation

I/Os

It is assumed that all sensors and dimmers are MQTT devices, posting and subscribing to appropriate topics. Published flow assumes presence of following devices. Off-course you can adopt it easily for your situation:

  • Light Dimmer - LED based Light Dimmer, controlled by MQTT topic. Payload: 0-100. 0 means no light, 100 means full intensity. 1 means Backlight Intensity.
  • Movement Sensor - generates topics with payload: OPEN - movement detected. After couple of seconds it sends payload CLOSED if there is no movement any more.
  • Ambient Light Sensor - generates topics with payload 0...1000. Units are Lux. 0 means darkness. 1000 - is daylight. The report is sent every minute.

Flow Description

The flow looks like on picture below (Don't know how to add)

In first control path the Hall Light Sensor Node subscribes to MQTT topic from Ambient Light sensor. Light Threshold selector forwards light intensity message based on reported ambient light level. If it is below 20 Lux, first output is activated and Enable Light Block writes Yes to Light_enabled context variable. Otherwise Light_enabled variable is set to No.

In second control path Light Brightness is selected based on timing. For this I have two inject nodes - one is activated at 9:00 PM and it has a payload of 1 (backlight brightness) and another one is activated at 6:00 AM and it has payload of 50 - normal brightness. The values are written to flow context variable Light_brightness by Light Brightness Adjustment node.

In third control path Hall Motion Sensor Node subscribes to MQTT topic from Motion Sensor. As written before motion sensor sends messages with OPEN and CLOSED Payload. Movement Detected? Node forwards only OPEN Messages to it's output. Light Enabled? node checks if Light_enabled variable is set to Yes, and if it the case, forwards the message. Light Brightness Adjustment changes message payload to currently selected brightness from flow context Light_brightness variable. Then finally this message sent to Hall Light Dimmer node, which publishes it to MQTT topic. As you see light will be switched on only if the current ambient light level is low enough and light intensity will be automatically adjusted.

To turn off the light after some delay Switch off Delay Trigger node is used. It is reset by OPEN Message, and starts delay after receiving any other message from motion sensor(this will be CLOSED message obviously). After time is elapsed it sends message with zero light brightness to Hall Light Dimmer node.

#Comments and Ideas Comments and ideas are wellcome. Post them in Forum topic: https://groups.google.com/d/topic/node-red/V1-HP4x7ntw/discussion

[{"id":"76384a52.7084c4","type":"mqtt-broker","z":"aca73478.c3fce8","broker":"localhost","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willRetain":null,"willPayload":"","birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":""},{"id":"da21213a.d1c418","type":"mqtt in","z":"aca73478.c3fce8","name":"Hall Motion Sensor","topic":"/myhome/state/Hall_motion","broker":"76384a52.7084c4","x":121.44998168945312,"y":299.73333740234375,"wires":[["c1e6aaab.f19138","9701b7d3.99416"]]},{"id":"2b0eb06f.d7e8d8","type":"mqtt out","z":"aca73478.c3fce8","name":"Hall Light Dimmer ","topic":"/myhome/command/Light_Hall/state","qos":"0","retain":"true","broker":"76384a52.7084c4","x":1116.4500732421875,"y":350.4166564941406,"wires":[]},{"id":"c1e6aaab.f19138","type":"switch","z":"aca73478.c3fce8","name":"Movement detected?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OPEN","vt":"str"}],"checkall":"false","outputs":1,"x":380.4500427246094,"y":277.9666748046875,"wires":[["a7f3a3f2.b51f38"]]},{"id":"9701b7d3.99416","type":"trigger","z":"aca73478.c3fce8","op1":"5","op2":"0","op1type":"nul","op2type":"val","duration":"8","extend":false,"units":"s","reset":"OPEN","name":"Switch off delay","x":502.4500427246094,"y":447.9666442871094,"wires":[["2b0eb06f.d7e8d8"]]},{"id":"e7886307.9cdb98","type":"mqtt in","z":"aca73478.c3fce8","name":"Hall Light Sensor","topic":"/myhome/state/Lumin_Hall","broker":"76384a52.7084c4","x":111.11666870117188,"y":81.11660766601562,"wires":[["ba0ba53c.012d6"]]},{"id":"1e9a8082.fb1d8f","type":"inject","z":"aca73478.c3fce8","name":"Reduce Brightness at 21:00","topic":"Night Brightness","payload":"1","payloadType":"str","repeat":"","crontab":"00 21 * * *","once":false,"x":165.45004272460938,"y":203.43331909179688,"wires":[["9455415e.123a28"]]},{"id":"160d3974.89f507","type":"inject","z":"aca73478.c3fce8","name":"Normal Brightness at 6:00","topic":"Night Brightness","payload":"50","payloadType":"num","repeat":"","crontab":"00 6 * * *","once":false,"x":156.11666870117188,"y":162.11666870117188,"wires":[["9455415e.123a28"]]},{"id":"ba0ba53c.012d6","type":"switch","z":"aca73478.c3fce8","name":"Light Threshold Selector","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"20","vt":"num"},{"t":"else"}],"checkall":"false","outputs":2,"x":465.11663818359375,"y":81.11666870117188,"wires":[["6c4b46e6.b31dd8"],["6af8fd01.69823c"]]},{"id":"6c4b46e6.b31dd8","type":"change","z":"aca73478.c3fce8","name":"Enable Light","rules":[{"t":"set","p":"Light_enabled","pt":"flow","to":"Yes","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":769.7833251953125,"y":44.399993896484375,"wires":[[]]},{"id":"6af8fd01.69823c","type":"change","z":"aca73478.c3fce8","name":"Disable Light","rules":[{"t":"set","p":"Light_enabled","pt":"flow","to":"No","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":772.449951171875,"y":112.91665649414062,"wires":[[]]},{"id":"9455415e.123a28","type":"change","z":"aca73478.c3fce8","name":"Light Brightness Adjustment","rules":[{"t":"set","p":"Light_brightness","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":514.11669921875,"y":179.11666870117188,"wires":[[]]},{"id":"a7f3a3f2.b51f38","type":"switch","z":"aca73478.c3fce8","name":"Light Enabled?","property":"Light_enabled","propertyType":"flow","rules":[{"t":"eq","v":"Yes","vt":"str"}],"checkall":"true","outputs":1,"x":611.1168212890625,"y":277.1166687011719,"wires":[["c474bc9b.e9ff88"]]},{"id":"c474bc9b.e9ff88","type":"change","z":"aca73478.c3fce8","name":"Light Brightness Adjustment","rules":[{"t":"set","p":"payload","pt":"msg","to":"Light_brightness","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":851.61669921875,"y":276.7499694824219,"wires":[["2b0eb06f.d7e8d8"]]}]
syoma755

Flow Info

created 1 year, 5 months ago

Node Types

Core
  • change (x4)
  • inject (x2)
  • mqtt in (x2)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • switch (x3)
  • trigger (x1)

Tags

  • Light
  • Motion
  • Automation
  • MQTT
  • Sensor
  • Dimmer
  • Control
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option