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;