I have tried many different things to get this to work. Below is a table of how I would like the logic of this flow to work. I am using MQTT to send the relevant data to a Pi. Currently the lights turn on at dusk and off at 22:00. I have a light sensor that sends out a 1 or 0 via MQTT depending on light level and turns on the lights at dusk, I also have an inject node that turns off the lights at 22:00, it also works great.
I would like to add a feature that would turn on the lights if these conditions exist:
A- dark out
B- the lights are off
C- if the lights are already on it should ignore the detection.
Both variables are arriving via MQTT here is what I've tried, there have been many others but I did not keep them.
[{"id":"33cb17ae.2d524","type":"function","z":"c631bfb4.5cc718","name":"Twisted Logic","func":"\nvar d2d = msg.d2d;\nvar detection = msg.dec;\n\nif (detection >= 1 && d2d <=0) {\n return {payload: 0}\n} else if (detection >= 1 && d2d <=1) {\n return {payload: 1}\n}\n","outputs":1,"noerr":0,"x":360,"y":780,"wires":[["4928a604.f19f9"]]},{"id":"4928a604.f19f9","type":"mqtt out","z":"c631bfb4.5cc718","name":"","topic":"office CP","qos":"","retain":"","broker":"cd0995e3.fc6f58","x":540,"y":780,"wires":[]},{"id":"72d968b3.abd44","type":"mqtt in","z":"c631bfb4.5cc718","name":"Dusk till Dawn","topic":"d2d","qos":"2","datatype":"auto","broker":"cd0995e3.fc6f58","x":170,"y":760,"wires":[["33cb17ae.2d524"]]},{"id":"40d01c94.befd94","type":"mqtt in","z":"c631bfb4.5cc718","name":"Detection","topic":"dec","qos":"2","datatype":"auto","broker":"cd0995e3.fc6f58","x":180,"y":800,"wires":[["33cb17ae.2d524"]]},{"id":"cd0995e3.fc6f58","type":"mqtt-broker","z":"","name":"","broker":"192.168.0.50","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]