Retrieve Domoticz time in API/JSON call  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
peterbos
Posts: 93
Joined: Saturday 07 November 2020 21:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Retrieve Domoticz time in API/JSON call

Post 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!
Number8
Posts: 374
Joined: Friday 23 May 2014 7:55
Target OS: Linux
Domoticz version: 2022.1
Location: Saint Pierre de Jards
Contact:

Re: Retrieve Domoticz time in API/JSON call

Post by Number8 »

This should do it:

Code: Select all

/json.htm?type=command&param=getSunRiseSet
Debian buster on NUC and three RPi with buster.
gerardvs
Posts: 81
Joined: Sunday 04 January 2015 0:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest-1
Location: /dev/null
Contact:

Re: Retrieve Domoticz time in API/JSON call

Post 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
peterbos
Posts: 93
Joined: Saturday 07 November 2020 21:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

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

Post 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
peterbos
Posts: 93
Joined: Saturday 07 November 2020 21:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

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

Post by peterbos »

Hi Gerard and Number 8,

Our posts crossed each other.

Peter
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests