[SOLVED] - How to update datetime item via rest - what should be the format?

Hi,

I would like to update my DateTime item via REST with linux collected datetime.

I have the following item:

DateTime Last_Correct_Data_Receive_Time "last received data: [%1$td-%1$tm-%1$tY %1$tH:%1$tM]"

and I tried to update date and time from the script using the following curl:

curl -s -X PUT -H "Content-Type: text/plain" -d "27-11-2018 10:22" "http://192.168.1.23:8080/rest/items/Last_Correct_Data_Receive_Time/state"
{"error":{"message":"State could not be parsed: 27-11-2018 10:22","http-code":400}}

Anyone have an idea of what type of data/format should I send to have it updated?

Just found my answer when looking into knx log.
The format of the datetime string should be like:
“2018-11-27T10:22:10”

1 Like

by the way: another way to achieve the same result (get linux system time in a DateTime Item in OH2) would be to install the NTP binding. You would need to install a NTP daemon on the linux box if you want to pull the local time (or use a public NTP server just to get the time info into OH2)

/etc/openhab2/items/ntp.items

DateTime	NTP_Time	"Date [%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM]"	(gNTP)	{channel="ntp:ntp:local:dateTime"}

/etc/openhab2/things/ntp.things

ntp:ntp:local	"NTP Server"	@	"HomeR"	[hostname="ntp.itcs.lan", refreshInterval=60, refreshNtp=30]

ntp.itcs.lan = localhost in my case

I use my linux box as a NTP server for all my LAN devices and sync this daemon with an external public NTP server.

edit: You have a different use case… it seems that you are using a script to transmit data to OH2 via REST API and you want to add a timestamp upon successful delivery… forget the NTP then :slight_smile:

1 Like

yes. I had a different purpose. I simply collect data from my Viessmann heating and update over rest api. The script was failing multiple times for different reasons, so I wanted to indicate when actually I’ve got the correct data and when the failure could happen

Thanks for help anyway. Perhaps I’ll need your script later on as well :slight_smile:

Even if this post is already older…
Under OH3 you can also update a DateTime item with EPOCH time format.
Before I found this post here, I had figured that out.