Node-Red Three Input AND Logic Assistance

Hi folks,
Simply love HASSIO. Am new here. Thanks to all for their awesome contributions.

I have a simple scenario I am stumped by in NR…

I’m running Philips Hue lights, motion and light sensors.
I would like a simple flow which allows for
time of day criteria (outputs on or off)
Lux detection (outputs numerical, can change to on as needed)
motion detection (outputs on or off)

Essentially- after a certain time AND there’s motion AND there is darkness then send on.

With a trigger timer and no motion, send off. The Bool node doesnt send anything other than on I think.
My flow as it stands now

my switch nodes inject topics (input1, 2 and 3), was hoping to preserve the msg.paylod by excluding it in the change node…

The AND gate is below:

This triggers my lights to turn_on with the conditions below, but doesn’t ever trigger the off sequence as the output of the AND bool only sends on, never off.

I’m sure sure there are much more elegant ways of doing this.
I’ve explored joins, splits, functions, etc… But have ended up with a complicated mess.

My environment:
HA 0.94.3
arch aarch64
RPi 3+
Have a small number of integrations and modified LoveLace interfaces - all works a treat…

Any forehead-slappingingly simple suggestions?

[{"id":"631d0958.d11d18","type":"server-state-changed","z":"fc619c34.edb83","name":"Motion?","version":1,"entityidfilter":"sensor.motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":322,"y":256,"wires":[["bd80828f.82d09"]]},{"id":"bd80828f.82d09","type":"api-current-state","z":"fc619c34.edb83","name":"lux < # ?","version":1,"outputs":2,"halt_if":"55","halt_if_type":"num","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.lux","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":476,"y":256,"wires":[["bd6c2cc8.2624b"],[]]},{"id":"bd6c2cc8.2624b","type":"schedex","z":"fc619c34.edb83","name":"Dark?","suspended":false,"ontime":"sunset","ontopic":"","onpayload":"","onoffset":0,"onrandomoffset":0,"offtime":"sunrise","offtopic":"","offpayload":"","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":616,"y":256,"wires":[["ecc9e1bc.d56c4","8fc4cf1e.c0fd4"]]},{"id":"8fc4cf1e.c0fd4","type":"api-call-service","z":"fc619c34.edb83","name":"Study Lights","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.study_light\"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":934,"y":256,"wires":[[]]},{"id":"ecc9e1bc.d56c4","type":"trigger","z":"fc619c34.edb83","op1":"","op2":"{\"service\": \"turn_off\"}","op1type":"nul","op2type":"json","duration":"5","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":774,"y":304,"wires":[["8fc4cf1e.c0fd4"]]}]

Thanks for the speedy reply - I’ll try it out tonight when I’m back at home.
Could I ask, how could I incorporate Big Timer (I only want to trigger after a certain time, say 10pm).
I have a few rooms with a few different needs…

Once again, thank you.

I don’t use bigtimer for any of my automations. I would recommend using eztimer or schedulex

Great - I’ll check those out.
You’ve essentially done exactly what I wanted to achieve using schedulex above then?
Lovely!
I’ve yet to try it, but looks simple indeed.
I’ll reply once again after I’ve had a go at testing.

Thanks so much.

Okay, I’m getting unsupported input errors on schedulex node.
I added a change node after the current state node to convert to string of on. And it seems to like that.

Schedulex doesn’t seem to pay any attention to the on time when I enter 24 hr format (my case 22:00 is the preferred start time).
Once committed NR tells me the status of the node is On Manual until off @ 06:39 (sunrise - my off time)…
Am I missing something?

Specifically here is my config (how do I add it like you did?):

[{"id":"54d45995.7aaee8","type":"server-state-changed","z":"27cb2c5d.2073c4","name":"Motion?","server":"51002d3f.b84be4","version":1,"entityidfilter":"binary_sensor.hue_motion_sensor_1_motion","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":72,"y":119,"wires":[["95870fc6.b7001"]]},{"id":"95870fc6.b7001","type":"api-current-state","z":"27cb2c5d.2073c4","name":"lux < 20","server":"51002d3f.b84be4","version":1,"outputs":2,"halt_if":"20","halt_if_type":"num","halt_if_compare":"lt","override_topic":false,"entity_id":"sensor.hue_motion_sensor_1_light_level","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":226,"y":119,"wires":[["9bf49f39.45c77"],[]]},{"id":"86e1a28f.de47","type":"schedex","z":"27cb2c5d.2073c4","name":"Dark?","suspended":false,"lat":"-27.47012","lon":"153.021072","ontime":"sunset","ontopic":"","onpayload":"","onoffset":"-60","onrandomoffset":0,"offtime":"sunrise","offtopic":"","offpayload":"","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":510,"y":120,"wires":[["8a2df983.d4f088","cd63f1bc.3d46d"]]},{"id":"8a2df983.d4f088","type":"trigger","z":"27cb2c5d.2073c4","op1":"","op2":"{\"service\":\"turn_off\"}","op1type":"nul","op2type":"json","duration":"5","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":680,"y":148,"wires":[["cd63f1bc.3d46d"]]},{"id":"cd63f1bc.3d46d","type":"api-call-service","z":"27cb2c5d.2073c4","name":"Study Lights","server":"51002d3f.b84be4","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.study\"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":120,"wires":[[]]},{"id":"9bf49f39.45c77","type":"change","z":"27cb2c5d.2073c4","name":"String","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":119,"wires":[["86e1a28f.de47"]]},{"id":"51002d3f.b84be4","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

okay I’m reading the schedex doco (and eztimer). this is normal behaviour for the node when I send on as an input.
It will stay on manual until the next off eventis triggered (i.e. sunrise in my case).
I don’t think those timers will quite do what I’m after in the flow you’ve suggested.
In my other room I have an existing timer set to turn off at 2200, I only want the motion sensor to work after this time (if I’m creeping around the house after 2200).
The flow in this thread turns off existing lights which are turned on at sunset until 2200… I didn’t explain that in my original description as I didn’t consider it at the time.

1 Like

Am testing with a time range node…
Fingers crossed.

Yeah, sorry should have been a time-range node. Threw it together a little fast.

1 Like

Kermit, you’re awesome.
I know it was a simple request.
However i set out with my approach all wrong with the bool node.
same outcome different approach, which is all so often the case with things.

It’s working the way I’d hoped. I’ve some basic refinement to undertake, but great!
Thanks again,