How to automatically ping devices and use the result

For my Zigbee divices I use this script to see “lastseen”. It works fine.

Same kind of script insite this test: