Node-red: combine two sensors to take action

This should be easy but I’m struggling with it! I want the inside lights in my house to come on when a vehicle is detected at my gate, AND it’s after midnight and before dawn.

I can set up Big Timer to trigger at those times, and I can access the state-changed sensor. But I can’t seem to set up a sensible configuration - Big Timer only triggers at the set times, or at 1 minute intervals (and I want it to be immediate) - and the state-changed sensor continuously runs, outputting things when it changes. I essentially need to know when the state changes but for it to be in the interval defined by big timer - if it had a ‘status’ output then it’d be fine, but at the moment I have to use the 1 minute poll which is not ideal.

Am I missing something simple?

Here is a working example from my system that is similar.

image

[{"id":"2d881784.0b8688","type":"server-state-changed","z":"fe1a8042.af255","name":"Front Door","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.zone_020","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"Violated","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":80,"y":31,"wires":[["e6e2fd16.2d584"],[]]},{"id":"863c18b1.137f18","type":"server-state-changed","z":"fe1a8042.af255","name":"Mud Rm Interior","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"sensor.zone_021","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"Violated","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":100,"y":91,"wires":[["e6e2fd16.2d584"],[]]},{"id":"e6e2fd16.2d584","type":"time-range-switch","z":"fe1a8042.af255","name":"22:30 - Dawn","lat":"","lon":"","startTime":"22:30","endTime":"dawn","startOffset":0,"endOffset":"0","x":300,"y":51,"wires":[["202042a6.fe983e"],[]]},{"id":"202042a6.fe983e","type":"api-call-service","z":"fe1a8042.af255","name":"Family Rm Light ON","server":"","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.familyroomlightswitch_2"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":540,"y":51,"wires":[["9cd57bf.501cc88"]]},{"id":"9cd57bf.501cc88","type":"delay","z":"fe1a8042.af255","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":290,"y":111,"wires":[["d1673a60.950988"]]},{"id":"d1673a60.950988","type":"api-call-service","z":"fe1a8042.af255","name":"Family Rm Light OFF","server":"","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.familyroomlightswitch_2"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":540,"y":111,"wires":[[]]}]

thanks. Is there any simple way to get it working with big timer and and AND gate, or is my logic about how it all works confused? (which I suspect is the case - big timer doesn’t really produce state info, just events…)

p.s. got it working with this approach, though - thanks! just want to understand the other ways of doing it…

Big Timer is not needed and I believe it is over complicated for what needs to be done. You only really need three.

image

You want vehicle detected at the front gate to start/trigger your logic (same as front door or Mud Rm in my flow) using the events state.

Then you want to check if the time is between midnight and dawn using the Time Range node; if true, turn on the lights using a Call Service node.

There are other ways to do this, like using a function node or some clever checks using trigger state with multiple conditions, but I think this “reads” better and is easier to maintain.

1 Like