Node-RED Lighting Automation Help

Hi,

Currently pulling over some automatons I have in yaml to node-red and trying to tweak (i.e. make better) at the same time. I’m a HA noob so bear with me :slight_smile:

Automation in yaml currently switches on light 30min before sunset IF either myself OR my partner are home. I did this with this in groups.yaml

  People:
 
    - device_tracker.me
    - device_tracker.her

and then the following condition within the relevant automation:

  condition: 
    - condition: state
      entity_id: group.people
      state: 'home'

The current sequence (flow) in node-red looks like this. This successfully turns on the lights 30min before sunset but doesn’t do any presence checking to see if we’re home
image

1st Question - How to I check for presence detection in node-red? Is it with the state node? Should this be before or after the switch in the sequence?

2nd Question - Assume its after sunset and neither of us are home so the lights are OFF. One of us then comes home…so I want them to turn on. The current automation trigger is the Bigtimer (at sunset) which has run and then stopped (we’re not home). How can i integrate this extra condition to turn ON after sunset when we come home? Is it easier to break this out to a separate automation?

1 Like

You’re almost there. The node you are looking for is the current-state node.

For your second question, you could use the event-state node to trigger when your group.people changes to home. Then, have a check for if it’s dark outside (there are various ways to do this) and turn on the lights.

Thanks @code-in-progress


So I added a state change node after the timer and before the switch, config looks like this…

And for the second bit I created a new sequence

image

The bigtimer is ON at Sunset and OFF at Sunrise…Will that work or is there a better way…??

There might be a better way. I think from a cursory look that your flow can work. In another thread, I detail out how I do actual “modes” with NodeRed and HA. You might want to give it a look over:

3 Likes