Page 1 of 1
Start script from API
Posted: Monday 09 March 2020 17:18
by DewGew
I want to start a timer device Q for X mins from domoticz api.
Is it possible to start a dzVents timer from domoticz API with a variables?
Code: Select all
/json.htm?type=command¶m=customevent&event=TIMER&data=X
Re: Start script from API [Solved]
Posted: Monday 09 March 2020 18:04
by waaren
DewGew wrote: Monday 09 March 2020 17:18
I want to start a timer device Q for X mins from domoticz api.
Is it possible to start a dzVents timer from domoticz API with a variables?
Code: Select all
/json.htm?type=command¶m=customevent&event=TIMER&data=X
Not with a timer( that's driven by the domoticz event system) but starting from dzVents 3.0.0 (domoticz V4.11687) you can trigger dzVents scripts with customEvents. See
the wiki chapter
In your example the customEvent name will be TIMER and you can access the passed data in the script.
Code: Select all
return
{
on =
{
customEvents = { 'TIMER' },
},
execute = function(domoticz, item)
-- your code here
end
}
Re: Start script from API
Posted: Tuesday 10 March 2020 7:33
by DewGew
I looking for similar like this:
Code: Select all
return
{
on =
{
customEvents = { 'TIMER' },
},
execute = function(domoticz, item)
domoticz.devices(item.data.IDX).switchOn().forSec(item.data.T)
end
}
Call the script with this:
Code: Select all
/json.htm?type=command¶m=customevent&event=TIMER&data={IDX=12,T=30}
Re: Start script from API
Posted: Tuesday 10 March 2020 8:28
by waaren
DewGew wrote: Tuesday 10 March 2020 7:33
I looking for similar like this:
Close ..
Code: Select all
return
{
on =
{
customEvents = { 'TIMER' },
},
execute = function(dz, item)
dz.devices(item.data.IDX).switchOn().forSec(item.data.T)
end
}
Code: Select all
/json.htm?type=command¶m=customevent&event=TIMER&data={"IDX":12,"T":30}
Re: Start script from API
Posted: Tuesday 10 March 2020 8:32
by DewGew
Great Thanks alot

Re: Start script from API
Posted: Tuesday 10 March 2020 11:39
by DewGew
waaren wrote: Tuesday 10 March 2020 8:28
DewGew wrote: Tuesday 10 March 2020 7:33
I looking for similar like this:
Close ..
Code: Select all
return
{
on =
{
customEvents = { 'TIMER' },
},
execute = function(dz, item)
dz.devices(item.data.IDX).switchOn().forSec(item.data.T)
end
}
Code: Select all
/json.htm?type=command¶m=customevent&event=TIMER&data={"IDX":12,"T":30}
Do I cancel the time if I send a switchOn() or switchOff() within the time?
Do I update time if I send a forSec() within the time?
Re: Start script from API
Posted: Tuesday 10 March 2020 12:13
by waaren
DewGew wrote: Tuesday 10 March 2020 11:39
Do I cancel the time if I send a switchOn() or switchOff() within the time?
Do I update time if I send a forSec() within the time?
No
No
The forSec is determined and set when the script executes and only the cancelQueuedCommand() will stop any scheduled actions.
Also be aware that the next state is also determined when the script executes initially. This might lead to unexpected results if the state changes within the time of the forSec.
That is why my personal preference is to use a combination of
cancelQueuedCommands()
switchOn()
switchOff().afterSec(xx)
because the behavior is predictable and not influenced by other commands.
Re: Start script from API
Posted: Thursday 12 March 2020 12:46
by DewGew
Great thanks @waaren works like a charm
