- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
/D_EnoceanRPS.json
r1 r3 7 7 "imgIconMax": "", 8 8 "halloIconsDir": "pics\/hallo", 9 "inScene": "0", 9 10 "DisplayStatus": { 10 11 "Service": "urn:upnp-esweb-nl:serviceId:EnoceanRPS1", … … 16 17 "doc_version": 1, 17 18 "doc_platform": 0, 18 "doc_page": "sensors" 19 }, 19 "doc_page": "sensors" 20 }, 20 21 "Tabs": [ 21 22 { 22 23 "Label": { 23 24 "lang_tag": "tabname_control", 24 "text": "Control" 25 "text": "Control" 25 26 }, 26 27 "Position": "0", 27 28 "TabType": "flash", 28 "ControlGroup":[ 29 { 30 "id":"1", 31 "type":"info" 32 } 33 ], 29 "SceneGroup": [ 30 { 31 "id": "1", 32 "top": "1", 33 "left": "0", 34 "x": "2", 35 "y": "1" 36 } 37 ], 38 "ControlGroup":[ 39 { 40 "id":"1", 41 "scenegroup": "1" 42 } 43 ], 34 44 "Control": [ 35 45 { 36 "ControlGroup":"1", 37 "ControlPair":"1", 38 "ControlHeader":"1", 46 "ControlGroup":"1", 39 47 "ControlType": "label", 40 48 "Label": { 41 49 "lang_tag": "lblButton", 42 "text": "Last button:" 50 "text": "Last button:" 43 51 }, 44 52 "Display": { … … 46 54 "Left": 50, 47 55 "Width": 75, 48 "Height": 20 49 } 56 "Height": 20 57 } 50 58 }, 51 59 { 52 "ControlGroup":"1", 53 "ControlPair":"1", 54 "ControlHeader":"1", 60 "ControlGroup":"1", 55 61 "ControlType": "variable", 62 "left": "1", 56 63 "Display": { 57 64 "Service": "urn:upnp-esweb-nl:serviceId:EnoceanRPS1", … … 60 67 "Left": 145, 61 68 "Width": 40, 62 "Height": 20 63 } 64 } 65 ] 69 "Height": 20 70 } 71 } 72 ] 66 73 }, 67 74 { 68 75 "Label": { 69 76 "lang_tag": "advanced", 70 "text": "Advanced" 77 "text": "Advanced" 71 78 }, 72 79 "Position": "2", 73 80 "TabType": "javascript", 74 81 "ScriptName": "shared.js", 75 "Function": "advanced_device" 76 }, 77 { 78 79 80 "text": "Logs"81 82 83 84 85 "Function": "device_logs"86 }, 87 88 89 90 "text": "Notifications"91 92 93 94 95 "Function": "device_notifications"96 } 82 "Function": "advanced_device" 83 }, 84 { 85 "Label": { 86 "lang_tag": "logs", 87 "text": "Logs" 88 }, 89 "Position": "4", 90 "TabType": "javascript", 91 "ScriptName": "shared.js", 92 "Function": "device_logs" 93 }, 94 { 95 "Label": { 96 "lang_tag": "notifications", 97 "text": "Notifications" 98 }, 99 "Position": "5", 100 "TabType": "javascript", 101 "ScriptName": "shared.js", 102 "Function": "device_notifications" 103 } 97 104 ], 98 105 "sceneList": { … … 103 110 "action": "SetButton", 104 111 "arguments": { 105 "newButtonValue": "A0" 112 "newButtonValue": "A0" 106 113 }, 107 114 "display": { … … 109 116 "variable": "Button", 110 117 "value": "A0" 111 } 118 } 112 119 } 113 } 120 } 114 121 }, 115 "eventList": { 116 "event_1": { 117 "label": "A button is pressed", 122 "eventList2": [ 123 { 124 "id": 1, 125 "label": { 126 "lang_tag": "button_is_pressed", 127 "text": "A button is pressed" 128 }, 118 129 "serviceId": "urn:upnp-esweb-nl:serviceId:EnoceanRPS1", 119 "argumentList": { 120 "argument_1": { 130 "argumentList": [ 131 { 132 "id": 1, 121 133 "dataType": "string", 122 134 "defaultValue": "", 123 "allowedValueList" : 124 { 125 "A1":"A1", "A0":"A0", 126 "B1":"B1", "B0":"B0", 127 "C1":"C1", "C0":"C0", 128 "D1":"D1", "D0":"D0" 129 }, 135 "allowedValueList": [ 136 { 137 "A1": "A1", 138 "HumanFriendlyText": { 139 "lang_tag": "hft_is_pressed", 140 "text": "_DEVICE_NAME_: A1 is pressed" 141 } 142 }, 143 { 144 "A0": "A0", 145 "HumanFriendlyText": { 146 "lang_tag": "hft_is_pressed", 147 "text": "_DEVICE_NAME_: A0 is pressed" 148 } 149 }, 150 { 151 "B1": "B1", 152 "HumanFriendlyText": { 153 "lang_tag": "hft_is_pressed", 154 "text": "_DEVICE_NAME_: B1 is pressed" 155 } 156 }, 157 { 158 "B0": "B0", 159 "HumanFriendlyText": { 160 "lang_tag": "hft_is_pressed", 161 "text": "_DEVICE_NAME_: B0 is pressed" 162 } 163 }, 164 { 165 "C1": "C1", 166 "HumanFriendlyText": { 167 "lang_tag": "hft_is_pressed", 168 "text": "_DEVICE_NAME_: C1 is pressed" 169 } 170 }, 171 { 172 "C0": "C0", 173 "HumanFriendlyText": { 174 "lang_tag": "hft_is_pressed", 175 "text": "_DEVICE_NAME_: C0 is pressed" 176 } 177 }, 178 { 179 "D1": "D1", 180 "HumanFriendlyText": { 181 "lang_tag": "hft_is_pressed", 182 "text": "_DEVICE_NAME_: D1 is pressed" 183 } 184 }, 185 { 186 "D0": "D0", 187 "HumanFriendlyText": { 188 "lang_tag": "hft_is_pressed", 189 "text": "_DEVICE_NAME_: D0 is pressed" 190 } 191 } 192 ], 130 193 "name": "Button", 131 194 "comparisson": "=", 132 "prefix": "Button", 133 "suffix": "" 134 } 135 } 136 }, 137 "event_2": { 138 "label": "A button is released", 195 "prefix": { 196 "lang_tag": "button", 197 "text": "What button?" 198 }, 199 "suffix": {} 200 } 201 ] 202 }, 203 { 204 "id": 2, 205 "label": { 206 "lang_tag": "button_is_released", 207 "text": "A button is released" 208 }, 139 209 "serviceId": "urn:upnp-esweb-nl:serviceId:EnoceanRPS1", 140 210 "serviceStateTable": { 141 211 "Released": { 142 212 "value": "1", 143 "comparisson": "=" 144 } 145 }, 146 "argumentList": { 147 "argument_1": { 213 "comparisson": "=" 214 } 215 }, 216 "argumentList": [ 217 { 218 "id": 1, 148 219 "dataType": "boolean", 149 "allowedValueList": { 150 "Yes": "1", 151 "No": "0" 152 }, 220 "allowedValueList": [ 221 { 222 "Yes": "1", 223 "HumanFriendlyText": { 224 "lang_tag": "hft_is_released", 225 "text": "_DEVICE_NAME_: Button is released" 226 } 227 }, 228 { 229 "No": "0", 230 "HumanFriendlyText": { 231 "lang_tag": "hft_is_not_released", 232 "text": "_DEVICE_NAME_: Button is not released" 233 } 234 } 235 ], 153 236 "name": "Released", 154 237 "comparisson": "=", 155 "prefix": "Released",156 "suffix": " "157 } 158 }159 } 160 },238 "prefix": {}, 239 "suffix": {} 240 } 241 ] 242 } 243 ], 161 244 "DeviceType": "urn:schemas-esweb-nl:device:EnoceanRPS:1", 162 "device_type": "urn:schemas-esweb-nl:device:EnoceanRPS:1" 245 "device_type": "urn:schemas-esweb-nl:device:EnoceanRPS:1" 163 246 } -
/I_Enocean.xml
r1 r3 5 5 </settings> 6 6 <functions> 7 8 7 8 -- EnOcean Message Structure Constants 9 9 EO_HSEQ = 3 10 10 EO_ORG = 4 … … 18 18 EO_ID0 = 12 19 19 EO_Status = 13 20 21 20 21 local ipAddress 22 22 local ipPort 23 23 local buffer = "" 24 24 25 25 bitw = require("bit") 26 26 27 27 -- 28 28 -- Used for performance timing hooks in the callouts … … 32 32 33 33 -- Thanks to guessed for this snippet. 34 35 36 37 38 39 40 41 42 43 34 function findChild(parentDevice, label) 35 for k, v in pairs(luup.devices) do 36 if (v.device_num_parent == parentDevice and v.id == label) then 37 return k 38 end 39 end 40 41 -- Dump a copy of the Global Module list for debugging purposes. 42 luup.log("findChild cannot find parentDevice: " .. tostring(parentDevice) .. " label: " .. label) 43 for k, v in pairs(luup.devices) do 44 44 luup.log("Device Number: " .. k .. 45 46 47 48 49 end 50 45 " v.device_type: " .. tostring(v.device_type) .. 46 " v.device_num_parent: " .. tostring(v.device_num_parent) .. 47 " v.id: " .. tostring(v.id) 48 ) 49 end 50 end 51 51 52 52 function mainStartup(lul_device) 53 54 55 56 57 53 PARENT_DEVICE = lul_device 54 Enocean_Devices_1BS = {} 55 Enocean_Devices_RPS = {} 56 Enocean_Count_1BS = 0 57 Enocean_Count_RPS = 0 58 58 59 59 luup.log("Starting Enocean device: " .. tostring(lul_device)) … … 65 65 end 66 66 67 68 69 70 71 72 73 74 75 67 for k, v in pairs(luup.devices) do 68 if (v.device_num_parent == lul_device) then 69 luup.log( "Found child device, lets save! id " .. tostring(v.id) .. " device " .. tostring(v.device_type)) 70 71 if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:DoorSensor:1") then 72 Enocean_Count_1BS = Enocean_Count_1BS + 1 73 Enocean_Devices_1BS[Enocean_Count_1BS] = v.id 74 end 75 if (tostring(v.device_type) == "urn:schemas-esweb-nl:device:EnoceanRPS:1") then 76 76 Enocean_Count_RPS = Enocean_Count_RPS + 1 77 77 Enocean_Devices_RPS[Enocean_Count_RPS] = v.id 78 79 80 81 82 83 78 end 79 end 80 end 81 82 ipAddress = device.ip 83 84 84 local portList = luup.variable_get("urn:upnp-esweb-nl:serviceId:Enocean1", "portList", lul_device) 85 85 if ((portList or "") == "") then … … 88 88 elseif (portList:find("%d") == nil) then 89 89 return false, "The Port parameter must be of the form nnnn. eg. 1470" 90 end 91 92 90 end 91 92 ipPort = portList 93 93 94 94 luup.log("open socket for read " .. ipAddress .. " port " .. ipPort ) 95 95 luup.io.open(lul_device, ipAddress, ipPort) 96 96 97 98 end 99 100 101 102 103 104 105 106 107 108 109 97 return true, "ok", "enocean" 98 end 99 100 101 function sendData( dataBuf ) 102 luup.log("Sending data " .. dataBuf ) 103 104 luup.io.write(dataBuf) 105 end 106 107 function processData( dataBuf ) 108 109 local EO_ID = getEnoceanID( dataBuf ) 110 110 111 111 luup.log("Received data " .. EO_ID .. " " .. getEnoceanMsg( dataBuf ) ) 112 113 114 115 116 117 118 luup.log( "device not found..." ) 112 113 local lsMsgT = getMsgType( dataBuf) 114 115 local EO_DEV = findChild(PARENT_DEVICE, EO_ID ) 116 117 if EO_DEV == nil then 118 luup.log( "device not found..." ) 119 119 120 local child_devices = luup.chdev.start(PARENT_DEVICE); 121 122 120 local child_devices = luup.chdev.start(PARENT_DEVICE); 121 122 for teller = 1, Enocean_Count_1BS do 123 123 luup.chdev.append(PARENT_DEVICE, child_devices, Enocean_Devices_1BS[teller], "Enocean 1BS Sensor #" .. Enocean_Devices_1BS[teller] , 124 124 "urn:schemas-micasaverde-com:device:DoorSensor:1","D_DoorSensor1.xml","","",false) 125 126 125 end 126 for teller = 1, Enocean_Count_RPS do 127 127 luup.chdev.append(PARENT_DEVICE, child_devices, Enocean_Devices_RPS[teller], "Enocean RPS Remote #" .. Enocean_Devices_RPS[teller] , 128 128 "urn:schemas-esweb-nl:device:EnoceanRPS:1","D_EnoceanRPS.xml","","",false) 129 130 131 132 129 end 130 131 if lsMsgT == "1BS" then 132 luup.log("EO 1BS ID " .. EO_ID .. " not found. Creating child device.") 133 133 luup.chdev.append(PARENT_DEVICE, child_devices, EO_ID, "Enocean 1BS Sensor #" .. EO_ID , 134 134 "urn:schemas-micasaverde-com:device:DoorSensor:1","D_DoorSensor1.xml","","",false) 135 136 137 end 138 139 140 135 Enocean_Count_1BS = Enocean_Count_1BS + 1 136 Enocean_Devices_1BS[Enocean_Count_1BS] = EO_ID 137 end 138 139 if lsMsgT == "RPS" then 140 luup.log("EO RPS ID " .. EO_ID .. " not found. Creating child device.") 141 141 luup.chdev.append(PARENT_DEVICE, child_devices, EO_ID, "Enocean RPS Remote #" .. EO_ID , 142 142 "urn:schemas-esweb-nl:device:EnoceanRPS:1","D_EnoceanRPS.xml","","",false) 143 144 145 146 147 148 149 150 151 143 Enocean_Count_RPS = Enocean_Count_RPS + 1 144 Enocean_Devices_RPS[Enocean_Count_RPS] = EO_ID 145 end 146 147 luup.chdev.sync(PARENT_DEVICE, child_devices) 148 149 EO_DEV = findChild(PARENT_DEVICE, EO_ID ) 150 151 end 152 152 153 153 if EO_DEV ~= nil then 154 154 155 156 local TrippedValue = "1" 157 158 --luup.log( "set tripped value " .. TrippedValue .. " to dev " .. EO_ID ) 155 if lsMsgT == "1BS" then 156 local TrippedValue = "1" 157 if ( get1BSDataContact( dataBuf) ) then TrippedValue = "0" end 158 --luup.log( "set tripped value " .. TrippedValue .. " to dev " .. EO_ID ) 159 159 luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", TrippedValue, EO_DEV) 160 160 161 161 end 162 162 163 164 163 if lsMsgT == "RPS" then 164 165 165 if (getRPSStatusNU( dataBuf) ) then 166 167 local ReleasedValue = "0" 168 169 170 171 172 local ReleasedValue = "0" 173 174 175 166 local lsValue = getRPSButton( dataBuf ) 167 local ReleasedValue = "0" 168 --luup.log("Sending button " .. lsValue .. " and releasedvalue " .. ReleasedValue ) 169 luup.variable_set("urn:upnp-esweb-nl:serviceId:EnoceanRPS1", "Button", lsValue, EO_DEV) 170 luup.variable_set("urn:upnp-esweb-nl:serviceId:EnoceanRPS1", "Released", ReleasedValue, EO_DEV) 171 else 172 local ReleasedValue = "0" 173 if ( getRPSAction( dataBuf ) == "released" ) then ReleasedValue = "1" end 174 --luup.log("Sending releasedvalue " .. ReleasedValue ) 175 luup.variable_set("urn:upnp-esweb-nl:serviceId:EnoceanRPS1", "Released", ReleasedValue, EO_DEV) 176 176 end 177 177 end 178 178 end 179 179 end 180 180 181 181 function formattohex(dataBuf) 182 183 184 185 186 187 188 end 189 190 191 192 193 194 195 196 197 198 eID = eID ..string.format("%02X:%02X", string.byte(dataBuf, EO_ID1), string.byte(dataBuf, EO_ID0) )199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 182 local resultstr = "" 183 184 if ( dataBuf ~= nil) then 185 for teller = 1, string.len(dataBuf) do 186 resultstr = resultstr .. string.format("%02X ", string.byte(dataBuf, teller) ) 187 end 188 end 189 -- Received data A5 5A B 5 30 0 0 0 0 15 A5 BB 30 E5 190 -- [RPS: ID=00:15:A5:BB, Data=Button A1: pressed 2Button B1, Status=[T21=1, NU=1, RP_COUNTER=0]] 191 192 return resultstr 193 end 194 195 --Enocean ID is formatted as: 00:15:A5:BB 196 function getEnoceanID( dataBuf ) 197 local eID = string.format("%02X:%02X:", string.byte(dataBuf, EO_ID3), string.byte(dataBuf, EO_ID2)) 198 eID = eID .. string.format("%02X:%02X", string.byte(dataBuf, EO_ID1), string.byte(dataBuf, EO_ID0) ) 199 return eID 200 end 201 202 function getEnoceanMsg( dataBuf ) 203 local lsMsg = getMsgType( dataBuf) 204 205 if lsMsg == "RPS" then 206 lsMsg = lsMsg .. ": " .. getRPS( dataBuf ) 207 end 208 if lsMsg == "1BS" then 209 lsMsg = lsMsg .. ": " .. get1BS( dataBuf ) 210 end 211 212 return lsMsg 213 end 214 215 function getMsgType(podataBuf) 216 local lsMsg = "unknown" 217 218 if string.byte(podataBuf, EO_ORG) == 5 then 219 lsMsg = "RPS" 220 end 221 if string.byte(podataBuf, EO_ORG) == 6 then 222 lsMsg = "1BS" 223 end 224 225 return lsMsg 226 end 227 228 function getRPS( podataBuf ) 229 local lsValue = "" 230 if (getRPSStatusNU( podataBuf) ) then 231 lsValue = "Button " .. getRPSButton( podataBuf ) .. " " .. getRPSAction( podataBuf ) 232 else 233 lsValue = "Button " .. getRPSAction( podataBuf ) 234 end 235 return lsValue 236 end 237 238 function get1BS( podataBuf ) 239 local lsValue = "Contact open" 240 241 if get1BSDataContact( podataBuf) then 242 lsValue = "Contact closed" 243 end 244 return lsValue 245 end 246 247 function get1BSDataContact( podataBuf ) 248 return (bitw.band( string.byte(podataBuf, EO_DB3), 0x01) > 0) 249 end 250 251 252 -- When statusNu = 1 then button pressed and button identified. when 0: released and unknown 253 function getRPSStatusNU( podataBuf ) 254 return (bitw.band( string.byte(podataBuf, EO_Status), 0x10) > 0) 255 end 256 257 258 -- There are four possible buttons: A1, A0, B1, B0 259 function getRPSButton( podataBuf ) 260 local lsBtn = string.char( 65 + bitw.rshift( string.byte(podataBuf, EO_DB3), 6) ) 261 if (bitw.band( string.byte(podataBuf, EO_DB3), 0x20) > 0) then lsBtn = lsBtn .. "0" else lsBtn = lsBtn .. "1" end 262 return lsBtn 263 end 264 265 -- Get pressed or released 266 function getRPSAction( podataBuf ) 267 local lsAction = "released" 268 if ( bitw.band( string.byte(podataBuf, EO_DB3), 0x10) > 0) then lsAction = "pressed" end 269 return lsAction 270 end 271 271 272 272 … … 278 278 local duration 279 279 280 280 if ( string.len(buffer) == 0 ) then 281 281 startTime = socket.gettime() 282 282 else 283 283 endTime = socket.gettime() 284 duration = math.floor((endTime - startTime) * 1000) 285 286 284 duration = math.floor((endTime - startTime) * 1000) 285 if (duration > 500) then 286 luup.log("timeout on buffer : " .. buffer) 287 287 288 289 290 end 291 292 293 294 295 288 startTime = socket.gettime() 289 buffer = "" 290 end 291 end 292 293 buffer = buffer .. data 294 295 if ( string.len(buffer) == 14 ) then 296 296 processData( buffer ) 297 298 299 297 buffer = "" 298 end 299 300 300 </lua> 301 301 </incoming> … … 303 303 <startup>mainStartup</startup> 304 304 <actionList> 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 305 <action> 306 <serviceId>urn:micasaverde-com:serviceId:SecuritySensor1</serviceId> 307 <name>GetArmed</name> 308 <run> 309 luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",lul_device) 310 </run> 311 </action> 312 <action> 313 <serviceId>urn:micasaverde-com:serviceId:SecuritySensor1</serviceId> 314 <name>SetArmed</name> 315 <run> 316 luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",lul_settings.newArmedValue,lul_device) 317 </run> 318 </action> 319 <action> 320 <serviceId>urn:micasaverde-com:serviceId:SecuritySensor1</serviceId> 321 <name>GetTripped</name> 322 <run> 323 luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",lul_device) 324 </run> 325 </action> 326 <action> 327 <serviceId>urn:micasaverde-com:serviceId:SecuritySensor1</serviceId> 328 <name>SetTripped</name> 329 <run> 330 luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",lul_settings.newTrippedValue,lul_device) 331 </run> 332 </action> 333 333 </actionList> 334 334 -
/D_Enocean.json
r1 r3 7 7 "imgIconMax": "", 8 8 "halloIconsDir": "pics\/hallo", 9 "inScene": "0", 9 10 "DisplayStatus": { 10 11 }, … … 14 15 "doc_version": 1, 15 16 "doc_platform": 0, 16 "doc_page": "devices" 17 "doc_page": "devices" 17 18 }, 18 19 "Tabs": [ … … 20 21 "Label": { 21 22 "lang_tag": "tabname_control", 22 "text": "Settings" 23 "text": "Settings" 23 24 }, 24 25 "Position": "0", 25 26 "TabType": "flash", 27 "SceneGroup":[ 28 { 29 "id": "1", 30 "top": "1", 31 "left": "0", 32 "x": "2", 33 "y": "1" 34 } 35 ], 26 36 "ControlGroup": [ 27 37 { 28 38 "id": "1", 29 "type": "info" 39 "type": "info", 40 "scenegroup": "1" 30 41 } 31 42 ], 32 43 "Control": [ 33 44 { 34 "ControlGroup": "1",35 "ControlPair": "1",36 "ControlHeader": "1",37 45 "ControlType": "label", 38 46 "Label": { 39 47 "lang_tag": "device_settings_page", 40 "text": "Port" 48 "text": "Port" 41 49 }, 42 50 "Display": { … … 44 52 "Left": 50, 45 53 "Width": 120, 46 "Height": 20 47 } 54 "Height": 20 55 } 48 56 }, 49 57 { 50 "ControlGroup": "1",51 "ControlPair": "1",52 "ControlHeader": "1",53 58 "ControlType": "variable", 54 59 "Display": { … … 58 63 "Left": 170, 59 64 "Width": 120, 60 "Height": 20 61 } 65 "Height": 20 66 } 62 67 }, 63 ] 68 ] 64 69 }, 65 70 { 66 71 "Label": { 67 72 "lang_tag": "advanced", 68 "text": "Advanced" 73 "text": "Advanced" 69 74 }, 70 75 "Position": "2", 71 76 "TabType": "javascript", 72 77 "ScriptName": "shared.js", 73 "Function": "advanced_device" 78 "Function": "advanced_device" 74 79 } 75 80 ]
Note: See TracChangeset
for help on using the changeset viewer.