Why does this flow not work

Hello all,

Probably another real noob question, but I’ve been working on a flow for a few days and can’t get it done.

I made a very simple flow: when motion is detected outside, I want the light under the carport to turn on and off after 30 seconds. Somehow it doesn’t work. The sensor detects motion and turns on the light carport, then nothing happens. The lamp stays on continuously.

I have also used the same flow in other places in my house and there it works fine, just not here and I do not know what is wrong.

Here is the flow:

carport

Here are the settings of my ‘events-state’.

Here the setting: of the switch.

Why does this flow not work? Hope someone will shed some light on it.

Johan

Edit: Here is the code of my flow

[{"id":"615fe651fd6e3ca8","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"275deb0aa0b68851","type":"server-state-changed","z":"615fe651fd6e3ca8","name":"Sensor carport","server":"aacf422.35ac2c","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.0x00158d00047b8551_illuminance","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"30","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":120,"y":100,"wires":[["e1b9501ec1d2999f"],["04f787fe2895fdb6"]]},{"id":"04f787fe2895fdb6","type":"api-call-service","z":"615fe651fd6e3ca8","name":"Lamp carport - aan","server":"aacf422.35ac2c","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.shelly1_b8bdd2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":400,"y":160,"wires":[[]]},{"id":"e1b9501ec1d2999f","type":"api-call-service","z":"615fe651fd6e3ca8","name":"Lamp carport- uit","server":"aacf422.35ac2c","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.shelly1_b8bdd2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":400,"y":40,"wires":[["c5bbb4667271a7ba"]]},{"id":"8d5ef902c3a64e76","type":"inject","z":"615fe651fd6e3ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":200,"wires":[["e1b9501ec1d2999f"]]},{"id":"c5bbb4667271a7ba","type":"debug","z":"615fe651fd6e3ca8","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":40,"wires":[]},{"id":"aacf422.35ac2c","type":"server","name":"Home Assistant","addon":true}]

I use a different method to do this. I depend on the dwell time of the motion sensor to tell me when there is no motion.

image

[{"id":"97e6a3ea.2d8cd","type":"api-call-service","z":"fe1a8042.af255","name":"Garage Light On","server":"f3f422ce.9f2a6","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.garagelightswitch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":310,"y":191,"wires":[["4e0859a3.102238"]]},{"id":"4ff57502.55030c","type":"api-call-service","z":"fe1a8042.af255","name":"Garage Light Off","server":"f3f422ce.9f2a6","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.garagelightswitch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":519,"y":248,"wires":[[]]},{"id":"a1f8653c.15a248","type":"trigger-state","z":"fe1a8042.af255","name":"Garage Motion","server":"f3f422ce.9f2a6","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.garage_motion_motion","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"},{"targetType":"entity_id","targetValue":"switch.garagelightswitch","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off","propertyValue":"new_state.state"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":102,"y":191,"wires":[["97e6a3ea.2d8cd"],[]]},{"id":"4e0859a3.102238","type":"ha-wait-until","z":"fe1a8042.af255","name":"No Motion","server":"f3f422ce.9f2a6","version":2,"outputs":1,"entityId":"binary_sensor.garage_motion_motion","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"0","timeoutType":"num","timeoutUnits":"minutes","checkCurrentState":true,"blockInputOverrides":true,"outputProperties":[],"x":290,"y":249,"wires":[["4ff57502.55030c"]]},{"id":"f3f422ce.9f2a6","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Interesting based on the times on your output flow nodes it looks like it did work. Are you able to manually trigger the output nodes and see if the light comes on / off. I do a very similar thing for house numbers.

I have been using this logic/flow for over a year without any problems - it works great.

I am not sure what you mean. But, I can manually turn the lights on / off from the HA Dashboard and I can control the lights with the actual physical light switches.

Copy the code I provided and import it into node-red. You should be able to read, edit/modify, and test it for yourself.

My recommendation is to connect a node like this to each of your outputs. If you click the node it will be true and fire the corresponding output. Unfortunately I am no were near my system to do any testing. I normally use this manual trigger node to ensure my output is working. Based on the time interval on your output nodes, it looks like they are firing but likely on output node configuration issue.
1000000568

Are you trying to turn_off two things?
You have both a device and an entity in your service calls.

Thanks for all your responses. I tested your flow, but now the lamp carport is not triggered at all.

As you can see, motion is detected, but nothing else happens.

Below my settings.

[{"id":"ec192952b0a7598e","type":"tab","label":"Carport","disabled":false,"info":"","env":[]},{"id":"97e6a3ea.2d8cd","type":"api-call-service","z":"ec192952b0a7598e","name":"Spotjes carport aan","server":"22f5da40.d3e236","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":["8a015b781931d1123e70e0200292a4d4"],"entityId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":350,"y":340,"wires":[["4e0859a3.102238"]]},{"id":"4ff57502.55030c","type":"api-call-service","z":"ec192952b0a7598e","name":"Sportjes carport uit","server":"aacf422.35ac2c","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":["8a015b781931d1123e70e0200292a4d4"],"entityId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":530,"y":420,"wires":[[]]},{"id":"a1f8653c.15a248","type":"trigger-state","z":"ec192952b0a7598e","name":"Sensor carport","server":"22f5da40.d3e236","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.0x00158d00047b8551_illuminance","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"switch.shelly1_b8bdd2","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":102,"y":340,"wires":[["97e6a3ea.2d8cd"],[]]},{"id":"4e0859a3.102238","type":"ha-wait-until","z":"ec192952b0a7598e","name":"Geen beweging","server":"22f5da40.d3e236","version":2,"outputs":1,"entityId":"sensor.0x00158d00047b8551_illuminance","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"0","timeoutType":"num","timeoutUnits":"minutes","checkCurrentState":true,"blockInputOverrides":true,"outputProperties":[],"x":300,"y":420,"wires":[["4ff57502.55030c"]]},{"id":"22f5da40.d3e236","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"aacf422.35ac2c","type":"server","name":"Home Assistant","addon":true}]

You are right, at one point I tried everything to get the error to surface. If I remove one of two, it still makes no difference.

Since I also want to do more in node-red in the future, I’m also just curious why it won’t work in this situation.

I tried your tip. As you can see, the inject-node does allow me to turn off the lamp.

I don’t get it: motion is recognized, the lamp is turned on, I can see that the motion detector returns to false, but the lamp is not turned off…

What I also find strange is that the same flow in the utility room and garage does work.

Sometimes the output of one node fits with the override values in the message for the next one.

What happens if you use the entity (switch.shelly1_b8bdd2) instead of the device in the flow I provided?

Thanks for the suggestion and thinking along, but you won’t believe where the error was. I had another Aqara motion sensor and thought to test if maybe the motion sensor in the carport was faulty. And you won’t believe it, but with the new sensor the flow immediately worked flawlessly. Too bad about all the energy I put into the research, but well, another lesson learned.

Thanks again to you and everyone who contributed and have a nice Sunday.

1 Like

That was going to be my next suggestion if the entity substitution did not work. Sometimes it is a hardware problem :slightly_smiling_face: