Hello all,
I need some assistance surrounding acquiring the first last_changed state of a person entity array. I am not looking for the home/not_home but rather when was the last time the state changed itself. I need to determine if the last state change was within the last 10 minutes. I can do this through a getHistory node but I need to combine multiple actions by checking multiple person(s) in a function.
Scenario:
Door unlocks, flow initiates, function checks to see which persons last_changed state has changed to “home” in the last 10 minutes, creates a welcome payload.msg for all person(s) who meet previous criteria and then announces TTS on supported device(s).
Anyone have a similar flow that can determine a time window for last changed in NR?
My poor attempt at trying to get at least the last_changed state status:
[{"id":"9e21ba5b.c58628","type":"inject","z":"f0fecdf0.b4cc9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":380,"wires":[["e4f3856b.c67928","4bf50d6c.ce5b44"]]},{"id":"e4f3856b.c67928","type":"api-get-history","z":"f0fecdf0.b4cc9","name":"Person","server":"f4c3f22d.c5133","startdate":"","enddate":"","entityid":"person.aaron","entityidtype":"is","useRelativeTime":false,"relativeTime":"","flatten":true,"output_type":"array","output_location_type":"msg","output_location":"payload","x":280,"y":260,"wires":[["3f073ad5.cefb76","fcb691ec.48db7"]]},{"id":"4bf50d6c.ce5b44","type":"function","z":"f0fecdf0.b4cc9","name":"","func":"const haCtx = global.get(\"homeassistant\");\nconst configCtx = haCtx.homeAssistant;\n\nconst aaron = configCtx.history[\"person.aaron\"];\nmsg=aaron;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":380,"wires":[[]]},{"id":"3f073ad5.cefb76","type":"change","z":"f0fecdf0.b4cc9","name":"send stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].last_changed","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":200,"wires":[["fcb691ec.48db7"]]},{"id":"fcb691ec.48db7","type":"debug","z":"f0fecdf0.b4cc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":140,"wires":[]},{"id":"f4c3f22d.c5133","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]