Enable vacuum only if it wasn't enabled at least the previous 60 min

Hello guys!


[{"id":"7b1eae33.e8bbd","type":"api-call-service","z":"e85ca6ad.06b898","name":"Turn On Limpiador","server":"17f27332.cbbb3d","version":5,"debugenabled":false,"domain":"vacuum","service":"start","areaId":[],"deviceId":[],"entityId":["vacuum.limpiador"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":770,"y":60,"wires":[[]]},{"id":"44c73cf4.7786a4","type":"api-current-state","z":"e85ca6ad.06b898","name":"Guest Mode","server":"17f27332.cbbb3d","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.guest_mode","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":410,"y":100,"wires":[[],["3e1271c9.4f15de"]]},{"id":"3e1271c9.4f15de","type":"time-range-switch","z":"e85ca6ad.06b898","name":"","lat":"42.31343","lon":"-7.88249","startTime":"08:00","endTime":"21:00","startOffset":0,"endOffset":0,"x":590,"y":100,"wires":[["7b1eae33.e8bbd"],[]]},{"id":"7a6fc414.26a8ec","type":"api-current-state","z":"e85ca6ad.06b898","name":"Vacuum docked?","server":"17f27332.cbbb3d","version":3,"outputs":2,"halt_if":"docked","halt_if_type":"str","halt_if_compare":"is","entity_id":"vacuum.limpiador","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":390,"y":40,"wires":[["44c73cf4.7786a4"],[]]},{"id":"f6f2d29a.12c0f","type":"comment","z":"e85ca6ad.06b898","name":"Limpiador","info":"","x":80,"y":100,"wires":[]},{"id":"b8a86c15.b9fe4","type":"server-state-changed","z":"e85ca6ad.06b898","name":"Home Occupancy < 10","server":"17f27332.cbbb3d","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.home_occupancy_confidence","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"10","halt_if_type":"num","halt_if_compare":"lt","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":140,"y":160,"wires":[["7a6fc414.26a8ec","32d591d.741ec6e"],["44d6caf1.fcbeb4"]]},{"id":"db432e5.2222bd","type":"inject","z":"e85ca6ad.06b898","name":"Start everyday at 10AM","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 10 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":280,"wires":[["d764f092.af3ca"]]},{"id":"d764f092.af3ca","type":"api-current-state","z":"e85ca6ad.06b898","name":"Vacation mode","server":"17f27332.cbbb3d","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.holiday_mode","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":380,"y":280,"wires":[["7a6fc414.26a8ec"],[]]},{"id":"e7fee426.60ca58","type":"comment","z":"e85ca6ad.06b898","name":"Limpiador on holidays","info":"","x":120,"y":240,"wires":[]},{"id":"32d591d.741ec6e","type":"api-call-service","z":"e85ca6ad.06b898","name":"Set fan speed Medium","server":"17f27332.cbbb3d","version":5,"debugenabled":false,"domain":"vacuum","service":"set_fan_speed","areaId":[],"deviceId":[],"entityId":["vacuum.limpiador"],"data":"{\"fan_speed\":\"Medium\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":660,"y":160,"wires":[[]]},{"id":"44d6caf1.fcbeb4","type":"api-call-service","z":"e85ca6ad.06b898","name":"Set fan speed Standard","server":"17f27332.cbbb3d","version":5,"debugenabled":false,"domain":"vacuum","service":"set_fan_speed","areaId":[],"deviceId":[],"entityId":["vacuum.limpiador"],"data":"{\"fan_speed\":\"Standard\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":670,"y":260,"wires":[[]]},{"id":"db64896e.450b68","type":"inject","z":"e85ca6ad.06b898","name":"manual speed set","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":930,"y":220,"wires":[["32d591d.741ec6e"]]},{"id":"76e787f2.b5cf08","type":"inject","z":"e85ca6ad.06b898","name":"manual speed set","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":890,"y":340,"wires":[["44d6caf1.fcbeb4"]]},{"id":"17f27332.cbbb3d","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

I currently have a nodered automation that enables my vacuum when no one is at home, between certain hour range and it changes the fan speed as well.

I’m trying to add another level of complexity by adding a new condition, only allow the vacuum run after all the other conditions met BUT also if the vacuum wasn’t running for at least the previous 60 minutes. This way I avoid the vacuum do one run after the other if I leave the home 2 minutes after it finished cleaning up.

Any light on how I can ever start researching this? thanks a lot!

Use the get history node, it should give you an array of all state changes.
I guess you need to use a function node to get the last time the state was running.

Or make use of a helper:
Define a helper boolean like “runwithinlasthour” and manually set this to false initially.
In your flow add a check for “runwithinlasthour” and only start the vacuum, if the value is false.
When you start the vacuum in your flow also set the helper to true.

Then all you have to do is defining another short automation which checks if the status of the helper has changed state to true for 60 minutes and in that case set it back to false.

Current state will give you timeSinceChangedMs. Send that into a switch node and set the value to > 3600000

image

If the last state change was cleaning.
If the device has more states, say unavailable then this fails.

That’s actually probably an easier solution. Set the current state to is idle for 60 minutes or whatever the rest state is after charging.

Depending on how log it charges for, you could also use not charging

image

Thinking about it, is not cleaning for 60 minutes should work.

image

Personally my vaccum only goes cleaning if it hasn’t cleaned during the last 20 hours. I created an input_boolean that acts as a switch and I use node-red-contrib-stoptimer-varidelay. The input boolean has the advantatge that you can place it somewhere in lovelace and enable/disable it manually as well to override the automatic config. On the other hand, varidelay persists any restart/deploy/whatever, so it’s great for long timespans like 20 hours and would even be safe to use with a 1 hour delay.

[{"id":"d03c4dc1.e0c3","type":"api-current-state","z":"504c4983.a509d8","name":"boolean on?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.ozma","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","x":1090,"y":260,"wires":[["68c28ebc.d62da","519c3d88.ef4274"],[]]},{"id":"68c28ebc.d62da","type":"api-call-service","z":"504c4983.a509d8","name":"boolean off","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"input_boolean.ozma","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1270,"y":220,"wires":[["7a2de815.3bf5b8"]]},{"id":"7a2de815.3bf5b8","type":"stoptimer-varidelay","z":"504c4983.a509d8","duration":"20","durationType":"num","units":"Hour","payloadtype":"num","payloadval":"0","name":"","reporting":"last_minute_seconds","persist":true,"x":1460,"y":220,"wires":[["ea086b11.39f1b8"],[],[]]},{"id":"ea086b11.39f1b8","type":"api-call-service","z":"504c4983.a509d8","name":"boolean on","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"input_boolean.ozma","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1650,"y":220,"wires":[[]]},{"id":"cfe6833f.17876","type":"inject","z":"504c4983.a509d8","name":"Trigger","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":950,"y":260,"wires":[["d03c4dc1.e0c3"]]},{"id":"519c3d88.ef4274","type":"api-call-service","z":"504c4983.a509d8","name":"vacuum on","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"vacuum","service":"start","entityId":"vacuum.ozma","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1270,"y":280,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

EDIT: applying it to your particular flow:
(you’ll still need the boolean and varidelay)

[{"id":"7b1eae33.e8bbd","type":"api-call-service","z":"504c4983.a509d8","name":"Turn On Limpiador","server":"17f27332.cbbb3d","version":5,"debugenabled":false,"service_domain":"vacuum","service":"start","entityId":["vacuum.limpiador"],"data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2910,"y":420,"wires":[[]]},{"id":"44c73cf4.7786a4","type":"api-current-state","z":"504c4983.a509d8","name":"Guest Mode","server":"17f27332.cbbb3d","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.guest_mode","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":2310,"y":420,"wires":[[],["3e1271c9.4f15de"]]},{"id":"3e1271c9.4f15de","type":"time-range-switch","z":"504c4983.a509d8","name":"","lat":"42.31343","lon":"-7.88249","startTime":"08:00","endTime":"21:00","startOffset":0,"endOffset":0,"x":2490,"y":420,"wires":[["a6bd0858.f3bf18"],[]]},{"id":"7a6fc414.26a8ec","type":"api-current-state","z":"504c4983.a509d8","name":"Vacuum docked?","server":"17f27332.cbbb3d","version":3,"outputs":2,"halt_if":"docked","halt_if_type":"str","halt_if_compare":"is","entity_id":"vacuum.limpiador","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":2290,"y":360,"wires":[["44c73cf4.7786a4"],[]]},{"id":"f6f2d29a.12c0f","type":"comment","z":"504c4983.a509d8","name":"Limpiador","info":"","x":1980,"y":420,"wires":[]},{"id":"b8a86c15.b9fe4","type":"server-state-changed","z":"504c4983.a509d8","name":"Home Occupancy < 10","server":"17f27332.cbbb3d","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.home_occupancy_confidence","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"10","halt_if_type":"num","halt_if_compare":"lt","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":2060,"y":480,"wires":[["7a6fc414.26a8ec","32d591d.741ec6e"],["44d6caf1.fcbeb4"]]},{"id":"db432e5.2222bd","type":"inject","z":"504c4983.a509d8","name":"Start everyday at 10AM","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 10 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1850,"y":300,"wires":[["d764f092.af3ca"]]},{"id":"d764f092.af3ca","type":"api-current-state","z":"504c4983.a509d8","name":"Vacation mode","server":"17f27332.cbbb3d","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.holiday_mode","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":2080,"y":300,"wires":[["7a6fc414.26a8ec"],[]]},{"id":"e7fee426.60ca58","type":"comment","z":"504c4983.a509d8","name":"Limpiador on holidays","info":"","x":2040,"y":240,"wires":[]},{"id":"32d591d.741ec6e","type":"api-call-service","z":"504c4983.a509d8","name":"Set fan speed Medium","server":"17f27332.cbbb3d","version":5,"debugenabled":false,"service":"set_fan_speed","entityId":["vacuum.limpiador"],"data":"{\"fan_speed\":\"Medium\"}","dataType":"json","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2400,"y":500,"wires":[[]]},{"id":"44d6caf1.fcbeb4","type":"api-call-service","z":"504c4983.a509d8","name":"Set fan speed Standard","server":"17f27332.cbbb3d","version":5,"debugenabled":false,"service":"set_fan_speed","entityId":["vacuum.limpiador"],"data":"{\"fan_speed\":\"Standard\"}","dataType":"json","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2410,"y":580,"wires":[[]]},{"id":"a6bd0858.f3bf18","type":"api-current-state","z":"504c4983.a509d8","name":"boolean on?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.ozma","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","x":2710,"y":400,"wires":[["db6200b3.bf668","7b1eae33.e8bbd"],[]]},{"id":"db6200b3.bf668","type":"api-call-service","z":"504c4983.a509d8","name":"boolean off","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"input_boolean.ozma","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2890,"y":360,"wires":[["e37e0e8.c375bf"]]},{"id":"e37e0e8.c375bf","type":"stoptimer-varidelay","z":"504c4983.a509d8","duration":"1","durationType":"num","units":"Hour","payloadtype":"num","payloadval":"0","name":"","reporting":"last_minute_seconds","persist":true,"ignoretimerpass":false,"x":3070,"y":360,"wires":[["4f0ffb35.65d394"],[],[]]},{"id":"4f0ffb35.65d394","type":"api-call-service","z":"504c4983.a509d8","name":"boolean on","server":"9405c3fe.d0a6c","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"input_boolean.ozma","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":3270,"y":360,"wires":[[]]},{"id":"17f27332.cbbb3d","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Thanks for all the replies guys! going to try it this weekend and see if I can make it work.

I think I found a way with my current flow that’s easy to implement. On my “Vacuum docked?” node, I just increased the state “is docked for” 60 minutes.

Now it will only pass the message if the entity has been in the docked state for at least 60 minutes.

I tried it after a few minutes and the vacuum didn’t start so it worked, however, I’m not sure if these 60 minutes have to be exact, or can it be 60 minutes or more for the node to pass on the message?

60 or more

coooool! then it should work!