Node Red change trigger state from binary sensor

Hi there,

I have a question about a node red automation.
I created an automation for the light in the corridor.


The reason why I created the automation is, that I want to turn the light on in my corridor with to triggers.
First trigger is the motion sensor from Hue -> if occupancy turns from false to true.
This works with the correct time and turn off, when the the trigger state change from false to true.
The light is called light.deckenlampe_flur.
This is an shelly dimmer 2.
The second trigger I want to use is the switch of the shelly.
If I turn the light manually on, I want, that the light also use the rules which are from the motion sensor.

In my current automation I have the problem, that when I now turn on the light manually the counter starts immediatly.

Is there a way, that I can change the state from the binary sensor from false to true, if I turn on the light manually?
I tried different ways, but no one works…

Regards
Timo

Try this

1 Like

Thank you @mbonani
the flow works, but I have the same problem, i cannot change the state of the motion sensor…
I use the shelly with the stock firmware.
is this the problem?
or what I have to set up hier:

here is my code, maybe you can fix it?
[{"id":"af7416ee.37c178","type":"tab","label":"Flur Backup","disabled":true,"info":""},{"id":"1c73597d.5bfbdf","type":"switch","z":"af7416ee.37c178","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":180,"wires":[["cb6dcae0.000078"],["bff73bf3.6b1518"]]},{"id":"94211752.509d4","type":"api-call-service","z":"af7416ee.37c178","name":"Tag ","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":100}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1610,"y":80,"wires":[["bff73bf3.6b1518","996e74bc.e546"]]},{"id":"20686e7d.bb3402","type":"api-call-service","z":"af7416ee.37c178","name":"","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.deckenlampe_flur","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1650,"y":400,"wires":[["e5da13a5.70314"]]},{"id":"bff73bf3.6b1518","type":"trigger","z":"af7416ee.37c178","name":"","op1":"","op2":"off","op1type":"nul","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"true","bytopic":"all","topic":"topic","outputs":1,"x":1330,"y":340,"wires":[["20686e7d.bb3402"]]},{"id":"5f545cca.2c7614","type":"trigger-state","z":"af7416ee.37c178","name":"","server":"818794df.29c548","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.flur_bewegungsmeldung_occupancy","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"bool","comparatorValue":"true","propertyValue":"new_state.state"},{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"bool","comparatorValue":"false","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"habool","x":270,"y":80,"wires":[["1c73597d.5bfbdf"],["1c73597d.5bfbdf"]]},{"id":"996e74bc.e546","type":"api-call-service","z":"af7416ee.37c178","name":"","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.mikrowelle_on_off","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1930,"y":80,"wires":[[]]},{"id":"e5da13a5.70314","type":"api-call-service","z":"af7416ee.37c178","name":"","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.mikrowelle_on_off","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1910,"y":540,"wires":[[]]},{"id":"fb93c45b.161b9","type":"trigger","z":"af7416ee.37c178","name":"","op1":"","op2":"1","op1type":"nul","op2type":"str","duration":"1","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":480,"y":500,"wires":[["a5ad5640.15adc"]]},{"id":"cb6dcae0.000078","type":"time-range-switch","z":"af7416ee.37c178","name":"Tag","lat":"","lon":"","startTime":"6:30","endTime":"23:00","startOffset":0,"endOffset":0,"x":1290,"y":120,"wires":[["94211752.509d4"],["69b2e451.820ab4"]]},{"id":"69b2e451.820ab4","type":"api-call-service","z":"af7416ee.37c178","name":"Nacht","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":30}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1610,"y":200,"wires":[["bff73bf3.6b1518","996e74bc.e546"]]},{"id":"3ae1175c.893398","type":"api-call-service","z":"af7416ee.37c178","name":"Tag ","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":100}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":400,"wires":[["be1a8a8e.0dda48"]]},{"id":"679b5aff.b6b4dc","type":"api-call-service","z":"af7416ee.37c178","name":"Nacht","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.deckenlampe_flur","data":"{\"brightness_pct\":30}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":520,"wires":[["be1a8a8e.0dda48"]]},{"id":"a5ad5640.15adc","type":"time-range-switch","z":"af7416ee.37c178","name":"Tag","lat":"","lon":"","startTime":"6:30","endTime":"23:00","startOffset":0,"endOffset":0,"x":670,"y":460,"wires":[["3ae1175c.893398"],["679b5aff.b6b4dc"]]},{"id":"be1a8a8e.0dda48","type":"api-call-service","z":"af7416ee.37c178","name":"","server":"818794df.29c548","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.mikrowelle_on_off","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":420,"wires":[[]]},{"id":"d90859a9.395268","type":"server-state-changed","z":"af7416ee.37c178","name":"Deckenlampe Flur","server":"818794df.29c548","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.deckenlampe_flur","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","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,"x":150,"y":440,"wires":[["fb93c45b.161b9"],[]]},{"id":"818794df.29c548","type":"server","name":"Home Assistant","addon":true}]

Why do you want to change the state of the motion sensor?

If motion sensor detect movement (state change to occupancy true) the light (Shelly) turns on.

If the occupancy changes to false, timer will count down 5s and the light turns off.
The timer will be set back, if the occupancy changes the state from false to true within the count down (in this example 5s)

If I manually turn on the Shelly, I want also that after 5s the light turns off - except motion will be detected, than the above flow will start.

So far so good, but if I now add the Shelly as a normal switch and integrate it to the existing flow the counter starts immediately and there is no way to change the state from the motion sensor - neither I wave directly in front of the sensor.

So my thought was, to change the state of the occupancy if I turn on the light to start the existing (working) flow…