Page 1 of 1

Retrieve Domoticz time in API/JSON call

Posted: Wednesday 13 January 2021 21:30
by peterbos
Hi,

I want to synchronize the time on a NodeMCU8266 (*) with the time Domoticz shows in the upper left corner of the dashboard page. This way I can avoid issues with summer and winter time, which are quite difficult to manage when using an NTP-server as source.

Of course I can synchronize with a CustomEvent every X hours, but then I have to maintain code on both the NodeMCU and in Domoticz. Is a JSON call available that I can use to get the time? I looked for it in the API/JSON guide but didn't find it. With a JSON call I only have to maintain the NodeMCU side since the Domoticz side is taken care of by Domoticz itself.

Thanks,
Peter

(*) Great stuff to combine with Domoticz by the way!

Re: Retrieve Domoticz time in API/JSON call

Posted: Wednesday 13 January 2021 22:02
by Number8
This should do it:

Code: Select all

/json.htm?type=command&param=getSunRiseSet

Re: Retrieve Domoticz time in API/JSON call

Posted: Wednesday 13 January 2021 22:02
by gerardvs
Not sure why you post this in dzVents if you want to call the API but you could use

Code: Select all

/json.htm?type=command&param=getSunRiseSet
Although you are not interested in sunrise or sunset there is also a 'ServerTime' attribute with the current time.

--Gerard

Re: Retrieve Domoticz time in API/JSON call [SOLVED]

Posted: Wednesday 13 January 2021 22:10
by peterbos
Hi all,

I found it. In the JSON/API guide there's a JSON commandstring /json.htm?type=command&param=getSunRiseSet. In addition to the sunrise and sunset times it also gives the ServerTime, which is what I was looking for. I then tried the commandstring /json.htm?type=command&param=getServerTime and that worked to. The response from Domoticz was:

{
"ServerTime" : "2021-01-13 22:00:37",
"status" : "OK",
"title" : "getServerTime"
}

I hope this undocumented feature may exist until forever :D

Peter

Re: Retrieve Domoticz time in API/JSON call  [Solved]

Posted: Thursday 14 January 2021 0:08
by peterbos
Hi Gerard and Number 8,

Our posts crossed each other.

Peter