Opengarage integration

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
saintman
Posts: 4
Joined: Monday 20 June 2016 11:13
Target OS: NAS (Synology & others)
Domoticz version: 3.5254
Location: Moscow
Contact:

Opengarage integration

Post by saintman »

Here are some instructions to integrate Opengarage hardware by Ray's DIY Electronics Hobby Projects with DZ.
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 
Script takes care of 2 cars with different heights. You are free to correct them and/or use height for 1 or more cars.
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 8-)
atatistcheff
Posts: 17
Joined: Sunday 19 June 2016 18:16
Target OS: Linux
Domoticz version: 3.8153
Contact:

Re: Opengarage integration

Post by atatistcheff »

Thanks for posting this. Just got the opengarage and your instructions worked great. Of course had to tweak the script a bit for my installation but it works just fine!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest