Status of two sensors and light

There are two sensors, one for door opening, the second for movement, as well as a smart switch.
I would like to organize the lights to turn on when both sensors are triggered.
I roughly think of this option: when the door opening sensor is triggered, the motion sensor is checked, if it has the status on, then the light turns on, if one sensor is triggered, nothing happens, when the status of both sensors is off, then the light turns off after a specified period of time ( for example 30 seconds).
Also, as long as the motion sensor sees movement, the light should be turned on.
I hope I explained it clearly.

So far I’m getting what I planned for one sensor at a time, but I can’t figure out how to do it for both to work at once.

[{"id":"bd7f71118b5611ad","type":"tab","label":"КоридорВ","disabled":false,"info":"","env":[]},{"id":"3b94d100d90ff95e","type":"server-state-changed","z":"bd7f71118b5611ad","name":"dver_open","server":"10cea322.6322ad","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.vkhodnaia_dver","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","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":60,"y":100,"wires":[["8d3bcef4171922d4"],["8d3bcef4171922d4"]]},{"id":"8d3bcef4171922d4","type":"switch","z":"bd7f71118b5611ad","name":"on and off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":100,"wires":[["8c1edcd7854ed093","4f3043aef367efb3"],["28d2c598e77f179d"]]},{"id":"8c1edcd7854ed093","type":"api-current-state","z":"bd7f71118b5611ad","name":"light_koridorv","server":"10cea322.6322ad","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.koridorv_switch_1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":490,"y":80,"wires":[["1e58987b9ed3f457"],[]]},{"id":"1e58987b9ed3f457","type":"api-call-service","z":"bd7f71118b5611ad","name":"On","server":"10cea322.6322ad","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.koridorv_switch_1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":80,"wires":[[]]},{"id":"28d2c598e77f179d","type":"trigger","z":"bd7f71118b5611ad","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"30","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":550,"y":200,"wires":[["7c7a1c5599ca71d8"]]},{"id":"7c7a1c5599ca71d8","type":"api-call-service","z":"bd7f71118b5611ad","name":"Off","server":"10cea322.6322ad","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.koridorv_switch_1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":530,"y":280,"wires":[[]]},{"id":"4f3043aef367efb3","type":"change","z":"bd7f71118b5611ad","name":"Stop","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":140,"wires":[["28d2c598e77f179d"]]},{"id":"f478a503e847d2d8","type":"server-state-changed","z":"bd7f71118b5611ad","name":"motion_vxod","server":"10cea322.6322ad","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.unknown_vkhod","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","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":70,"y":160,"wires":[["8d3bcef4171922d4"],["8d3bcef4171922d4"]]},{"id":"10cea322.6322ad","type":"server","name":"Home Assistant","addon":true}]

I ask for help in solving this problem.

Does there need to be a delay between the opening of the door and checking for motion? Without knowing the layout, I can imagine that you would need to get into the room for the motion sensor to be triggered - otherwise the flow will check for motion as soon as the door sensor is triggered, find none, and then it will stop.
Happy to help a little further once we work out just how you would like this to work.

I didn’t even think about this, but it’s possible that there might be a delay in triggering something that isn’t quite correct, but I can suggest another option, there are two motion sensors, one inside the room, the other outside the room, you can probably check for one of the two motion sensors , probably this will make the response more accurate, unless of course it’s more complicated than a delay.

You can use jsonata for the condition and make it so both entities have to be off/on.

Edit: You can use more than 2 entities, add to the entity list then use and to add in the jsonata

(entity1) and (entity2) and (entity3)
$entities('light.dj').state = 'off' and $entities('sensor.kitchen_motion').state = 'off'

Does the door being open actually matter at all? Could there be motion inside the room, that you wouldn’t want to turn the light on for?

Seems like you could use the door opening to turn the light on, and if there is no motion inside the room for 30secs, then turn it off. If there is motion, keep resetting the timer. I wonder if there is a little bit of over-complication happening here?

Alas, this method did not help, the light turns on whenever the sensors are triggered, if you open the door, but there is no movement, the light turns on and if there is movement, but the door is closed, then the light still turns on.
But it is necessary for the light to turn on if the door is open and movement is detected.

[{"id":"3b94d100d90ff95e","type":"server-state-changed","z":"bd7f71118b5611ad","name":"dver_open","server":"10cea322.6322ad","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":["binary_sensor.vkhodnaia_dver","binary_sensor.unknown_vkhod"],"entityIdType":"list","outputInitially":false,"stateType":"str","ifState":"$entities('binary_sensor.vkhodnaia_dver').state = 'on' and $entities('binary_sensor.unknown_vkhod').state = 'on'","ifStateType":"jsonata","ifStateOperator":"jsonata","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","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":60,"y":100,"wires":[["8d3bcef4171922d4"],["8d3bcef4171922d4"]]},{"id":"10cea322.6322ad","type":"server","name":"Home Assistant","addon":true}]

It does, because there is often movement in the room and there is no need to turn it on just because of movement.

By the way, it’s a good idea, but it’s probably better to do it this way.
Tell me how to do this?

Ok, seems strange but sure, we can make it work.

If the door is open, but there is no motion, do you want the light to remain on?

That’s it, I seem to have done it myself as you advised above, at least it works, the door opens and the light turns on, the door closes and the 30-second countdown begins, and if movement is detected inside the room, the timer is reset until the movement ends.
I think this will suit me, thank you very much for the hint on how to work.

[{"id":"4c8ff9cb098b83c1","type":"server-state-changed","z":"bd7f71118b5611ad","name":"motion_vhod","server":"10cea322.6322ad","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.unknown_vkhod","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","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":70,"y":180,"wires":[["ad7cab79b4e5fdc3"],["ad7cab79b4e5fdc3"]]},{"id":"10cea322.6322ad","type":"server","name":"Home Assistant","addon":true}]

Perhaps I did something primitive and could have been done in smaller blocks, but as far as I know Node-Red, that’s what I did)))
And most importantly it works.

