Node-RED Light Automation: Solving Presence Detection

Hey everyone, I’m here to share my journey with Node-RED and smart home automation. I’ve been working on a project to automate my home lights based on presence detection, and it’s been both challenging and rewarding. Let me walk you through my setup and the solution I found.

The Goal:
I wanted my lights to turn on when I or my wife enter the house, but only if the other isn’t already home. Additionally, I didn’t want the lights to turn off when someone leaves if the other person is still present. Sounds simple, but the logic was a bit tricky!

The Setup:
I have two input_boolean entities, one for me and one for my wife. These are triggered by presence sensors (ping and app sensors). The lights should activate based on who’s home, but without overlapping or conflicting actions.

The Challenge:
Initially, my Node-RED flow would toggle the lights on or off regardless of the other person’s status. For example, if my wife was already home, my arrival would still trigger the lights to turn on, which wasn’t ideal. I needed a way to check if someone was already present before executing the automation.

The Solution:
After some research and trial and error, I figured out how to incorporate state checks into my flow. Here’s what I did:

  1. Presence Check Nodes:
    I added nodes to check the state of both input_boolean entities. This allows the flow to determine if either of us is already home before taking action.

  2. Conditional Logic:
    Using function nodes, I implemented conditional logic to decide whether to turn the lights on or off. For example, if I arrive home and my wife is already present, the lights won’t toggle. However, if I’m the only one home, the lights will turn on.

  3. Departure Handling:
    To prevent the lights from turning off when someone leaves, I set up a delay mechanism. If the last person leaves, the lights will turn off after a short period (I chose 5 minutes to account for any potential delays or false triggers).

The Flow:
Here’s a simplified version of my Node-RED flow:

  • Input Boolean Check:

    • Node 1: Check if input_boolean.jeroen_thuis is on.
    • Node 2: Check if input_boolean.angela_thuis is on.
  • Conditional Logic:

    • If only one person is home, turn the corresponding lights on.
    • If both are home, no action is taken.
    • If the last person leaves, turn the lights off after a delay.

Tips and Tricks:

  • Use State Sensors:
    Ensure your presence sensors are reliable and correctly configured. I found that using both ping and app sensors provided better accuracy.
  • Test Incrementally:
    Break down your flow into smaller sections and test each part before integrating them. This helps identify and fix issues early.
  • Document Your Flow:
    Add comments and labels to your nodes for clarity. It makes maintaining and updating your flow much easier in the future.

Conclusion:
After some tweaking and testing, my Node-RED setup now perfectly handles our presence-based lighting needs. It’s amazing how a bit of logic and creativity can transform a simple idea into a seamless smart home feature. If anyone has questions or suggestions, feel free to reach out!

Happy automating! :rocket: