This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Zwave - Fibaro Motion Sensor
#29
Hello

I managed to integrate zwave, rf devices, .... by using domoticz as gateway, for now I only use it for switching zwave and rf devices and it works pretty well

domoticz you find here (I installed it on a synology nas):
https://www.domoticz.com/

below my user library

Code:
DOMOTICZ_IP = '192.168.0.12' DOMOTICZ_PORT = '8084' DOMOTICZ_ID_BASEMENT_COMPRESSOR = '23' DOMOTICZ_ID_LIVINGROOM_READING_LIGHT = '215' DOMOTICZ_ID_LIVINGROOM_VENTILATOR = '102' KNX_GROUP_LIVINGROOM_COMPRESSOR_ON_OFF = '8/0/0' KNX_GROUP_LIVINGROOM_COMPRESSOR_ON_OFF_STATUS = '8/0/1' KNX_GROUP_LIVINGROOM_READING_LIGHT_ON_OFF = '8/1/0' KNX_GROUP_LIVINGROOM_READING_LIGHT_ON_OFF_STATUS = '8/1/1' KNX_GROUP_LIVINGROOM_VENTILATOR_ON_OFF = '8/1/2' KNX_GROUP_LIVINGROOM_VENTILATOR_ON_OFF_STATUS = '8/1/3' -- write value to knx only if value changed function writeKNX(group, value, default, typ)  local key,time   --  time = os.microtime() --  log('writeKNX(group, value, typ)',group,value,typ)  key = 'KNX_GRP_' .. string.gsub(group, "/", "_") --  log('writeKNX(group, value, typ)',key)  if ((storage.get(key, default)) ~= value) then --    log('now writing writeKNX(group, value, typ)',key, group, value)    storage.set(key, value)    grp.write(group, value, typ)  end end -- toggle on / off function domoticzSwitch(host, port, domoticzId, value)  local time --  time = os.microtime() --  log('domoticzSwitch(host, port, domoticzId, value)',host, port, domoticzId, value)  if (value == true) then    domoticzCmd(host, port, domoticzId, 'switchlight', 'On')  else    domoticzCmd(host, port, domoticzId, 'switchlight', 'Off')  end   --  time = os.microtime() - time --  log('domoticzSwitch(host, port)',host, port, domoticzId, value, time) end -- get On Off Status function domoticzGetSwitchStatus(host, port, domoticzId)  local time, status --  time = os.microtime() --  log('domoticzGetSwitchStatus(host, port, domoticzId)',host, port, domoticzId)  status = domoticzStatus(host,port,domoticzId)  result =  (status.result[1].Status == "On")   --  time = os.microtime() - time --  log('domoticzGetSwitchStatus(host, port, domoticzId)',host, port, domoticzId, result, time)  return result end -- send command to domoticz function domoticzCmd(host, port, domoticzId, domoticzCmd, cmdParam)  local http, request,r, c, h --  time = os.microtime() --  log('domoticzCmd', host, port, domoticzId, domoticzCmd, cmdParam)     -- load the http module     local http = require("socket.http")  request = "http://" .. host .. ":" .. port .. "/json.htm?type=command&param=" .. domoticzCmd .. "&idx=" .. domoticzId .. "&switchcmd=" .. cmdParam --  log('domoticzCmd', host, port, domoticzId, domoticzCmd, cmdParam, request)     -- connect to server  r, c, h = http.request (request) --  time = os.microtime() - time --  log('domoticzCmd', host, port, domoticzId, domoticzCmd, cmdParam, r, c, h, time) end -- retrieve a status from domoticz function domoticzStatus(host, port, domoticzId)  local http, request,r, c, h --  time = os.microtime() --  log('domoticzStatus', host, port, domoticzId)  -- build the http request     local http = require("socket.http")  request = "http://" .. host .. ":" .. port .. "/json.htm?type=devices&rid=" .. domoticzId-- --  log('domoticzStatus', host, port, domoticzId, request)  -- execute the http request  r, c, h = http.request (request) --  time = os.microtime() - time --  log('domoticzStatus', host, port, domoticzId, r, c, h, time)  -- decode the json object  local json = require("json")    local statusobject = json.pdecode(r)  return statusobject end

here a trigger to switch a device based a knx event
Code:
SCRIPT = 'user.library' lib = require(SCRIPT) if not lib then alert('Event ' .. event .. ' not handled: script ' .. SCRIPT .. ' missing') os.sleep(60) return end -- object mapped to this event must have its data type set value = event.getvalue() -- toggle on/off domoticzSwitch(DOMOTICZ_IP, DOMOTICZ_PORT, DOMOTICZ_ID_LIVINGROOM_VENTILATOR, value) -- only write on changed data writeKNX(KNX_GROUP_LIVINGROOM_VENTILATOR_ON_OFF_STATUS, value, false, dt.bool)

finally my deamon script to ensure that the knx status is correctly set even if I use domoticz or my zwave remote

Code:
SCRIPT = 'user.library' lib = require(SCRIPT) if not lib then alert('Event ' .. event .. ' not handled: script ' .. SCRIPT .. ' missing') os.sleep(60) return end ----------------------------------- -- determine the domticz status ----------------------------------- -- basement bStatus = domoticzGetSwitchStatus(DOMOTICZ_IP, DOMOTICZ_PORT, DOMOTICZ_ID_BASEMENT_COMPRESSOR) writeKNX(KNX_GROUP_LIVINGROOM_COMPRESSOR_ON_OFF, bStatus, false, dt.bool) -- livingroom -- reading light bStatus = domoticzGetSwitchStatus(DOMOTICZ_IP, DOMOTICZ_PORT, DOMOTICZ_ID_LIVINGROOM_READING_LIGHT) -- only write on changed data --writeKNX(KNX_GROUP_LIVINGROOM_READING_LIGHT_ON_OFF, bStatus, false, dt.bool) -- ventilator bStatus = domoticzGetSwitchStatus(DOMOTICZ_IP, DOMOTICZ_PORT, DOMOTICZ_ID_LIVINGROOM_VENTILATOR) -- only write on changed data --writeKNX(KNX_GROUP_LIVINGROOM_VENTILATOR_ON_OFF, value, false, dt.bool)

I am sure code could be cleaner but I am still learning lua

Enjoy Smile

Next step let a mobotix cam trigger the opening/closing of doors, but manage the opening hours per user through logic machine
Reply


