Hi, I am trying to calculate time difference between last_triggered time of a HA script with current date. I am stuck how to do it. Can anyone help me?
I want to flow to continue only if the last triggered time to current time is more then 2 days.
This is the script value I choose for testing this flow.
{"attributes":{"can_cancel":true,"friendly_name":"cover (living room ALL) - down","last_triggered":"2020-06-14T18:07:51.819657+00:00"},"context":{"id":"835360fa78f44028a467841b420631e1","parent_id":null,"user_id":null},"entity_id":"script.cover_living_room_covers_down","last_changed":"2020-06-14T21:23:53.427000+00:00","last_updated":"2020-06-14T21:23:53.427000+00:00","state":"off"}
[{"id":"3b8a4ccb.a80d44","type":"inject","z":"a384315.94b895","name":"Go","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":2140,"wires":[["25c953fa.344e94"]]},{"id":"25c953fa.344e94","type":"api-get-history","z":"a384315.94b895","name":"","server":"1cf948dc.a805f7","startdate":"","enddate":"","entityid":"script.cover_living_room_covers_down","entityidtype":"is","useRelativeTime":false,"relativeTime":"1d","flatten":true,"output_type":"split","output_location_type":"msg","output_location":"payload","x":370,"y":2140,"wires":[["8d9bcb00.f6e75"]]},{"id":"8d9bcb00.f6e75","type":"change","z":"a384315.94b895","name":"","rules":[{"t":"move","p":"payload.attributes.last_triggered","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":2020,"wires":[["88a45274.831198"]]},{"id":"88a45274.831198","type":"function","z":"a384315.94b895","name":"Calc difference ms","func":"flow.set(\"startTime\");\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":2020,"wires":[["d109c417.d561e","da4e1215.f45948"]]},{"id":"d109c417.d561e","type":"debug","z":"a384315.94b895","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1110,"y":2080,"wires":[]},{"id":"da4e1215.f45948","type":"function","z":"a384315.94b895","name":"Calc difference ms","func":"var now = new Date();\nmsg.payload = now - flow.get(\"startTime\");\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":2120,"wires":[["2847c817.8dfab8"]]},{"id":"2847c817.8dfab8","type":"debug","z":"a384315.94b895","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1110,"y":2120,"wires":[]},{"id":"1cf948dc.a805f7","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]