Timers API questions & remarks

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Timers API questions & remarks

Post by jvdz »

I have been playing with the timers API's for both addtimer and addsetpointtimer and found some quirks and have some questions:

The "/json.htm?type=command&param=getschedules" only returns the timers that are none-persistent for both the switches and setpoint devices. Is this intentional?
eg: output for getschedules:

Code: Select all

{
	"result" : 
	[
		{
			"Active" : "true",
			"Color" : "",
			"Date" : "",
			"Days" : 1234567,
			"DevName" : "DeviceName",
			"DeviceRowID" : 57,
			"IsThermostat" : "false",
			"Level" : 40,
			"MDay" : 0,
			"Month" : 0,
			"Occurence" : 0,
			"Randomness" : "false",
			"ScheduleDate" : "2025-12-29 15:20:00",
			"Time" : "15:20",
			"TimerCmd" : 0,
			"TimerID" : 1,
			"TimerType" : 2,
			"TimerTypeStr" : "On Time",
			"Type" : "Device"
		},
		{
			"Active" : "true",
			"Date" : "",
			"Days" : 1234567,
			"DevName" : "Devicename3",
			"DeviceRowID" : 59,
			"IsThermostat" : "true",
			"MDay" : 0,
			"Month" : 0,
			"Occurence" : 0,
			"ScheduleDate" : "2025-12-29 15:05:00",
			"Temperature" : "15.6",
			"Time" : "15:05",
			"TimerID" : 2,
			"TimerType" : 2,
			"TimerTypeStr" : "On Time",
			"Type" : "Device"
		}
	],
	"status" : "OK",
	"title" : "getschedules"
}
the "/json.htm?type=command&param=gettimers&idx=57" does return them all:

Code: Select all

{
	"result" : 
	[
		{
			"Active" : "true",
			"Cmd" : 0,
			"Color" : "",
			"Date" : "",
			"Days" : 1234567,
			"Level" : 40,
			"MDay" : 0,
			"Month" : 0,
			"Occurence" : 0,
			"Persistent" : "false",
			"Randomness" : "false",
			"Time" : "15:20",
			"Type" : 2,
			"idx" : "1"
		},
		{
			"Active" : "true",
			"Cmd" : 0,
			"Color" : "",
			"Date" : "",
			"Days" : 127,
			"Level" : 100,
			"MDay" : 0,
			"Month" : 0,
			"Occurence" : 0,
			"Persistent" : "true",
			"Randomness" : "true",
			"Time" : "11:05",
			"Type" : 2,
			"idx" : "2"
		},
		{
			"Active" : "true",
			"Cmd" : 0,
			"Color" : "",
			"Date" : "",
			"Days" : 134,
			"Level" : 100,
			"MDay" : 0,
			"Month" : 0,
			"Occurence" : 0,
			"Persistent" : "true",
			"Randomness" : "true",
			"Time" : "11:10",
			"Type" : 2,
			"idx" : "3"
		},
		{
			"Active" : "true",
			"Cmd" : 0,
			"Color" : "",
			"Date" : "",
			"Days" : 13,
			"Level" : 100,
			"MDay" : 0,
			"Month" : 0,
			"Occurence" : 0,
			"Persistent" : "true",
			"Randomness" : "true",
			"Time" : "11:16",
			"Type" : 2,
			"idx" : "4"
		}
	],
	"status" : "OK",
	"title" : "gettimers"
}
Maybe I am not properly understanding what persistent really means, other than that one can't override them, but I did expect the "/json.htm?type=command&param=getschedules" to return them all!?

Some Wiki remarks:

Code: Select all

"/json.htm?type=command&param=addtimer&idx=DeviceRowID&active=true&timertype=2&hour=0&min=20&randomness=false&command=0&days=1234567"
- is missing the persistent option
- states that "days = 1=Mon, 2=Tue, 3=Wed, 4=Thurs, 5=Fri, 6=Sat, 7=Sun", but that should be:

Code: Select all

	-- days bit position: 1=mon (1), 2=tue (2), 3=wed (4), 4=thu (8), 5=fri (16), 6=sat (32), 7=sun (64). 
	     Add the values in the brackets together for the days to be activated.  eg 40=thu+sat
	-- 128 = all days
	-- 256 = weekdays
	-- 512 = weekends


