Automation to switch lights on at specific time, off at specific time, and then motion activated for a specifci time

Hey there,

I am trying to configure an automation via node-red that will allow my lights to turn on between 5pm - 10 pm each day, and then when off, become motion activated from 10pm - 8am (setting 1 light to 25% when motion is no longer activated, but turning off the remaining).

I am able to get the lights turned on from 5pm-10pm just fine, but the motion part is having issues. The motion is wanting to overide the window of time in that once 8am hits, the automation continues to run resulting in the lights turning on / off with motion (Not wanted or intended).

I have been able to complete this automation with the built in automation platform in Hassio, but am unabe to get it working correctly in node-red (trying to centrailize all automations in one area).

Any advice or help would be greatly appreciated! I’ve searched and watched several youtube videos, but can’t seem to get the logic correct.

Greetings Tarantino Anthony,

So the right way to write a Blueprint, (well let’s call it best practice and the method suggested in the docs), is to write an automation or script that does a simplified version of that you want first, then add the blueprint magic sauce. Getting the logic working is not always easy, and becomes obfuscated in all that variable substitution stuff, making everything frustrating.
Get what you want working with sample entities instead of !inputs, then make the blueprint out of that by adding the !inputs and variables and such. Try to avoid device triggers and selectors. You can make them work, but people tend to struggle with those when dealing with them outside of the GUI editor context.

Please follow Community Questions Guideline #9 by sharing your properly-formatted automation YAML configuration and/or Node-RED flow json, so that we can see what you want and where you are having issues.

FYI, these forums tend to have fewer Node-RED users than some of the other Home Assistant-related support sites. If you don’t get an answer here you may want to try Reddit or Discord.

I handle similar time of day limitations / enabled actions by using a cronplus node to set my various “TOD” names and using a change node off of it to set a global “TOD” variable. I then check the TOD in a switch node in my flows as a logic gate. I also use the cronplus changes as global triggers to start certain flows.

@actarantino Here is the nodes I mentioned

