Start script from API  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Start script from API

Post 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&param=customevent&event=TIMER&data=X
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Start script from API  [Solved]

Post 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&param=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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Start script from API

Post 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&param=customevent&event=TIMER&data={IDX=12,T=30}
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Start script from API

Post 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&param=customevent&event=TIMER&data={"IDX":12,"T":30}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Start script from API

Post by DewGew »

Great Thanks alot :)
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Start script from API

Post 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&param=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?
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Start script from API

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Start script from API

Post by DewGew »

Great thanks @waaren works like a charm :)
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest