I would like to get the date and timestamp of the latest device turned on then turned off. I can ping the device but I don’t know how to show that in openhab.
Is it possible to write something in Python that will write something in a text file then ask opehab to print it somewhere?
What I would do is ping the device (starting for down state for example) and if up, it writes the timestamp for up then when down, it writes the timestamp for down state then the time difference then next line and restart when device goes up.
When you say “ping the device” do you literally mean the ping command or are you talking figuratively?
If you are literally doing a network ping, then just use the Network binding. Then create a Rule that triggers when that switch changes state. If it changed to ON you know the device came up. If it changed to OFF you know the device went down.
From there you can populate a DateTime Item with the current time.
In another rule that triggers periodically using a Time cron trigger, calculate the difference between the DateTime Item and now and populate an Item with that difference to get your Uptime/Downtime.