[{“id”:“e3f0bb36.c7f638”,“type”:“cronplus”,“z”:“864e4169.fd187”,“g”:“a476dfec26398cb5”,“name”:“TOD”,“outputField”:“TOD”,“timeZone”:“America/Denver”,“storeName”:“”,“commandResponseMsgOutput”:“output1”,“defaultLocation”:“39.751542, -104.893605”,“defaultLocationType”:“fixed”,“outputs”:1,“options”:[{“name”:“Overnight”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“OVERNIGHT”,“expressionType”:“cron”,“expression”:“0 0 0 * * * *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”},{“name”:“5 AM”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“5AM”,“expressionType”:“cron”,“expression”:“0 0 5 * * ? *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”},{“name”:“Predawn”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“PREDAWN”,“expressionType”:“solar”,“expression”:“0 0 3 * * * *”,“location”:“39.751836432323614 -104.89346344023942”,“offset”:“-60”,“solarType”:“selected”,“solarEvents”:“sunrise”},{“name”:“Early Morning”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“EARLYMORNING”,“expressionType”:“solar”,“expression”:“0 * * * * * *”,“location”:“39.751836432323614 -104.89346344023942”,“offset”:“0”,“solarType”:“selected”,“solarEvents”:“sunrise”},{“name”:“Morning”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“MORNING”,“expressionType”:“solar”,“expression”:“0 * * * * * *”,“location”:“39.751836432323614 -104.89346344023942”,“offset”:“30”,“solarType”:“selected”,“solarEvents”:“sunrise”},{“name”:“Day”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“DAY”,“expressionType”:“cron”,“expression”:“0 0 8 * * * *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”},{“name”:“10AM”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“10AM”,“expressionType”:“cron”,“expression”:“0 0 10 * * ? *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”},{“name”:“Afternoon”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“AFTERNOON”,“expressionType”:“cron”,“expression”:“0 0 16 * * * *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”},{“name”:“Golden Hour”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“GOLDENHOUR”,“expressionType”:“solar”,“expression”:“0 * * * * * *”,“location”:“39.751836432323614 -104.89346344023942”,“offset”:“0”,“solarType”:“selected”,“solarEvents”:“eveningGoldenHourStart”},{“name”:“Early Evening”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“EARLYEVENING”,“expressionType”:“solar”,“expression”:“0 * * * * * *”,“location”:“39.751836432323614 -104.89346344023942”,“offset”:“-30”,“solarType”:“selected”,“solarEvents”:“sunset”},{“name”:“Evening”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“EVENING”,“expressionType”:“solar”,“expression”:“0 * * * * * *”,“location”:“39.751836432323614 -104.89346344023942”,“offset”:“0”,“solarType”:“selected”,“solarEvents”:“sunset”},{“name”:“Late Evening”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“LATEEVENING”,“expressionType”:“solar”,“expression”:“0 * * * * * *”,“location”:“39.751836432323614 -104.89346344023942”,“offset”:“60”,“solarType”:“selected”,“solarEvents”:“sunset”},{“name”:“Night”,“topic”:“TOD”,“payloadType”:“str”,“payload”:“NIGHT”,“expressionType”:“cron”,“expression”:“0 0 22 * * * *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”},{“name”:“Weekend”,“topic”:“DOW”,“payloadType”:“str”,“payload”:“WEEKEND”,“expressionType”:“cron”,“expression”:“0 1 0 * * SAT-SUN *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”},{“name”:“Weekday”,“topic”:“DOW”,“payloadType”:“str”,“payload”:“WEEKDAY”,“expressionType”:“cron”,“expression”:“0 1 0 * * Mon-FRI *”,“location”:“”,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”}],“x”:130,“y”:120,“wires”:[[“1f8db05.a008c5”]]},{“id”:“1f8db05.a008c5”,“type”:“switch”,“z”:“864e4169.fd187”,“g”:“a476dfec26398cb5”,“name”:“Topic”,“property”:“topic”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“TOD”,“vt”:“str”},{“t”:“eq”,“v”:“DOW”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:250,“y”:120,“wires”:[[“abe747f0.666ea8”,“275a20a289f132a6”,“02f99eff914b5fd5”],[“55d9ea18.d47be4”]]},{“id”:“02f99eff914b5fd5”,“type”:“change”,“z”:“864e4169.fd187”,“g”:“a476dfec26398cb5”,“name”:“Set TOD”,“rules”:[{“t”:“set”,“p”:“TOD”,“pt”:“global”,“to”:“TOD”,“tot”:“msg”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:420,“y”:100,“wires”:[[“a3eed122.99881”]]},{“id”:“a3eed122.99881”,“type”:“link out”,“z”:“864e4169.fd187”,“g”:“a476dfec26398cb5”,“name”:“Time of Day Change”,“mode”:“link”,“links”:[“267aaead04f0e124”,“3135caa235bcc555”,“43897514ff3ea8a3”,“587d142a78b43fbb”,“7166e9a6d65133c7”,“b4c430e429a01957”,“ae7c1cb1f4555a47”,“1f6b6a65f9d1fb5b”],“x”:640,“y”:100,“wires”:,“l”:true},{“id”:“fae3b4404ee9b1d4”,“type”:“global-config”,“env”:,“modules”:{“node-red-contrib-cron-plus”:“2.2.4”}}]

I don’t understand people wanting to “centralize” all their automations on NR while using HA… it makes no sense, adding a failure point…
Since your question has almost nothing to do with HA, I’d try on Node-Red’s forum: https://discourse.nodered.org/

Because NodeRed is a supported integration option within HA - Node-RED - Home Assistant Community

Some people prefer different levels of programming complexity.

Having previously ran my entire system through a standalone Node-Red server (which was designed for industrial level IOT) I can still do much more complicated automations and cross flow interactions through that vs. simple Automations available in HA w/o having to dive into YAML level scripting.