Hi, ive been diving into node red for my more advanced automations and I made something that I think could be done smoother and simpler.
I want the lights to turn off when I’m in bed (motion sensor) and my phone is charging.
Flow code
[{"id":"136c13e32b82c7cc","type":"api-call-service","z":"97aba0f8a5c773f2","name":"","server":"","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.osram_weis_level_light_color_on_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1790,"y":2240,"wires":[["c1d58ef68de71456"]]},{"id":"165fa34a49b72a46","type":"api-current-state","z":"97aba0f8a5c773f2","name":"","server":"","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.fig_lx1_is_charging","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1020,"y":2220,"wires":[["b9f0e58e7f45fb58","444d71a349657ca8"],[]]},{"id":"b9f0e58e7f45fb58","type":"debug","z":"97aba0f8a5c773f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":2160,"wires":[]},{"id":"2498ba88d1497e0c","type":"debug","z":"97aba0f8a5c773f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1550,"y":2180,"wires":[]},{"id":"c32a01774329d4c8","type":"time-range-switch","z":"97aba0f8a5c773f2","name":"","lat":"","lon":"","startTime":"20:00","endTime":"01:00","startOffset":0,"endOffset":0,"x":1550,"y":2240,"wires":[["136c13e32b82c7cc","2498ba88d1497e0c"],[]]},{"id":"99f55ee0d6f4d4fd","type":"debug","z":"97aba0f8a5c773f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":190,"y":2180,"wires":[]},{"id":"ad204a8f5782af07","type":"server-state-changed","z":"97aba0f8a5c773f2","name":"","server":"","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.philips_sml001_fc6b090b_occupancy","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":340,"y":2240,"wires":[["99f55ee0d6f4d4fd","4af04180b89cfb58"],[]]},{"id":"c1d58ef68de71456","type":"debug","z":"97aba0f8a5c773f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1810,"y":2180,"wires":[]},{"id":"4af04180b89cfb58","type":"msg-resend","z":"97aba0f8a5c773f2","interval":"1","intervalUnit":"secs","maximum":"120","bytopic":false,"clone":false,"firstDelayed":false,"addCounters":false,"waitForResend":false,"highRate":false,"outputCountField":"","outputMaxField":"","name":"","x":710,"y":2220,"wires":[["165fa34a49b72a46","49e679dd53a774f0"]]},{"id":"49e679dd53a774f0","type":"debug","z":"97aba0f8a5c773f2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":2160,"wires":[]},{"id":"444d71a349657ca8","type":"delay","z":"97aba0f8a5c773f2","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":1350,"y":2240,"wires":[["c32a01774329d4c8"]]}]
First I tried to build an AND gate, but I had to inject the motion sensor cue into the charging state, so I simplified it and put them one after the other.
The motion sensor is almost under the bed, so it tracks if I walk in front of the bed. I plug the phone in afterwards so the state check for charging get retriggered by the “msg-resend” (I tried first with a trigger node but could figure out how to reset after a few minutes in a smart way).
To save traffic, I limit the signal afterwards and then do a time check and the turn the lights off.
I haven’t extensively tested this, but it seems to work, but it doesn’t feel very elegant, and I wonder if I could do it only with no extra installed msg resend node.
I also have more workflows in mind that rely on input_booleans that get set by multiple sensors, that don’t depend on each other like in this example and I haven’t found a good way for these “AND gate” style setups.
Cheers.