# State changed duration

**URL:** <https://discourse.nodered.org/t/state-changed-duration/8592>\
**Category:** General\
**Created:** [4 March 2019 13:05 UTC](https://discourse.nodered.org/t/state-changed-duration/8592 "2019-03-04T13:05:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel1411](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@daniel1411](https://discourse.nodered.org/u/daniel1411)\
**Post date:** [4 March 2019 13:05 UTC](https://discourse.nodered.org/t/state-changed-duration/8592/1 "2019-03-04T13:05:53Z")

</div>

Hi

i using [Hass.io](http://Hass.io) and Node red, and i want to create the following flow:

## State Sensor X Change to Y

I want to create split/flow that if time is \< 20 min from state change go to 1 and if not go to 2

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [4 March 2019 13:13 UTC](https://discourse.nodered.org/t/state-changed-duration/8592/2 "2019-03-04T13:13:57Z")

</div>

These examples in the cookbook will be of help

[https://cookbook.nodered.org/basic/route-on-context](https://cookbook.nodered.org/basic/route-on-context)

[https://cookbook.nodered.org/basic/trigger-timeout](https://cookbook.nodered.org/basic/trigger-timeout)

---

<div class="post-metadata">

**Author:** ![daniel1411](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@daniel1411](https://discourse.nodered.org/u/daniel1411)\
**Post date:** [5 March 2019 19:39 UTC](https://discourse.nodered.org/t/state-changed-duration/8592/3 "2019-03-05T19:39:17Z")

</div>

Tnx for the response but according to this  
i can call/set node if i didnt get response more than X time

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c2f8404320c8f3f7002b6006a308f47e811022c6.png)

i want for example create the following flow.

Door sensor open -\> the node should check if the Boolean (state) was change to home more than 30 min  
do do action X if less open the light.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [5 March 2019 20:57 UTC](https://discourse.nodered.org/t/state-changed-duration/8592/4 "2019-03-05T20:57:37Z")

</div>

Flow 1 (home in last 30 mins)  
`What ever you want -[Trigger]-[Change Node to set global value]`

Trigger node Send true then wait for 30 minutes then send false  
So if triggered in the last 30 mins global value is true otherwise false

Flow 2  
`Door sensor open -[switch node to check global value]----`  
If global value is true do something otherwise don't

---

<div class="post-metadata">

**Author:** ![daniel1411](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@daniel1411](https://discourse.nodered.org/u/daniel1411)\
**Post date:** [6 March 2019 19:21 UTC](https://discourse.nodered.org/t/state-changed-duration/8592/5 "2019-03-06T19:21:22Z")

</div>

Which node did you use? Possible to paste an example here please I am new in the field.

Tnx  
!

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [6 March 2019 19:53 UTC](https://discourse.nodered.org/t/state-changed-duration/8592/6 "2019-03-06T19:53:45Z")

</div>

The trigger and change node and the switch node as per my last reply

---

<div class="post-metadata">

**Author:** ![slurpey](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/slurpey/32/16320_2.png) [@slurpey](https://discourse.nodered.org/u/slurpey)\
**Post date:** [8 July 2022 08:31 UTC](https://discourse.nodered.org/t/state-changed-duration/8592/7 "2022-07-08T08:31:02Z")

</div>

Hi, I tried my own ways only using nodes as I'm useless with anything more fancy and I think it works

For me, my flow is to try to detect when the cleaning lady is done. She hates light sensors and all that so I turn the whole house lights "on" and deactivate sensors at 9h00am on fridays - when she arrives. But sometimes she stays 1h30min, sometimes 4 hours. I wanted to switch all back to normal once she turns off the light beside the entrance door - triggering restart of automated stuff.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/6/d618a827dff84a3c09780689b62569f05d1d5738.png)

```auto
[{"id":"fd8614f35e5086dd","type":"ha-wait-until","z":"696f8303.5ee06c","name":"Wait until lights off","server":"a0eea9da.0fe1d8","version":1,"outputs":1,"entityId":"switch.hallsonoff","entityIdFilterType":"exact","property":"","comparator":"is","value":"off","valueType":"str","timeout":"0","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"data","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":610,"y":100,"wires":[["fbda29edbe577364"]]},{"id":"364a918cfc1fddfa","type":"api-current-state","z":"696f8303.5ee06c","name":"Light on for at least 60min","server":"a0eea9da.0fe1d8","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.hallsonoff","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"60","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":370,"y":120,"wires":[["fd8614f35e5086dd"],[]]},{"id":"a97e68170b634c05","type":"server-state-changed","z":"696f8303.5ee06c","name":"Hall light on","server":"a0eea9da.0fe1d8","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.hallsonoff","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"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":130,"y":120,"wires":[["364a918cfc1fddfa"],[]]},{"id":"fbda29edbe577364","type":"api-call-service","z":"696f8303.5ee06c","name":"Cleaning Lady not Home","server":"a0eea9da.0fe1d8","version":5,"debugenabled":false,"domain":"device_tracker","service":"see","areaId":[],"deviceId":[],"entityId":[],"data":"{\"dev_id\":\"asmert\",\"location_name\":\"not_home\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":890,"y":100,"wires":[[]]},{"id":"a0eea9da.0fe1d8","type":"server","name":"GOOD Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

```
