Switch on a light at specific time only if we are after dusk

I would like to switch on a light at a specific time only if we are in the period dusk<->down.
I am trying to do this without using function nodes.
I tries to use sun, inject and Boolean node but I cannot figure out how to combine them together…
Is there any suggestion you would give me or any new palette to install?

Thank You

You could use a current-state node to check if sun.sun state is below_horizon

Starting from your idea I found a daylight sensor.
I don’t know if it comes from dark sky or it is embedded in HA but I could check if it is not golden_hour_1, solar_noon or golden_hour_2…

Deconz has a daylight sensor

This was my outside xmas lights flow i used

[{"id":"a8943e80.46cd9","type":"eztimer","z":"1bcd72e2.fbd4ed","name":"Dusk till MIdnight","autoname":"sunsetStart - dawn","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"-33.91126","lon":"151.17529","timerType":"1","startupMessage":true,"ontype":"1","ontimesun":"sunsetStart","ontimetod":"17:00","onproperty":"payload","onvaluetype":"bool","onvalue":"true","onoffset":"","onrandomoffset":false,"onsuppressrepeats":true,"offtype":"1","offtimesun":"dawn","offtimetod":"23:59:00","offduration":"00:01:00","offproperty":"payload","offvaluetype":"bool","offvalue":"false","offoffset":0,"offrandomoffset":0,"offsuppressrepeats":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":130,"y":80,"wires":[["b883264.21a09d8"]]}]

From the cookbook in the documentation:

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/sun-events.html

eztimer node is very useful.
Anyway I don’t want simply switch on/off the light following the sun but use the sun status to “confirm” I can switch on the light.
For example if a 7:00 I would want to witch on the light but the sun is above the orison the light should not switch on.
In the end I tried to use a simple function node In this way:

[{"id":"bf9da50c.9e87c8","type":"api-call-service","z":"45dd8798.2cfc88","name":"","server":"c6e21e6c.847e8","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"{{payload}}","entityId":"switch.luce1_portico","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":910,"y":500,"wires":[[]]},{"id":"ff01aa4c.00ee28","type":"eztimer","z":"45dd8798.2cfc88","name":"","autoname":"sunset - sunriseEnd","tag":"eztimer","suspended":false,"sendEventsOnSuspend":false,"lat":"45.6666400","lon":"9.0488400","timerType":"1","startupMessage":false,"ontype":"1","ontimesun":"sunset","ontimetod":"17:00","onproperty":"payload","onvaluetype":"str","onvalue":"turn_on","onoffset":0,"onrandomoffset":0,"onsuppressrepeats":false,"offtype":"1","offtimesun":"sunriseEnd","offtimetod":"dusk","offduration":"00:01:00","offproperty":"payload","offvaluetype":"str","offvalue":"turn_off","offoffset":0,"offrandomoffset":0,"offsuppressrepeats":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":false,"sun":false,"x":380,"y":500,"wires":[["10d55e3e.9c07a2","12963c23.6e6b2c"]]},{"id":"1427e6e1.b7aa11","type":"inject","z":"45dd8798.2cfc88","name":"","topic":"interruttore","payload":"info","payloadType":"str","repeat":"","crontab":"00 07 * * 1,2,3,4,5","once":false,"onceDelay":0.1,"x":150,"y":500,"wires":[["ff01aa4c.00ee28"]]},{"id":"10d55e3e.9c07a2","type":"function","z":"45dd8798.2cfc88","name":"","func":"if ( msg.payload.state == \"on\" ) { var msg1 = { payload: \"turn_on\" } }\nelse { msg1 = msg }\nreturn msg1;\n","outputs":1,"noerr":0,"x":610,"y":500,"wires":[["bf9da50c.9e87c8","f5e12f7d.416188"]]},{"id":"f5e12f7d.416188","type":"debug","z":"45dd8798.2cfc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":850,"y":600,"wires":[]},{"id":"12963c23.6e6b2c","type":"debug","z":"45dd8798.2cfc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":560,"y":640,"wires":[]},{"id":"e95e5932.98fbc","type":"inject","z":"45dd8798.2cfc88","name":"","topic":"on","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":560,"wires":[["ff01aa4c.00ee28"]]},{"id":"31686eab.19ba4a","type":"inject","z":"45dd8798.2cfc88","name":"","topic":"off","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":620,"wires":[["ff01aa4c.00ee28"]]},{"id":"c6e21e6c.847e8","type":"server","z":"","name":"Casa (local https)","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

So I bought to use an “info” message at the specific time to get the eztimer node status. If it is “on” then I can switch on the light otherwise I drop the message.
Unfortunately the function node looks not to change the message payload in this case but I cannot figure out why…

var newMsg = "";
if ( msg.payload.state == "on" ) { newMsg = {payload: "turn_on"} } else { newMsg = { payload: msg.payload } }
return newMsg;


Checkout the time-range-switch