Messages In This Thread
RE: Zwave - Fibaro Motion Sensor - by edgars - 01.07.2015, 08:57
RE: Zwave - Fibaro Motion Sensor - by edgars - 02.07.2015, 08:07
RE: Zwave - Fibaro Motion Sensor - by edgars - 03.07.2015, 12:03
RE: Zwave - Fibaro Motion Sensor - by Peter - 09.07.2015, 07:30
RE: Zwave - Fibaro Motion Sensor - by edgars - 27.08.2015, 09:53
RE: Zwave - Fibaro Motion Sensor - by andeug - 18.09.2015, 16:15
RE: Zwave - Fibaro Motion Sensor - by admin - 21.09.2015, 08:45
RE: Zwave - Fibaro Motion Sensor - by andeug - 27.09.2015, 09:18
RE: Zwave - Fibaro Motion Sensor - by admin - 28.09.2015, 06:18
RE: Zwave - Fibaro Motion Sensor - by andeug - 29.09.2015, 19:33
RE: Zwave - Fibaro Motion Sensor - by edgars - 30.09.2015, 06:28
RE: Zwave - Fibaro Motion Sensor - by edgars - 08.10.2015, 12:48
RE: Zwave - Fibaro Motion Sensor - by admin - 11.11.2015, 07:07
RE: Zwave - Fibaro Motion Sensor - by admin - 12.11.2015, 07:45
RE: Zwave - Fibaro Motion Sensor - by npinguin - 25.11.2015, 22:01
RE: Zwave - Fibaro Motion Sensor - by admin - 26.11.2015, 07:02
RE: Zwave - Fibaro Motion Sensor - by edgars - 19.01.2016, 09:00
RE: Zwave - Fibaro Motion Sensor - by edgars - 19.01.2016, 10:38
RE: Zwave - Fibaro Motion Sensor - by edgars - 29.01.2016, 11:49
RE: Zwave - Fibaro Motion Sensor - by edgars - 29.01.2016, 12:19
RE: Zwave - Fibaro Motion Sensor - by edgars - 03.03.2016, 09:42
RE: Zwave - Fibaro Motion Sensor - by edgars - 04.04.2016, 13:03
RE: Zwave - Fibaro Motion Sensor - by edgars - 05.04.2016, 07:05
RE: Zwave - Fibaro Motion Sensor - by edgars - 07.04.2016, 07:49
RE: Zwave - Fibaro Motion Sensor - by edgars - 12.04.2016, 11:47
RE: Zwave - Fibaro Motion Sensor - by edgars - 28.04.2016, 09:00
RE: Zwave - Fibaro Motion Sensor - by edgars - 04.08.2016, 09:57
RE: Zwave - Fibaro Motion Sensor - by andeug - 07.08.2016, 13:54
RE: Zwave - Fibaro Motion Sensor - by admin - 17.08.2016, 06:36
RE: Zwave - Fibaro Motion Sensor - by gaxy - 17.08.2016, 08:53
RE: Zwave - Fibaro Motion Sensor - by admin - 17.08.2016, 09:08
RE: Zwave - Fibaro Motion Sensor - by baggins - 22.02.2017, 21:48
RE: Zwave - Fibaro Motion Sensor - by baggins - 23.02.2017, 16:47
RE: Zwave - Fibaro Motion Sensor - by baggins - 23.02.2017, 22:48
RE: Zwave - Fibaro Motion Sensor - by baggins - 24.02.2017, 07:39
RE: Zwave - Fibaro Motion Sensor - by admin - 24.02.2017, 09:58
RE: Zwave - Fibaro Motion Sensor - by baggins - 24.02.2017, 10:07
RE: Zwave - Fibaro Motion Sensor - by baggins - 28.03.2017, 11:21
RE: Zwave - Fibaro Motion Sensor - by edgars - 28.03.2017, 12:34
RE: Zwave - Fibaro Motion Sensor - by baggins - 28.03.2017, 12:59
RE: Zwave - Fibaro Motion Sensor - by baggins - 29.03.2017, 13:06
RE: Zwave - Fibaro Motion Sensor - by edgars - 30.03.2017, 12:56
RE: Zwave - Fibaro Motion Sensor - by baggins - 30.03.2017, 17:03
RE: Zwave - Fibaro Motion Sensor - by baggins - 31.03.2017, 17:09
RE: Zwave - Fibaro Motion Sensor - by edgars - 03.04.2017, 06:41
RE: Zwave - Fibaro Motion Sensor - by baggins - 18.05.2017, 15:59
RE: Zwave - Fibaro Motion Sensor - by admin - 18.05.2017, 16:23
RE: Zwave - Fibaro Motion Sensor - by baggins - 18.05.2017, 16:58
RE: Zwave - Fibaro Motion Sensor - by baggins - 19.05.2017, 15:48
RE: Zwave - Fibaro Motion Sensor - by JMM - 18.11.2017, 16:02
RE: Zwave - Fibaro Motion Sensor - by ewatt - 14.03.2018, 09:54
RE: Zwave - Fibaro Motion Sensor - by Daniel - 14.03.2018, 10:26
RE: Zwave - Fibaro Motion Sensor - by JMM - 14.03.2018, 11:27
RE: Zwave - Fibaro Motion Sensor - by ewatt - 14.03.2018, 12:16
RE: Zwave - Fibaro Motion Sensor - by Daniel - 14.03.2018, 11:39
RE: Zwave - Fibaro Motion Sensor - by Igori - 28.01.2020, 13:19
RE: Zwave - Fibaro Motion Sensor - by Daniel - 28.01.2020, 13:51
RE: Zwave - Fibaro Motion Sensor - by Igori - 28.01.2020, 15:05
RE: Zwave - Fibaro Motion Sensor - by Daniel - 28.01.2020, 15:13
RE: Zwave - Fibaro Motion Sensor - by Igori - 29.01.2020, 17:14

Forum Jump: