Node Red Change Light Color Depending On holiday

Hi guys,

Need a little help. I have a flow setup to turn on my outside lights 30 minutes after sunset and turn them off 30 minutes before sunrise. I’m using phillips hue bulb and have them turn on to white. Works good. What i’m trying to do is add options for the lights to change colors for holidays. Let’s say ST Patricks Day. On March 17 i would like the lights to come on green instead of white, and then after St Patric’s Day go back to normal. What would be the best way of doing that. Eventually i would like to add some more options for Christmas, and other holidays. Any suggestions? I’m posting my current flow. TIA

[{"id":"caebef34.4abf3","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"272aa8e0.2709f8","type":"time-range-switch","z":"caebef34.4abf3","name":"Sun State","lat":"42.016073","lon":"-87.850211","startTime":"sunset","endTime":"sunrise","startOffset":"+30","endOffset":"-30","x":240,"y":260,"wires":[["a000e68b.fbd3c8"],["745a7739.50dc2"]]},{"id":"f4fa8006.df3368","type":"inject","z":"caebef34.4abf3","name":"test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":90,"y":140,"wires":[["272aa8e0.2709f8"]]},{"id":"a000e68b.fbd3c8","type":"api-call-service","z":"caebef34.4abf3","name":"Turn On Front","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front","data":"{\"transition\":60,\"brightness_pct\":80,\"kelvin\":\"6500\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":200,"wires":[["da6f1a41.65e5"]]},{"id":"da6f1a41.65e5","type":"debug","z":"caebef34.4abf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":200,"wires":[]},{"id":"745a7739.50dc2","type":"api-call-service","z":"caebef34.4abf3","name":"Turn Off Front","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.front","data":"{\"transition\":60}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":320,"wires":[["7b2fad00.6979b4"]]},{"id":"7b2fad00.6979b4","type":"debug","z":"caebef34.4abf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":320,"wires":[]},{"id":"bd211b56.2affd8","type":"server","name":"Home Assistant","addon":true}]
1 Like

Something like this?
I haven’t written the config to change the color, they are just placeholders.

[{"id":"272aa8e0.2709f8","type":"time-range-switch","z":"caebef34.4abf3","name":"Sun State","lat":"42.016073","lon":"-87.850211","startTime":"sunset","endTime":"sunrise","startOffset":"+30","endOffset":"-30","x":240,"y":260,"wires":[["a000e68b.fbd3c8"],["745a7739.50dc2"]]},{"id":"a000e68b.fbd3c8","type":"api-call-service","z":"caebef34.4abf3","name":"Turn On Front","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front","data":"{\"transition\":60,\"brightness_pct\":80,\"kelvin\":\"6500\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":200,"wires":[["e27c7898.4b8068"]]},{"id":"745a7739.50dc2","type":"api-call-service","z":"caebef34.4abf3","name":"Turn Off Front","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.front","data":"{\"transition\":60}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":320,"wires":[["7b2fad00.6979b4"]]},{"id":"f4fa8006.df3368","type":"inject","z":"caebef34.4abf3","name":"test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":90,"y":140,"wires":[["272aa8e0.2709f8"]]},{"id":"e27c7898.4b8068","type":"api-current-state","z":"caebef34.4abf3","name":"","server":"4bbca37b.1700ec","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.date","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":770,"y":200,"wires":[["d9ad3a5.67927c8"]]},{"id":"7b2fad00.6979b4","type":"debug","z":"caebef34.4abf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":320,"wires":[]},{"id":"d9ad3a5.67927c8","type":"switch","z":"caebef34.4abf3","name":"","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"\\d{4}-03-17","vt":"str","case":false},{"t":"regex","v":"\\d{4}-12-25","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":2,"x":970,"y":200,"wires":[["ff89b447.691ab8"],["d9c3613a.f964b"]]},{"id":"d9c3613a.f964b","type":"api-call-service","z":"caebef34.4abf3","name":"Set to Hellis81's birthday","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front","data":"{\"transition\":60,\"brightness_pct\":80,\"kelvin\":\"6500\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1230,"y":200,"wires":[[]]},{"id":"ff89b447.691ab8","type":"api-call-service","z":"caebef34.4abf3","name":"Set to  ST Patricks Day","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front","data":"{\"transition\":60,\"brightness_pct\":80,\"kelvin\":\"6500\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1220,"y":160,"wires":[[]]},{"id":"bd211b56.2affd8","type":"server","name":"Home Assistant","addon":true},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

This assumes you have the sensor.date entity.
If you don’t then you can use the inject node to send the timestamp and convert that to a date

Oh… since you inject every minute you probably want this also.


This will make sure it does not send turn on every minute.

1 Like

Thank you!
I will give it a try when I’m home and report back tomorrow.

Ok so I’m trying it out today. I don’t have the sensor.date entity so i will use the timestamp to date conversion. I have one more question. How do you add a date range to the switch. I saw how you did one leg for St Patric’s day and the other one for Christmas. Is it possible to do a date range? Let’s say i want to use the Christmas setting starting a week before Christmas and ending 3 days after.
Thanks for all your help!

I think this could work.

[{"id":"272aa8e0.2709f8","type":"time-range-switch","z":"caebef34.4abf3","name":"Sun State","lat":"42.016073","lon":"-87.850211","startTime":"sunset","endTime":"sunrise","startOffset":"+30","endOffset":"-30","x":240,"y":260,"wires":[["8eca453f.878678"],["745a7739.50dc2"]]},{"id":"745a7739.50dc2","type":"api-call-service","z":"caebef34.4abf3","name":"Turn Off Front","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.front","data":"{\"transition\":60}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":540,"y":320,"wires":[["7b2fad00.6979b4"]]},{"id":"f4fa8006.df3368","type":"inject","z":"caebef34.4abf3","name":"test","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"timestamp","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":90,"y":140,"wires":[["272aa8e0.2709f8"]]},{"id":"8eca453f.878678","type":"api-current-state","z":"caebef34.4abf3","name":"","server":"4bbca37b.1700ec","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.front","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":530,"y":200,"wires":[["a000e68b.fbd3c8"],[]]},{"id":"7b2fad00.6979b4","type":"debug","z":"caebef34.4abf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":320,"wires":[]},{"id":"a000e68b.fbd3c8","type":"api-call-service","z":"caebef34.4abf3","name":"Turn On Front","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front","data":"{\"transition\":60,\"brightness_pct\":80,\"kelvin\":\"6500\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":740,"y":200,"wires":[["35d39874.bc40a8"]]},{"id":"35d39874.bc40a8","type":"function","z":"caebef34.4abf3","name":"","func":"var date = new Date(msg.timestamp);\nmsg.monthday = \"\" + (date.getMonth()+1) + date.getDate();\nmsg.monthday = msg.monthday*1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":920,"y":200,"wires":[["d9ad3a5.67927c8"]]},{"id":"d9ad3a5.67927c8","type":"switch","z":"caebef34.4abf3","name":"","property":"monthday","propertyType":"msg","rules":[{"t":"eq","v":"317","vt":"num"},{"t":"btwn","v":"1217","vt":"num","v2":"1228","v2t":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1070,"y":200,"wires":[["da6f1a41.65e5","4c8fe2b3.e4110c"],["4c260f53.20e8"]]},{"id":"da6f1a41.65e5","type":"debug","z":"caebef34.4abf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1030,"y":100,"wires":[]},{"id":"4c260f53.20e8","type":"api-call-service","z":"caebef34.4abf3","name":"Set to Hellis81's birthday","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front","data":"{\"transition\":60,\"brightness_pct\":80,\"kelvin\":\"6500\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1330,"y":180,"wires":[[]]},{"id":"4c8fe2b3.e4110c","type":"api-call-service","z":"caebef34.4abf3","name":"Set to  ST Patricks Day","server":"bd211b56.2affd8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.front","data":"{\"transition\":60,\"brightness_pct\":80,\"kelvin\":\"6500\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1320,"y":140,"wires":[[]]},{"id":"bd211b56.2affd8","type":"server","name":"Home Assistant","addon":true},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I use a function node to create a month date string and then convert it to number. Meaning today is 312.
That way it’s easy to create ranges of dates.

In the switch node you see that I have one that is one day only and one that is a range.

If you want to switch them manually, create an input_select with all the option you want.

If you want it to work automatically, a simple choice would be to integrate your google calendar or something of the sort and put that as a condition for color selection.

OK, I got it working, played around with changing some dates to make sure it fires up the different colors. I had the first trigger repeat every minute in my initial flow to make sure lights turned off if the first command for some reason didn’t turn off all of them. And at night to make sure they turned on. I see that you made it not repeat at all. What makes it fire initially? Sorry for the many questions. I’m new to home assistant and node red. Just installed it this week.

I just removed it because it flooded my debug window.

I don’t know if you can trigger on sun state instead? Can’t remember what your sun conditions was.

But you can have it repeat each minute, i just forgot to reset it before I exported.

I use a function to determine month/day range for holidays and then use a switch accordingly:

let d = new Date();
if (d.getMonth() == 9) {
	msg.payload = "Halloween";
	return msg;
}
if (d.getMonth() == 10 && d.getDate() < 28) {
	msg.payload = "Thanksgiving";
	return msg;
}
if ((d.getMonth() == 11 && d.getDate() < 27) || (d.getMonth() == 10 && d.getDate() >= 28)) {
	msg.payload = "Christmas";
	return msg;
}
if ((d.getMonth() == 11 && d.getDate() > 26) || (d.getMonth() == 0 && d.getDate() < 2)) {
    msg.payload = "NewYear";
    return msg;
}
if ((d.getMonth() == 1) && (d.getDate() > 1 && d.getDate() < 15)) {
    msg.payload = "Valentine";
    return msg;
}
msg.payload = "Nothing";
return msg;

1 Like