My DZ server runs on a Synology station.
1. Create Dummy Switch to open/close garage door. "On Action" and "Off Action" fill with "http://192.168.x.x:8080/cc?click=1&dkey=opendoor"
2. Create Dummy Text Device.
3. Create Dummy Distance Device.
4. Copy JSON.lua script to domoticz/var/scripts/lua/JSON.lua
5. Copy script below named "script_time_xxx.lua" to the same dir.
6. Check your dummies, should work.
I am not a coder, so my script is based on this one:
Code: Select all
commandArray={}
--your variables
idxS = 38 -- IDX of your Dummy Switch to open/close garage
idxT = 39 -- IDX of your Dummy Text Device to get a written status of your garage
idxD = 107 -- IDX of your Dummy Distance Device to have a distance in cm in DZ
ip = '192.168.x.x' -- IP of your Opengarage device
port = xxxx -- port of your Opengarage device
--end of your variables
json = (loadfile "/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua")()
local dist = " "
local door = " "
local jsondata = assert(io.popen('curl http://'..ip..':'..port..'/jc'))
local jsondevices = jsondata:read('*all')
jsondata:close()
local jsonDIST = json:decode(jsondevices)
dist = jsonDIST.dist
door = jsonDIST.door
-- print (jsondevices) --uncomment for debug in DZ Log
-- print (jsonDIST) --uncomment for debug in DZ Log
if (dist > 270)
then garstatus = 'Empty'
elseif (dist < 135) and (dist > 131)
then garstatus = 'Car1 parked'
elseif (dist < 115) and (dist > 110)
then garstatus = 'Car2 parked'
elseif (dist < 23)
then garstatus = 'Garage opened!'
else garstatus = 'Unknown car!'
end
-- print (dist) --uncomment for debug in DZ Log
-- print (door) --uncomment for debug in DZ Log
-- print (garstatus) --uncomment for debug in DZ Log
commandArray[1] = {['UpdateDevice']=idxS..'|'..door..'|'..door..''}
commandArray[2] = {['UpdateDevice']=idxT..'|0|'..garstatus..''}
commandArray[3] = {['UpdateDevice']=idxD..'|0|'..dist..''}
return commandArray
Door Opened height and Empty height should also be corrected.
Script runs every 60 seconds so there is a delay in status of Dummies.
Definitely not a clean code, but works for me