You last post seems to only have the one node in it - if you post the entire flow perhaps someone might be able to suggest improvements or efficiencies?

Glad to hear you got it working ok though.

Why alone? Here are the door open sensor and motion sensor

[{"id":"bd7f71118b5611ad","type":"tab","label":"КоридорВ","disabled":false,"info":"","env":[]},{"id":"3b94d100d90ff95e","type":"server-state-changed","z":"bd7f71118b5611ad","name":"dver_open","server":"10cea322.6322ad","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.vkhodnaia_dver","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","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":60,"y":100,"wires":[["8d3bcef4171922d4"],["8d3bcef4171922d4"]]},{"id":"8d3bcef4171922d4","type":"switch","z":"bd7f71118b5611ad","name":"on and off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":100,"wires":[["8c1edcd7854ed093"],["28d2c598e77f179d"]]},{"id":"8c1edcd7854ed093","type":"api-current-state","z":"bd7f71118b5611ad","name":"light_koridorv","server":"10cea322.6322ad","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.koridorv_switch_1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":490,"y":80,"wires":[["1e58987b9ed3f457"],[]]},{"id":"1e58987b9ed3f457","type":"api-call-service","z":"bd7f71118b5611ad","name":"On","server":"10cea322.6322ad","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.koridorv_switch_1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":80,"wires":[[]]},{"id":"28d2c598e77f179d","type":"trigger","z":"bd7f71118b5611ad","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"30","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":550,"y":200,"wires":[["7c7a1c5599ca71d8"]]},{"id":"7c7a1c5599ca71d8","type":"api-call-service","z":"bd7f71118b5611ad","name":"Off","server":"10cea322.6322ad","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.koridorv_switch_1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":530,"y":280,"wires":[[]]},{"id":"4f3043aef367efb3","type":"change","z":"bd7f71118b5611ad","name":"Stop","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":140,"wires":[["28d2c598e77f179d"]]},{"id":"4c8ff9cb098b83c1","type":"server-state-changed","z":"bd7f71118b5611ad","name":"motion_vhod","server":"10cea322.6322ad","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.unknown_vkhod","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":"0","forType":"num","forUnits":"minutes","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":70,"y":180,"wires":[["ad7cab79b4e5fdc3"],["ad7cab79b4e5fdc3"]]},{"id":"ad7cab79b4e5fdc3","type":"switch","z":"bd7f71118b5611ad","name":"on and off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":180,"wires":[["4f3043aef367efb3"],["28d2c598e77f179d"]]},{"id":"10cea322.6322ad","type":"server","name":"Home Assistant","addon":true}]