The addsetpointtimer/updatesetpointtimer/deletesetpointtimer api's aren't documented in the wiki yet:

Code: Select all

/json.htm?type=command&param=addsetpointtimer&idx=IDX&active=true&timertype=2&hour=12&min=0&persistent=false&tvalue=15&vunit=%C2%B0C&days=1234567
/json.htm?type=command&param=updatesetpointtimer&idx=Timer_Id&active=true&timertype=2&hour=12&min=0&persistent=false&tvalue=15&vunit=%C2%B0C&days=1234567
will add stuff when i encounter more stuff.
User avatar
waltervl
Posts: 6676
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Timers API questions & remarks

Post by waltervl »

Persistent: Will be available in all timer plans when enabled. (available from beta dd 20-12-2023) ( https://wiki.domoticz.com/Managing_Devi ... ice_Timers )

I suppose that is why persistent are not listed with getschedules. Where is this API call used in the gui?

You are free to update the wiki when needed ;-)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Timers API questions & remarks

Post by jvdz »

waltervl wrote: Monday 29 December 2025 13:02 Persistent: Will be available in all timer plans when enabled. (available from beta dd 20-12-2023)
I've seen that but it simply isn't clear in my mind yet what that means. So what exactly is the difference between a persistent and non persistent timer as far as behaviour?
waltervl wrote: Monday 29 December 2025 13:02 I suppose that is why persistent are not listed with getschedules. Where is this API call used in the gui?
I don't suppose anything when coding in general and am looking for logic answers when having my coderbrain switched on. 😉
waltervl wrote: Monday 29 December 2025 13:02 You are free to update the wiki when needed ;-)
Understood, but I only document stuff I understand.
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Timers API questions & remarks

Post by jvdz »

To answer the question why they are not in getschedules, i looked in the sourcecode and it is because TimerPlan==9999 aren't selected:

this is in the sql WHERE statement for getschedules:

Code: Select all

"SELECT t.ID, t.Active, d.[Name], t.DeviceRowID AS ID, 0 AS IsScene, 0 AS IsThermostat, t.[Date], t.Time, t.Type, t.Cmd, t.Level, t.Color, 0 AS Temperature, t.Days, t.UseRandomness, t.MDay, t.Month, t.Occurence"
" FROM Timers AS t, DeviceStatus AS d"
" WHERE (d.ID == t.DeviceRowID) AND (t.TimerPlan==%d)"
" ORDER BY d.[Name], t.Time"
...
missing TimerPlan  in Select and no field "persistent" is created for the result.
and this for gettimers:

Code: Select all

("SELECT ID, Active, [Date], Time, Type, Cmd, Level, Color, Days, UseRandomness, MDay, Month, Occurence, TimerPlan"
" FROM Timers "
" WHERE (DeviceRowID==%" PRIu64 ") AND ((TimerPlan==%d) OR (TimerPlan==9999))"
" ORDER BY ID"
.... result field definition...
root["result"][ii]["Persistent"] = (atoi(sd[13].c_str()) == 9999) ? "true" : "false";
So question remains whether this is deliberate or a missed update when persistent was introduced. :-)
User avatar
waltervl
Posts: 6676
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Timers API questions & remarks

Post by waltervl »

There is only one to ask ;-)

But where in the gui is getschedules used? I do not think it is used somewhere. So probably the reason it was not changed during introduction of the persistent timers as it has no influence on the gui of Domoticz.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
JanJaap
Posts: 229
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: Timers API questions & remarks

Post by JanJaap »

Hey,

I'm getting the same result (all timers) on "/json.htm?type=command&param=getschedules"
but the other command "/json.htm?type=command&param=gettimers&idx=545" (both with idx for switch and setpoint devices) returns just this:

Code: Select all

{
	"status" : "OK",
	"title" : "gettimers"
}


not sure still how to make a timer persistent. As far as I understand the term 'persistent', all timers are?

btw, updatesetpointtimer works fine with the given params
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], heggink and 1 guest