Help with scheduler and illuminance

Hello!

I´m a newbie on node-red and now I asking of your professional help.

I´m using the light-scheduler to turn on/off my lights. But now I also have a lux sensor that I want to implement in my nodes.

I still want the scheduler to trigger the right time but I also want the lux sensor to be true or false so I think there is a AND function I need? Please help.

[{"id":"9e428680.235468","type":"api-call-service","z":"a07e7a47.416498","name":"Köksfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.koksfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":970,"y":60,"wires":[[]]},{"id":"d51ba0e.24b576","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":60,"wires":[["9e428680.235468"]]},{"id":"c650875f.9e8278","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":360,"wires":[["9c72de08.52b12"]]},{"id":"155a9b0f.1b38b5","type":"switch","z":"a07e7a47.416498","name":"ON/OFF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":640,"y":300,"wires":[["d51ba0e.24b576","58493cea.66a874","364714a0.00311c","15a0eef2.b66a01"],["c650875f.9e8278","beded214.d8fd6","64e2fbc5.7efc64","ea019097.34379"]]},{"id":"9c72de08.52b12","type":"api-call-service","z":"a07e7a47.416498","name":"Köksfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.koksfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":970,"y":360,"wires":[[]]},{"id":"3d82269e.36fb0a","type":"api-call-service","z":"a07e7a47.416498","name":"Tvättfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.tvattfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":970,"y":120,"wires":[[]]},{"id":"58493cea.66a874","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":120,"wires":[["3d82269e.36fb0a"]]},{"id":"21952889.9a6ae8","type":"api-call-service","z":"a07e7a47.416498","name":"Allrumsfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.allrumfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":180,"wires":[[]]},{"id":"364714a0.00311c","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":180,"wires":[["21952889.9a6ae8"]]},{"id":"a13588b6.6233d8","type":"api-call-service","z":"a07e7a47.416498","name":"Hallbyrå/Slinga","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hallbyra","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":240,"wires":[[]]},{"id":"15a0eef2.b66a01","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":240,"wires":[["a13588b6.6233d8"]]},{"id":"beded214.d8fd6","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":420,"wires":[["384d8527.2f8b1a"]]},{"id":"384d8527.2f8b1a","type":"api-call-service","z":"a07e7a47.416498","name":"Tvättfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.tvattfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":970,"y":420,"wires":[[]]},{"id":"64e2fbc5.7efc64","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":480,"wires":[["c56c2733.c18308"]]},{"id":"c56c2733.c18308","type":"api-call-service","z":"a07e7a47.416498","name":"Allrumsfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.allrumfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":480,"wires":[[]]},{"id":"ea019097.34379","type":"delay","z":"a07e7a47.416498","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":540,"wires":[["af96f302.470f6"]]},{"id":"af96f302.470f6","type":"api-call-service","z":"a07e7a47.416498","name":"Hallbyrå/Slinga","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.hallbyra","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":540,"wires":[[]]},{"id":"c432e301.721df","type":"change","z":"a07e7a47.416498","name":"Enable Light","rules":[{"t":"set","p":"light_enabled","pt":"flow","to":"yes","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":60,"wires":[[]]},{"id":"8d80b85.cb48748","type":"change","z":"a07e7a47.416498","name":"Disable Light","rules":[{"t":"set","p":"light_enabled","pt":"flow","to":"no","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":120,"wires":[[]]},{"id":"4a88cb0d.7a0324","type":"switch","z":"a07e7a47.416498","name":"Light Threshold Selector","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"2000","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":410,"y":80,"wires":[["c432e301.721df"],["8d80b85.cb48748"]]},{"id":"adb1c1e0.148f1","type":"poll-state","z":"a07e7a47.416498","name":"LUX","server":"20909698.98f8da","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"10","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.resistance_sensor","state_type":"str","halt_if":"2000","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"x":190,"y":80,"wires":[["4a88cb0d.7a0324"],[]]},{"id":"1bc4bdfa.dfc472","type":"change","z":"a07e7a47.416498","name":"Light Enabled?","rules":[{"t":"change","p":"light_enabled","pt":"flow","from":"yes","fromt":"str","to":"on","tot":"str"},{"t":"set","p":"payload","pt":"flow","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":360,"wires":[["155a9b0f.1b38b5"]]},{"id":"af89e6c8.33d5f8","type":"inject","z":"a07e7a47.416498","name":"","topic":"","payload":"auto","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":180,"wires":[["895ed5f8.506b98"]]},{"id":"bedea38e.18f8d","type":"inject","z":"a07e7a47.416498","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":220,"wires":[["895ed5f8.506b98"]]},{"id":"895ed5f8.506b98","type":"light-scheduler","z":"a07e7a47.416498","settings":"cb1af3fc.bf21d","events":"[{\"start\":{\"dow\":1,\"mod\":300},\"end\":{\"dow\":1,\"mod\":570}},{\"start\":{\"dow\":2,\"mod\":300},\"end\":{\"dow\":2,\"mod\":570}},{\"start\":{\"dow\":3,\"mod\":300},\"end\":{\"dow\":3,\"mod\":570}},{\"start\":{\"dow\":4,\"mod\":300},\"end\":{\"dow\":4,\"mod\":570}},{\"start\":{\"dow\":5,\"mod\":300},\"end\":{\"dow\":5,\"mod\":570}},{\"start\":{\"dow\":6,\"mod\":300},\"end\":{\"dow\":6,\"mod\":570}},{\"start\":{\"dow\":0,\"mod\":300},\"end\":{\"dow\":0,\"mod\":570}},{\"start\":{\"dow\":1,\"mod\":780},\"end\":{\"dow\":2,\"mod\":0}},{\"start\":{\"dow\":2,\"mod\":780},\"end\":{\"dow\":3,\"mod\":0}},{\"start\":{\"dow\":3,\"mod\":780},\"end\":{\"dow\":4,\"mod\":0}},{\"start\":{\"dow\":4,\"mod\":780},\"end\":{\"dow\":5,\"mod\":0}},{\"start\":{\"dow\":5,\"mod\":780},\"end\":{\"dow\":6,\"mod\":0}},{\"start\":{\"dow\":6,\"mod\":780},\"end\":{\"dow\":0,\"mod\":0}},{\"start\":{\"dow\":0,\"mod\":780},\"end\":{\"dow\":1,\"mod\":0}},{\"start\":{\"dow\":1,\"mod\":0},\"end\":{\"dow\":1,\"mod\":120}},{\"start\":{\"dow\":2,\"mod\":0},\"end\":{\"dow\":2,\"mod\":120}},{\"start\":{\"dow\":3,\"mod\":0},\"end\":{\"dow\":3,\"mod\":120}},{\"start\":{\"dow\":4,\"mod\":0},\"end\":{\"dow\":4,\"mod\":120}},{\"start\":{\"dow\":5,\"mod\":0},\"end\":{\"dow\":5,\"mod\":120}},{\"start\":{\"dow\":6,\"mod\":0},\"end\":{\"dow\":6,\"mod\":120}},{\"start\":{\"dow\":0,\"mod\":0},\"end\":{\"dow\":0,\"mod\":120}}]","topic":"scheduler","name":"05.00 - Soluppgång & Solnedgång - 02.00","onPayload":"on","onPayloadType":"str","offPayload":"off","offPayloadType":"str","onlyWhenDark":true,"scheduleRndMax":0,"sunElevationThreshold":"5","sunShowElevationInStatus":true,"outputfreq":"output.statechange.startup","x":200,"y":360,"wires":[["1bc4bdfa.dfc472"]]},{"id":"20909698.98f8da","type":"server","z":"","name":"Hassio","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"cb1af3fc.bf21d","type":"light-scheduler-settings","z":"","name":"Hem","latitude":"58.420959","longitude":"14.189730"}]

Isn't the point of a lux sensor to trigger things based on their value ?

I cannot import your flow because of some nodes you are using (home assistant?)

But looking at the on/off, why do you connect 4 nodes to "on" and 4 to "off" ? You should be able to connect both on and off to the same nodes.

And what are the delay nodes used for ?

The "Light enabled" change node, you are changing (read: overwriting) the flow variable you previously set with the lux sensor ?

Modify the change node like this:

and set the flow variable to "ON" and "OFF" instead of yes/no.

Then you can remove the switch node connected to the delay nodes.

output:

I'm wondering if the multiple "delay" nodes are necessary. Since they're all set to the same delay, and from a quick look at the docs they don't change the message contents, wouldn't a single delay in each path, and splitting the output work just as well (and take up less resources)?

Yes indeed, I could not replicate the connections to the "unknown" nodes (once you remove the connections, you cannot connect anything), it could possibly work 1 one api-call as well, depending on what OP is trying to do.

Now I got many questions :slight_smile:

How can I set this to turn_on and turn_off without having 4 on and 4 off???

Without my 5s delay the service nodes don´t trigger...

Will this do a and function for the lux and scheduler?

I use hass.io

Please edit your posts in stead of posting new ones.

Click once on a "call service" node, on the right side, there are tabs, one of which is the info tab. Read the information belonging to this node and how to use it.

Also go through the documentation of node-red, which harbours a lot of useful insights.

Without my 5s delay the service nodes don´t trigger...

Ofcourse they will, the problem is more likely that the flow variable has not been set before you are pressing the buttons and you are overwriting the flow variable.

This is my last try. I fixed the on/off. The 5s delay I still need. But that is not my problem.

I need a AND function so scheduler and illuminance sensor can work together.

Here is my work:

[{"id":"9747cd78.44d02","type":"light-scheduler","z":"a234d308.ca74a","settings":"cb1af3fc.bf21d","events":"[{\"start\":{\"dow\":1,\"mod\":780},\"end\":{\"dow\":1,\"mod\":1320}},{\"start\":{\"dow\":2,\"mod\":780},\"end\":{\"dow\":2,\"mod\":1320}},{\"start\":{\"dow\":3,\"mod\":780},\"end\":{\"dow\":3,\"mod\":1320}},{\"start\":{\"dow\":4,\"mod\":780},\"end\":{\"dow\":4,\"mod\":1320}},{\"start\":{\"dow\":5,\"mod\":780},\"end\":{\"dow\":5,\"mod\":1320}},{\"start\":{\"dow\":6,\"mod\":780},\"end\":{\"dow\":6,\"mod\":1320}},{\"start\":{\"dow\":0,\"mod\":780},\"end\":{\"dow\":0,\"mod\":1320}}]","topic":"","name":"Solnedgånd - 22.00","onPayload":"on","onPayloadType":"str","offPayload":"off","offPayloadType":"str","onlyWhenDark":true,"scheduleRndMax":"5","sunElevationThreshold":"5","sunShowElevationInStatus":true,"outputfreq":"output.statechange.startup","x":270,"y":220,"wires":[["610ef883.cc54b8"]]},{"id":"667f6844.ce0108","type":"api-call-service","z":"a234d308.ca74a","name":"Hallfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_{{payload}}","entityId":"light.hallfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":100,"wires":[[]]},{"id":"6499d3a9.b7f92c","type":"api-call-service","z":"a234d308.ca74a","name":"Sovrumsfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_{{payload}}","entityId":"light.sovrumsfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":760,"y":160,"wires":[[]]},{"id":"b19151ae.55dcd","type":"api-call-service","z":"a234d308.ca74a","name":"Vitrinskåp","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_{{payload}}","entityId":"light.vitrinskap","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":740,"y":220,"wires":[[]]},{"id":"44cb1a0a.26b5b4","type":"api-call-service","z":"a234d308.ca74a","name":"Hall groventré","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_{{payload}}","entityId":"light.hall_groventre","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":760,"y":280,"wires":[[]]},{"id":"34719638.2fd5da","type":"api-call-service","z":"a234d308.ca74a","name":"Kontorsfönster","server":"20909698.98f8da","version":1,"debugenabled":false,"service_domain":"light","service":"turn_{{payload}}","entityId":"light.kontorsfonster","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":760,"y":340,"wires":[[]]},{"id":"610ef883.cc54b8","type":"delay","z":"a234d308.ca74a","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":500,"y":220,"wires":[["667f6844.ce0108","6499d3a9.b7f92c","b19151ae.55dcd","44cb1a0a.26b5b4","34719638.2fd5da"]]},{"id":"db573efe.f0ee7","type":"poll-state","z":"a234d308.ca74a","name":"","server":"20909698.98f8da","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"10","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.resistance_sensor","state_type":"str","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":220,"y":160,"wires":[[]]},{"id":"cb1af3fc.bf21d","type":"light-scheduler-settings","z":"","name":"Hem","latitude":"58.420959","longitude":"14.189730"},{"id":"20909698.98f8da","type":"server","z":"","name":"Hassio","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Hi.....

Some thoughts:

Granted things are not easy when people post with unusual nodes and importing them for the sake of testing is not always appreciated by others.

I'm guilty of doing that many times.

But for your flow a small suggestion:
All those blue nodes, put a debug node in parallel with them..
Then if people don't have the other nodes they can at least see what is being sent to them.

I have worked on this flow for a long time now. I got the scheduler and illuminance sensor to work. But I have problem with on and off triggering.

Could I get a time delay on this and function code for the: msg.payload.lux ??

if (msg.payload.schema == "on" && msg.payload.lux == "on") {
msg.payload = "on"
} else {
msg.payload = "off";
}

return msg;

What do you mean by this? Are you saying you want to delay sending the message if lux and schema are 'on', but send the off right away if one of them is not 'on'?

Two ways I can think of. (1) add a delay if the true side of the IF statement (not recommended) or (2) have the function node have two outputs.The true would go to one and the false would go to the other and on the true leg add a delay node into the flow.

(Like a cloud in the middle of the day) If the lux sensor quickly change its value to on, then the lights turns on and off, on and off.

Sooooo, how do you quantify that? And how about the flip side I.e. what if there is a bright light like a flash of lightning or a car’s headlights?

That's not a problem now, but if there is a solution on both sides (on and off) it would be very good...

How about a delay on both function outputs?

I don't understand.

I need the delay to reset if the state change to off again and vise versa.

reset

If the received message has this property set to any value, all outstanding messages held by the node are cleared without being sent.

You could also try the trigger node, don’t send the first message and wait for x amount of time before sending the original msg or you can send a reset to it.