# Right way/better way: action if other entity inactive "recently"

**URL:** <https://discourse.nodered.org/t/right-way-better-way-action-if-other-entity-inactive-recently/59029>\
**Category:** General\
**Created:** [26 February 2022 16:29 UTC](https://discourse.nodered.org/t/right-way-better-way-action-if-other-entity-inactive-recently/59029 "2022-02-26T16:29:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sblessley](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sblessley/32/57464_2.png) [@sblessley](https://discourse.nodered.org/u/sblessley)\
**Post date:** [26 February 2022 16:29 UTC](https://discourse.nodered.org/t/right-way-better-way-action-if-other-entity-inactive-recently/59029/1 "2022-02-26T16:29:21Z")

</div>

Noob here. I have two sensors, a PIR sensor outdoors, and a door switch. I want to trigger a response if there is motion sensed _but the door sensor hasn't been triggered just before_. The use-case is somebody's left a package at the door, but not when opening the door to fetch it.

I thought of having a state node change the message payload to an empty string, but that seems like a hack. What's the right way?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [26 February 2022 16:57 UTC](https://discourse.nodered.org/t/right-way-better-way-action-if-other-entity-inactive-recently/59029/2 "2022-02-26T16:57:27Z")

</div>

Hi @sblessley,

Here is _one_ way, not sure it's the _best_ way, using node-red-contrib-simple-gate to block or pass messages. You can install the node via the hamburger menu Manage Palette option.

 ![Untitled 5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95d8f73479bde6d8c13aadb9c657487487e5075e.jpeg)

```auto
[{"id":"ef953fdf48b0e4ef","type":"group","z":"6067dcc19d4df957","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["0882ed954c72e44f","ef17d4824ad7e50a","c9e1dc67254f1578","0b51da2be9330f6a","5ad883d03ca32e20","42bb894e40fd83c9"],"x":34,"y":39,"w":972,"h":122},{"id":"0882ed954c72e44f","type":"inject","z":"6067dcc19d4df957","g":"ef953fdf48b0e4ef","name":"Door sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":80,"wires":[["c9e1dc67254f1578"]]},{"id":"ef17d4824ad7e50a","type":"inject","z":"6067dcc19d4df957","g":"ef953fdf48b0e4ef","name":"PIR sensor","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":120,"wires":[["0b51da2be9330f6a"]]},{"id":"c9e1dc67254f1578","type":"trigger","z":"6067dcc19d4df957","g":"ef953fdf48b0e4ef","name":"","op1":"close","op2":"open","op1type":"str","op2type":"str","duration":"2","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":330,"y":80,"wires":[["42bb894e40fd83c9"]]},{"id":"0b51da2be9330f6a","type":"gate","z":"6067dcc19d4df957","g":"ef953fdf48b0e4ef","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":690,"y":120,"wires":[["5ad883d03ca32e20"]]},{"id":"5ad883d03ca32e20","type":"debug","z":"6067dcc19d4df957","g":"ef953fdf48b0e4ef","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":120,"wires":[]},{"id":"42bb894e40fd83c9","type":"change","z":"6067dcc19d4df957","g":"ef953fdf48b0e4ef","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":80,"wires":[["0b51da2be9330f6a"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 April 2022 16:58 UTC](https://discourse.nodered.org/t/right-way-better-way-action-if-other-entity-inactive-recently/59029/3 "2022-04-27T16:58:13Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
