thought I’d bring this thread back to life with a follow up question…I too am looking to suppress an automation if an entity has been triggered within the last 30 seconds. I am however having issues with the Get History node response within Node Red…
I intend on using the last_changed datetime attribute included in the Get History response to determine when the entity was last triggered. The last item’s last_changed value in the Get History array that is returned appears to correspond to the relative date range configured in the Get History Node request and not when the Entity’s state was last changed.
vs
*The Get History last_changed datetime appears to be UTC while my machine and the Home Assistant frontend are representing UTC +2 for my timezone.
Below is the Node Red implementation, please let me know if I have implemented anything incorrectly or if there is another way to implement such logic within node red. thanks
[{"id":"5850c808.b65c88","type":"server-state-changed","z":"6b578c04.3d58e4","name":"Driveway Beam Movement","server":"18cd850f.0ce76b","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.drivewaybeam","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,"x":510,"y":280,"wires":[["56965379.05f0ac"],[]]},{"id":"56965379.05f0ac","type":"api-get-history","z":"6b578c04.3d58e4","name":"","server":"18cd850f.0ce76b","startdate":"now - 30","enddate":"now ","entityid":"binary_sensor.drivewaybeam","entityidtype":"is","useRelativeTime":true,"relativeTime":"1 min","flatten":true,"output_type":"array","output_location_type":"msg","output_location":"payload","x":710,"y":320,"wires":[["794742ef.8a768c","22710964.3eefc6"]]},{"id":"794742ef.8a768c","type":"function","z":"6b578c04.3d58e4","name":"Check Time Difference","func":"var now = new Date();\nvar history_array = msg.payload;\n//var history_array = msg.payload.reverse();\n//msg.payload.LastTimeTriggered= history_array[0].last_updated;\n//flow.set('LastTimeTriggered',history_array[0].last_updated);\n//flow.set('LastSinceLastTriggered',(now-Date.parse(history_array[0].last_updated)));\nmsg.payload = now-Date.parse(history_array[history_array.length-1].last_updated)\nreturn msg ;\n","outputs":1,"noerr":0,"x":880,"y":320,"wires":[["b63fab34.271af8","fc174bf7.341dc8"]]},{"id":"b63fab34.271af8","type":"switch","z":"6b578c04.3d58e4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"3000","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1070,"y":360,"wires":[[]]},{"id":"25fe5bd5.e7acd4","type":"inject","z":"6b578c04.3d58e4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":540,"y":360,"wires":[["56965379.05f0ac"]]},{"id":"22710964.3eefc6","type":"debug","z":"6b578c04.3d58e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":830,"y":380,"wires":[]},{"id":"fc174bf7.341dc8","type":"debug","z":"6b578c04.3d58e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1070,"y":420,"wires":[]},{"id":"18cd850f.0ce76b","type":"server","z":"","name":"Home Assistant"}] ```