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?
Switch event via api
Moderators: leecollings, remb0
-
- Posts: 1
- Joined: Monday 09 December 2019 17:32
- Target OS: Windows
- Domoticz version:
- Contact:
Switch event via api
Last edited by hardus77 on Friday 13 December 2019 23:59, edited 1 time in total.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Switch event via api
My approach would be to have the API update a uservariable and use the user variable as trigger for a dzVents script.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.
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¶m=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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest