node-red-contrib-presence-faker
node-red-contrib-presence-faker copied to clipboard
Stop schedule
Hi, Based on a boolean vacation mode I wanted to start and stop a presence faker process. The start part is all right. But when I set the vacation mode to false, the ongoing schedule keeps continuing until the last block. I would grately apreciate your help on this.
Thanks for your help.
Hi @fabienouwerx, Would you mind sharing your flow export?
In the meantime I have found some kind of solution (probably not the most efficient one) with a 'change' module. My target or issue is that, when a cycle of presence faker is ongoing, that a change from vacation mode to false stops the current cycle and turns all lights to off.
[{"id":"5544dd74a0fa84e6","type":"debug","z":"66066be0a5294fed","name":"Debug Random","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1200,"y":60,"wires":[]},{"id":"8e0d4f97125367f2","type":"api-call-service","z":"66066be0a5294fed","name":"Buanderie","server":"a4262908.99bf68","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"{{payload}}","entityId":"light.buanderie","data":"{}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":880,"y":60,"wires":[["5544dd74a0fa84e6"]]},{"id":"4a180df428757f2d","type":"api-call-service","z":"66066be0a5294fed","name":"S-d-B","server":"a4262908.99bf68","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"{{payload}}","entityId":"light.s_d_b","data":"{}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":140,"wires":[["5544dd74a0fa84e6"]]},{"id":"98e5fd6709041d1a","type":"api-call-service","z":"66066be0a5294fed","name":"Bureau Axelle","server":"a4262908.99bf68","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"{{payload}}","entityId":"light.halogene_bureau_axelle","data":"{}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":220,"wires":[["5544dd74a0fa84e6"]]},{"id":"a647ab1344218e40","type":"presence-faker","z":"66066be0a5294fed","name":"Random Buanderie","onPayload":"turn_on","onPayloadType":"str","onTopic":"light.buanderie","offPayload":"turn_off","offPayloadType":"str","offTopic":"light.buanderie","windowBegin":"16:30","windowEnd":"23:50","minDurationHours":0,"minDurationMinutes":"3","minDurationSeconds":"0","minDuration":"180","maxDurationHours":0,"maxDurationMinutes":"20","maxDurationSeconds":"0","maxDuration":"1200","minCount":"15","maxCount":"30","startupBehavior":"onMsg","actionOnDisable":"off","firstBlockType":"off","lastBlockType":"off","isLoggingEnabled":true,"x":590,"y":60,"wires":[["8e0d4f97125367f2"]]},{"id":"c38ed071f30ac87c","type":"presence-faker","z":"66066be0a5294fed","name":"Random S-d-B","onPayload":"turn_on","onPayloadType":"str","onTopic":"light.buanderie","offPayload":"turn_off","offPayloadType":"str","offTopic":"light.buanderie","windowBegin":"16:30","windowEnd":"23:50","minDurationHours":0,"minDurationMinutes":"10","minDurationSeconds":"0","minDuration":"600","maxDurationHours":0,"maxDurationMinutes":"40","maxDurationSeconds":"0","maxDuration":"2400","minCount":"4","maxCount":"10","startupBehavior":"onMsg","actionOnDisable":"off","firstBlockType":"off","lastBlockType":"off","isLoggingEnabled":true,"x":580,"y":140,"wires":[["4a180df428757f2d"]]},{"id":"4b3b5b37441d1a9c","type":"presence-faker","z":"66066be0a5294fed","name":"Random Bureau Axelle","onPayload":"turn_on","onPayloadType":"str","onTopic":"light.buanderie","offPayload":"turn_off","offPayloadType":"str","offTopic":"light.buanderie","windowBegin":"19:00","windowEnd":"23:50","minDurationHours":0,"minDurationMinutes":"20","minDurationSeconds":"0","minDuration":"1200","maxDurationHours":"1","maxDurationMinutes":"35","maxDurationSeconds":"0","maxDuration":"5700","minCount":"2","maxCount":"5","startupBehavior":"onMsg","actionOnDisable":"off","firstBlockType":"off","lastBlockType":"off","isLoggingEnabled":true,"x":600,"y":220,"wires":[["98e5fd6709041d1a"]]},{"id":"a9c4f74fa98170ac","type":"change","z":"66066be0a5294fed","name":"Disable Random","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":220,"wires":[["a647ab1344218e40","c38ed071f30ac87c","4b3b5b37441d1a9c"]]},{"id":"a91bf7840aee1964","type":"eztimer","z":"66066be0a5294fed","name":"","debug":true,"autoname":"goldenHour - 23:47:00","tag":"eztimer","topic":"","suspended":false,"sendEventsOnSuspend":false,"latLongSource":"manual","latLongHaZone":"zone.home","lat":"50.8503396","lon":"4.3517103","timerType":"1","startupMessage":true,"ontype":"1","ontimesun":"goldenHour","ontimetod":"17:00","onpropertytype":"msg","onproperty":"payload","onvaluetype":"str","onvalue":"true","onoffset":"-17","onrandomoffset":true,"onsuppressrepeats":false,"offtype":"2","offtimesun":"night","offtimetod":"23:47:00","offduration":"00:01:00","offpropertytype":"msg","offproperty":"payload","offvaluetype":"str","offvalue":"false","offoffset":"15","offrandomoffset":true,"offsuppressrepeats":false,"resend":false,"resendInterval":"1m","mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":340,"y":60,"wires":[["a647ab1344218e40","c38ed071f30ac87c","4b3b5b37441d1a9c"]]},{"id":"33df41102e5d899d","type":"server-state-changed","z":"66066be0a5294fed","name":"Vacation Mode On","server":"a4262908.99bf68","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.vacation_mode","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,"outputProperties":[{"property":"payload","propertyType":"msg","value":"trigger","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":260,"wires":[["a91bf7840aee1964","25aa18859c266f54"],["a9c4f74fa98170ac","05fdd43a4b0f9e30"]]},{"id":"25aa18859c266f54","type":"change","z":"66066be0a5294fed","name":"Auto","rules":[{"t":"set","p":"payload","pt":"msg","to":"auto","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":300,"wires":[["701d90827b98ce03","f7956d46c7fa01ce","6491b9e84f505c07"]]},{"id":"05fdd43a4b0f9e30","type":"change","z":"66066be0a5294fed","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":540,"wires":[["701d90827b98ce03","f7956d46c7fa01ce","6491b9e84f505c07"]]},{"id":"701d90827b98ce03","type":"light-scheduler","z":"66066be0a5294fed","settings":"82c0a865c2221645","events":"[{"start":{"dow":5,"mod":915},"end":{"dow":5,"mod":1405}},{"start":{"dow":6,"mod":910},"end":{"dow":6,"mod":1420}},{"start":{"dow":0,"mod":905},"end":{"dow":0,"mod":1390}},{"start":{"dow":3,"mod":900},"end":{"dow":3,"mod":1390}},{"start":{"dow":2,"mod":905},"end":{"dow":2,"mod":1360}},{"start":{"dow":1,"mod":905},"end":{"dow":1,"mod":1375}},{"start":{"dow":4,"mod":935},"end":{"dow":4,"mod":1395}}]","topic":"","name":"Timer Hall","onPayload":"turn_on","onPayloadType":"str","offPayload":"turn_off","offPayloadType":"str","onlyWhenDark":true,"scheduleRndMax":"20","sunElevationThreshold":"6","sunShowElevationInStatus":true,"outputfreq":"output.statechange","x":560,"y":300,"wires":[["43814fee6263934e"]]},{"id":"f7956d46c7fa01ce","type":"light-scheduler","z":"66066be0a5294fed","settings":"82c0a865c2221645","events":"[{"start":{"dow":1,"mod":455},"end":{"dow":1,"mod":500}},{"start":{"dow":2,"mod":470},"end":{"dow":2,"mod":510}},{"start":{"dow":3,"mod":460},"end":{"dow":3,"mod":500}},{"start":{"dow":4,"mod":455},"end":{"dow":4,"mod":495}},{"start":{"dow":5,"mod":470},"end":{"dow":5,"mod":505}},{"start":{"dow":6,"mod":485},"end":{"dow":6,"mod":515}}]","topic":"","name":"Timer S-d-B AM","onPayload":"turn_on","onPayloadType":"str","offPayload":"turn_off","offPayloadType":"str","onlyWhenDark":true,"scheduleRndMax":"5","sunElevationThreshold":"0","sunShowElevationInStatus":true,"outputfreq":"output.statechange","x":580,"y":540,"wires":[["e1efa66813d3fb1a"]]},{"id":"6491b9e84f505c07","type":"light-scheduler","z":"66066be0a5294fed","settings":"82c0a865c2221645","events":"[{"start":{"dow":1,"mod":905},"end":{"dow":1,"mod":1400}},{"start":{"dow":2,"mod":905},"end":{"dow":2,"mod":1405}},{"start":{"dow":3,"mod":900},"end":{"dow":3,"mod":1380}},{"start":{"dow":4,"mod":905},"end":{"dow":4,"mod":1415}},{"start":{"dow":5,"mod":905},"end":{"dow":5,"mod":1425}},{"start":{"dow":6,"mod":900},"end":{"dow":0,"mod":0}},{"start":{"dow":0,"mod":905},"end":{"dow":0,"mod":1370}},{"start":{"dow":1,"mod":450},"end":{"dow":1,"mod":540}},{"start":{"dow":2,"mod":450},"end":{"dow":2,"mod":540}},{"start":{"dow":3,"mod":465},"end":{"dow":3,"mod":540}},{"start":{"dow":4,"mod":445},"end":{"dow":4,"mod":540}},{"start":{"dow":5,"mod":460},"end":{"dow":5,"mod":540}},{"start":{"dow":6,"mod":480},"end":{"dow":6,"mod":540}},{"start":{"dow":0,"mod":505},"end":{"dow":0,"mod":560}}]","topic":"","name":"Timer Cuisine & Aquarium AM","onPayload":"turn_on","onPayloadType":"str","offPayload":"turn_off","offPayloadType":"str","onlyWhenDark":true,"scheduleRndMax":"15","sunElevationThreshold":"6","sunShowElevationInStatus":true,"outputfreq":"output.statechange","x":630,"y":460,"wires":[["98b93e6cbb406b19"]]},{"id":"43814fee6263934e","type":"api-call-service","z":"66066be0a5294fed","name":"Hall","server":"a4262908.99bf68","version":3,"debugenabled":true,"service_domain":"homeassistant","service":"{{payload}}","entityId":"light.hall","data":"{}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":300,"wires":[["94849a38e5019a9c"]]},{"id":"e1efa66813d3fb1a","type":"api-call-service","z":"66066be0a5294fed","name":"S-d-B","server":"a4262908.99bf68","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"{{payload}}","entityId":"light.s_d_b","data":"{}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":540,"wires":[["94849a38e5019a9c"]]},{"id":"98b93e6cbb406b19","type":"api-call-service","z":"66066be0a5294fed","name":"Cuisine, Aquarium","server":"a4262908.99bf68","version":3,"debugenabled":false,"service_domain":"homeassistant","service":"{{payload}}","entityId":"light.cuisine, light.aquarium","data":"{}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":380,"wires":[["94849a38e5019a9c"]]},{"id":"94849a38e5019a9c","type":"debug","z":"66066be0a5294fed","name":"Debug Timer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1180,"y":300,"wires":[]},{"id":"8d1a931dc1d1e3d8","type":"light-scheduler","z":"66066be0a5294fed","settings":"82c0a865c2221645","events":"[{"start":{"dow":1,"mod":905},"end":{"dow":1,"mod":1400}},{"start":{"dow":2,"mod":905},"end":{"dow":2,"mod":1405}},{"start":{"dow":3,"mod":900},"end":{"dow":3,"mod":1380}},{"start":{"dow":4,"mod":905},"end":{"dow":4,"mod":1415}},{"start":{"dow":5,"mod":905},"end":{"dow":5,"mod":1425}},{"start":{"dow":6,"mod":900},"end":{"dow":0,"mod":0}},{"start":{"dow":0,"mod":905},"end":{"dow":0,"mod":1370}}]","topic":"","name":"Timer Cuisine & Aquarium PM","onPayload":"turn_on","onPayloadType":"str","offPayload":"turn_off","offPayloadType":"str","onlyWhenDark":true,"scheduleRndMax":"15","sunElevationThreshold":"6","sunShowElevationInStatus":true,"outputfreq":"output.statechange","x":630,"y":380,"wires":[["98b93e6cbb406b19"]]},{"id":"a4262908.99bf68","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":"82c0a865c2221645","type":"light-scheduler-settings","name":"Brussels","latitude":"50.8166144","longitude":"4.3646976"}]
Sending a payload of false should do the trick. Here's a list of items to send to enable/disable this: https://github.com/csuermann/node-red-contrib-presence-faker/blob/db38ebacb4f714a1180eb1241492bb90dccc1e1d/presence-faker.js#L198
Thanks for your help. Could you be a bit more explicit on how a false payload could be sent? I'm quite a rookie with Node-red and HA as a whole.
Thanks a lot!
Here's a snippet of the flow that works for me. The first switch gets input from a Home Assitant input boolean if the house is empty or not. This sends "on"/"off", which presence-faker doesn't know what to do with. This first switch converts this to boolean true/false. For you to play with, I added 2 injection nodes to send "on"/"off" through the switch, and 2 injection nodes to send True/False boolean directly to presence-faker. You should be able to adapt this to your flow.
Lastly, I had to add a switch to the output of the presence-faker node as it seems the Home Assitant did not like "{{payload}}" for the service field. This 'hack' gets around the issue of the lights not properly turning on/off. An additional side benefit is that you can include attributes to send to the lights on/off, such as brightness, color, transition, etc.
Hope this helps you. Import (ctrl-i) the following into your node-red:
[{"id":"ce56b5c52f0fc95b","type":"inject","z":"8675964a94df30b1","name":"on","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":150,"y":320,"wires":[["53308bf4caca1b9b"]]},{"id":"fa2f656e07657fcb","type":"inject","z":"8675964a94df30b1","name":"off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":150,"y":400,"wires":[["53308bf4caca1b9b"]]},{"id":"53308bf4caca1b9b","type":"change","z":"8675964a94df30b1","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":360,"wires":[["d0ce6b687d5be031"]]},{"id":"d0ce6b687d5be031","type":"presence-faker","z":"8675964a94df30b1","name":"Entrance Light","onPayload":"turn_on","onPayloadType":"str","onTopic":"light.entry","offPayload":"turn_off","offPayloadType":"str","offTopic":"light.entry","windowBegin":"17:00","windowEnd":"01:00","minDurationHours":0,"minDurationMinutes":"3","minDurationSeconds":"10","minDuration":"190","maxDurationHours":0,"maxDurationMinutes":"5","maxDurationSeconds":"15","maxDuration":"315","minCount":"10","maxCount":"15","startupBehavior":"onMsg","actionOnDisable":"off","firstBlockType":"off","lastBlockType":"off","isLoggingEnabled":false,"x":540,"y":360,"wires":[["68850604da9a82d4"]]},{"id":"68850604da9a82d4","type":"switch","z":"8675964a94df30b1","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"turn_on","vt":"str"},{"t":"eq","v":"turn_off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":360,"wires":[["3980b7ea8686cd81"],["4869f7c9a380758e"]]},{"id":"3980b7ea8686cd81","type":"api-call-service","z":"8675964a94df30b1","name":"Faker lights control on","server":"297f3107.45965e","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{topic}}"],"data":"{"brightness_pct": "100"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":340,"wires":[[]]},{"id":"4869f7c9a380758e","type":"api-call-service","z":"8675964a94df30b1","name":"Faker lights control off","server":"297f3107.45965e","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":[],"entityId":["{{topic}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":380,"wires":[[]]},{"id":"83d014c9907e88c7","type":"inject","z":"8675964a94df30b1","name":"true","props":[{"p":"payload"},{"p":"topic","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":350,"y":300,"wires":[["d0ce6b687d5be031"]]},{"id":"b75693a4b14746ea","type":"inject","z":"8675964a94df30b1","name":"false","props":[{"p":"payload"},{"p":"topic","v":"false","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":350,"y":420,"wires":[["d0ce6b687d5be031"]]},{"id":"297f3107.45965e","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"}]