Page 1 of 1

Switch event via api

Posted: Monday 09 December 2019 17:38
by hardus77
Hello everyone,,
I have setup a trigger on blue iris to trip when someone walks up my walkway. I was going to have that trigger call the api to turn on the light at night for 15 min. I can't seem to find a way to call an event from the api so all I can do is turn on the light. I want the light to stay on if it's manually turned on tough.reverse image search email checker port checker

How do I do that?

Re: Switch event via api

Posted: Monday 09 December 2019 22:14
by waaren
hardus77 wrote: Monday 09 December 2019 17:38
I have setup a trigger on blue iris to trip when someone walks up my walkway. I was going to have that trigger call the api to turn on the light at night for 15 min. I can't seem to find a way to call an event from the api so all I can do is turn on the light. I want the light to stay on if it's manually turned on tough.
My approach would be to have the API update a uservariable and use the user variable as trigger for a dzVents script.

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

dzVents script could look like something as

Code: Select all

--      Create domoticz uservar as type string        
--      Update with 
--      http://domoticz_IP:domoticz_PORT/json.htm?type=command&param=updateuservariable&idx=<uservariable id>&vname=whoIsOnMyWalkway&vtype=2&vvalue=someone

return 
{
    on = 
    {
        variables = { 'whoIsOnMyWalkway' }, -- change to name of your uservar 
        devices = { 'testLight' }, -- change to name of your light
    },

    data =           -- persistent data is needed here to identify if light was switched manually or by script
    {
        lastOn = 
        { 
             initial = '',  
        },
    },

    logging = 
    { 
        level = domoticz.LOG_DEBUG
    },
    
    execute = function(dz, item )
        _G.logMarker =  _G.moduleLabel -- set logmarker to scriptname
        
        local myLight = dz.devices('testLight') -- change to name of your light
        
        if item.isVariable then
            dz.log('script triggered by uservariable ' ..item.name ..'; value is ' .. item.value,dz.LOG_DEBUG)
            myLight.cancelQueuedCommands()
            myLight.switchOn().checkFirst().silent()
            if dz.data.lastOn ~= 'device' then
                myLight.switchOff().silent().afterMin(15)
                dz.data.lastOn = 'uservar'
            else
                dz.log('Light switched on manually. I will not switch it off' ,dz.LOG_DEBUG)
            end      
        else -- triggered manually 
            dz.log('script triggered by device ' .. item.name .. '; state is'  .. item.state,dz.LOG_DEBUG)
            myLight.cancelQueuedCommands()
            if item.active then 
                dz.data.lastOn = 'device' 
            else
                dz.data.lastOn = ''
            end
        end 
    end
}