- Files:
-
- 20 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk
- Property svn:ignore
-
old new 1 1 compressit 2 2 pushit 3 backup
-
- Property svn:ignore
-
/trunk/I_PingSensor.xml
r20 r30 11 11 <functions> 12 12 local PING_SID = "urn:demo-ted-striker:serviceId:PingSensor1" 13 local SWITCH_SID = "urn:upnp-org:serviceId:SwitchPower1" 13 14 local SECURITY_SID = "urn:micasaverde-com:serviceId:SecuritySensor1" 14 15 local HADEVICE_SID = "urn:micasaverde-com:serviceId:HaDevice1" 15 16 local GATEWAY_SID = "urn:micasaverde-com:serviceId:HomeAutomationGateway1" 16 17 17 local DEBUG_MODE = false18 local DEBUG_MODE = true 18 19 local DEFAULT_PERIOD = 15 19 20 local DEFAULT_ADDRESS = "127.0.0.1" … … 35 36 -- Initializes variables if none were found in config 36 37 -- 37 local function initSettings(address, period, invert )38 local function initSettings(address, period, invert, enable) 38 39 -- 39 40 -- Create a fallback delay if no parameters are given 40 41 -- 41 if (period == nil or period<= DEFAULT_PERIOD) then42 if (period == nil or tonumber(period) <= DEFAULT_PERIOD) then 42 43 period = DEFAULT_PERIOD 43 44 end … … 47 48 -- 48 49 address = address or DEFAULT_ADDRESS 50 51 -- 52 -- Default to being enabled. 53 -- 54 enable = enable or "1" 49 55 50 56 -- … … 57 63 luup.variable_set(PING_SID, "Address", address, parentDevice) 58 64 luup.variable_set(PING_SID, "Invert", invert, parentDevice) 65 luup.variable_set(SWITCH_SID, "Target", enable, parentDevice) 66 luup.variable_set(SWITCH_SID, "Status", enable, parentDevice) 59 67 60 68 luup.variable_set(HADEVICE_SID, "LastUpdate", os.time(os.date('*t')), parentDevice) … … 64 72 log("Initialized variable: 'Period' = " .. period) 65 73 log("Initialized variable: 'Invert' = " .. invert) 66 67 -- 68 -- due to strange behavior we have to restart the lua engine 69 -- if we wouldn't, the sensor would not appear as sensor in the UI 70 -- (the results of the action call do not matter) 71 -- 72 log("RESTARTING LUA TO INITIALIZE PING SENSOR!") 73 lul_resultcode, lul_resultstring, lul_job, lul_returnarguments = luup.call_action(GATEWAY_SID, "Reload", {}, 0) 74 75 return address, period, invert 74 log("Initialized variable: 'Enable' = " .. enable) 75 76 luup.task("Please restart Luup to initialize the plugin.", 1, "Ping Sensor", -1) 77 78 return address, period, invert, enable 76 79 end 77 80 78 81 79 82 local function readSettings(parentDevice) 80 local address = ""81 local period = ""82 local invert = ""83 84 83 -- 85 84 -- Get local address and delay between repetition from configuration 86 85 -- 87 address = luup.variable_get(PING_SID, "Address", parentDevice) 88 period = luup.variable_get(PING_SID, "Period", parentDevice) 89 invert = luup.variable_get(PING_SID, "Invert", parentDevice) 86 local address = luup.variable_get(PING_SID, "Address", parentDevice) 87 local period = luup.variable_get(PING_SID, "Period", parentDevice) 88 local invert = luup.variable_get(PING_SID, "Invert", parentDevice) 89 local enable = luup.variable_get(SWITCH_SID, "Status", parentDevice) 90 90 91 91 -- 92 92 -- init configuration variables if they were empty 93 93 -- 94 if (address == nil or period == nil or invert == nil ) then95 address, period, invert = initSettings(address, period, invert)96 end 97 98 return address, period, invert 94 if (address == nil or period == nil or invert == nil or enable == nil) then 95 address, period, invert, enable = initSettings(address, period, invert, enable) 96 end 97 98 return address, period, invert, enable 99 99 end 100 100 … … 120 120 -- 121 121 -- log("Address found was: " .. address .. " / Delay found was: " .. tostring(period) .. "s") 122 local address, period, invert = readSettings(parentDevice)122 local address, period, invert, enable = readSettings(parentDevice) 123 123 if (address == nil or period == nil) then 124 124 log("#" .. tostring(parentDevice) .. " starting up with id " .. luup.devices[parentDevice].id .. "could not be started.") … … 131 131 -- 132 132 PARENT_DEVICE = parentDevice 133 PING_ADDRESS = address134 PING_DELAY = period135 PING_INVERT = invert136 133 137 134 -- … … 203 200 local function setResult(parentDevice, pingResult) 204 201 -- Store the current ping result only when it has changed 205 local currentState = luup.variable_get(SECURITY_SID, "Tripped", parentDevice) 206 if (currentState ~= pingResult) then 202 local origTripped = luup.variable_get(SECURITY_SID, "Tripped", parentDevice) 203 origTripped = origTripped or "0" 204 205 if (origTripped ~= pingResult) then 207 206 local time = os.time(os.date('*t')) 208 local origTripped = luup.variable_get(SECURITY_SID, "Tripped", parentDevice)209 origTripped = origTripped or "0"210 207 211 208 luup.variable_set(SECURITY_SID, "Tripped", pingResult, parentDevice) … … 226 223 -- 227 224 -- Reset the timer at the beginning, just in case the subsequent code fails. 228 -- 225 -- 229 226 -- The last parameter is temporary, can be removed in later builds once bug fix 230 227 -- is in place (http://forum.micasaverde.com/index.php?topic=1608.0) 231 228 -- 232 luup.call_timer("refreshCache", 1, tostring(PING_DELAY), "") 233 234 -- ping the address, write result, inverted if necessary. 235 setResult(PARENT_DEVICE, invertResult(executePing(PING_ADDRESS), PING_INVERT)) 229 local address, period, invert, enable = readSettings(parentDevice) 230 luup.call_timer("refreshCache", 1, tostring(period), "") 231 232 -- 233 -- To avoid having to be able to "cancel" a running timer, esp after repeated 234 -- enable/disable calls, we simply "do nothing" in this code if the timer is 235 -- disabled. The actual timer itself is never stopped, we simply don't respond 236 -- if we're disabled. 237 -- 238 if (enable == "1") then 239 -- ping the address, write result, inverted if necessary. 240 setResult(PARENT_DEVICE, invertResult(executePing(address), invert)) 241 debug("Ping Enabled, executed") 242 else 243 debug("Ping Disabled, not executed " .. (enable or "No value")) 244 end 236 245 end 237 246 </functions> … … 295 304 </run> 296 305 </action> 306 307 <action> 308 <serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId> 309 <name>SetTarget</name> 310 <run> 311 luup.variable_set(SWITCH_SID, "Target", lul_settings.newTargetValue, parentDevice) 312 luup.variable_set(SWITCH_SID, "Status", lul_settings.newTargetValue, parentDevice) 313 </run> 314 </action> 297 315 </actionList> 298 316 </implementation> -
/trunk/D_PingSensor.xml
r20 r30 25 25 <SCPDURL>S_SecuritySensor1.xml</SCPDURL> 26 26 </service> 27 <service> 28 <serviceType>urn:schemas-upnp-org:service:SwitchPower:1</serviceType> 29 <serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId> 30 <SCPDURL>S_SwitchPower1.xml</SCPDURL> 31 </service> 27 32 </serviceList> 28 33 <implementationList> -
/trunk/D_PingSensor.json
r20 r30 7 7 "imgIconMax": "", 8 8 "halloIconsDir": "pics\/hallo", 9 "inScene": "1", 9 10 "DisplayStatus": { 10 11 "Service": "urn:micasaverde-com:serviceId:SecuritySensor1", 11 12 "Variable": "Tripped", 12 13 "MinValue": "0", 13 "MaxValue": "1" 14 "MaxValue": "1" 14 15 }, 15 16 "doc_url": { … … 18 19 "doc_version": 1, 19 20 "doc_platform": 0, 20 "doc_page": "sensors" 21 "doc_page": "sensors" 21 22 }, 22 23 "ToggleButton": 1, … … 25 26 "Label": { 26 27 "lang_tag": "tabname_control", 27 "text": "Control" 28 "text": "Control" 28 29 }, 29 30 "Position": "0", 30 31 "TabType": "flash", 32 "SceneGroup":[ 33 { 34 "id": "1", 35 "top": "0.5", 36 "left": "0", 37 "x": "2", 38 "y": "1" 39 }, 40 { 41 "id": "2", 42 "top": "2", 43 "left": "0", 44 "x": "2", 45 "y": "1" 46 } 47 ], 31 48 "ControlGroup":[ 32 49 { 33 50 "id": "1", 34 "isSingle": "1" 51 "isSingle": "1", 52 "scenegroup": "1" 35 53 }, 36 54 { 37 55 "id": "2", 38 "isSingle": "1" 56 "isSingle": "1", 57 "scenegroup": "2" 39 58 } 40 59 ], … … 45 64 "Label": { 46 65 "lang_tag": "cmd_arm", 47 "text": "Arm" 66 "text": "Arm" 48 67 }, 49 68 "Display": { … … 54 73 "Left": 50, 55 74 "Width": 75, 56 "Height": 20 75 "Height": 20 57 76 }, 58 77 "Command": { … … 62 81 { 63 82 "Name": "newArmedValue", 64 "Value": "1" 65 } 66 ] 67 } 83 "Value": "1" 84 } 85 ] 86 } 68 87 }, 69 88 { … … 72 91 "Label": { 73 92 "lang_tag": "cmd_bypass", 74 "text": "Bypass" 75 }, 93 "text": "Bypass" 94 }, 95 "left": "1", 76 96 "Display": { 77 97 "Service": "urn:micasaverde-com:serviceId:SecuritySensor1", … … 81 101 "Left": 145, 82 102 "Width": 75, 83 "Height": 20 103 "Height": 20 84 104 }, 85 105 "Command": { … … 89 109 { 90 110 "Name": "newArmedValue", 91 "Value": "0" 92 } 93 ] 94 } 111 "Value": "0" 112 } 113 ] 114 } 95 115 }, 96 116 { … … 144 164 "text": "Invert" 145 165 }, 166 "left": "1", 146 167 "Display": { 147 168 "Service": "urn:demo-ted-striker:serviceId:PingSensor1", … … 164 185 } 165 186 } 166 ] 187 ] 167 188 }, 168 189 { 169 190 "Label": { 170 191 "lang_tag": "advanced", 171 "text": "Advanced" 192 "text": "Advanced" 172 193 }, 173 194 "Position": "2", 174 195 "TabType": "javascript", 175 196 "ScriptName": "shared.js", 176 "Function": "advanced_device" 197 "Function": "advanced_device" 177 198 }, 178 199 { 179 200 "Label": { 180 201 "lang_tag": "logs", 181 "text": "Logs" 202 "text": "Logs" 182 203 }, 183 204 "Position": "4", 184 205 "TabType": "javascript", 185 206 "ScriptName": "shared.js", 186 "Function": "device_logs" 207 "Function": "device_logs" 187 208 }, 188 209 { 189 210 "Label": { 190 211 "lang_tag": "notifications", 191 "text": "Notifications" 212 "text": "Notifications" 192 213 }, 193 214 "Position": "5", 194 215 "TabType": "javascript", 195 216 "ScriptName": "shared.js", 196 "Function": "device_notifications" 197 } 217 "Function": "device_notifications" 218 } 198 219 ], 199 220 "sceneList": { … … 204 225 "action": "SetArmed", 205 226 "arguments": { 206 "newArmedValue": "1" 227 "newArmedValue": "1" 207 228 }, 208 229 "display": { … … 210 231 "variable": "Armed", 211 232 "value": "1" 212 } 233 } 213 234 }, 214 235 "cmd_2": { … … 217 238 "action": "SetArmed", 218 239 "arguments": { 219 "newArmedValue": "0" 240 "newArmedValue": "0" 220 241 }, 221 242 "display": { … … 223 244 "variable": "Armed", 224 245 "value": "0" 225 } 226 } 227 } 246 } 247 } 248 }, 249 "group_2": { 250 "cmd_3": { 251 "label": "Enable", 252 "serviceId": "urn:upnp-org:serviceId:SwitchPower1", 253 "action": "SetTarget", 254 "arguments": { 255 "newTargetValue": "1" 256 }, 257 "display": { 258 "service": "urn:upnp-org:serviceId:SwitchPower1", 259 "variable": "Status", 260 "value": "1" 261 } 262 }, 263 "cmd_4": { 264 "label": "Disable", 265 "serviceId": "urn:upnp-org:serviceId:SwitchPower1", 266 "action": "SetTarget", 267 "arguments": { 268 "newTargetValue": "0" 269 }, 270 "display": { 271 "service": "urn:upnp-org:serviceId:SwitchPower1", 272 "variable": "Status", 273 "value": "0" 274 } 275 } 276 } 228 277 }, 229 278 "eventList": { … … 237 286 "allowedValueList": { 238 287 "Yes": "1", 239 "No": "0" 288 "No": "0" 240 289 }, 241 290 "name": "Tripped", 242 291 "comparisson": "=", 243 292 "prefix": "Tripped?", 244 "suffix": "" 245 } 246 } 293 "suffix": "" 294 } 295 } 247 296 }, 248 297 "event_2": { … … 252 301 "Armed": { 253 302 "value": "1", 254 "comparisson": "=" 255 } 303 "comparisson": "=" 304 } 256 305 }, 257 306 "argumentList": { … … 260 309 "allowedValueList": { 261 310 "Yes": "1", 262 "No": "0" 311 "No": "0" 263 312 }, 264 313 "name": "Tripped", 265 314 "comparisson": "=", 266 315 "prefix": "Tripped?", 267 "suffix": " " 268 } 269 } 316 "suffix": " " 317 } 318 } 270 319 } 271 320 }, 272 "DeviceType": "urn:schemas-micasaverde-com:device:MotionSensor:1", 321 "eventList2": [ 322 { 323 "id": 1, 324 "label": { 325 "lang_tag": "door_window_motion_sensor_is_tripped", 326 "text": "A sensor (door\/window\/motion\/etc.) is tripped" 327 }, 328 "serviceId": "urn:micasaverde-com:serviceId:SecuritySensor1", 329 "argumentList": [ 330 { 331 "id": 1, 332 "dataType": "boolean", 333 "defaultValue": "", 334 "allowedValueList": [ 335 { 336 "Yes": "1", 337 "HumanFriendlyText": { 338 "lang_tag": "", 339 "text": "_DEVICE_NAME_ is Tripped" 340 } 341 }, 342 { 343 "No": "0", 344 "HumanFriendlyText": { 345 "lang_tag": "", 346 "text": "_DEVICE_NAME_ is not Tripped" 347 } 348 } 349 ], 350 "name": "Tripped", 351 "comparisson": "=", 352 "prefix": {}, 353 "suffix": {} 354 } 355 ] 356 }, 357 { 358 "id": 2, 359 "label": { 360 "lang_tag": "an_armed_sensor_is_tripped", 361 "text": "An armed sensor is tripped" 362 }, 363 "serviceId": "urn:micasaverde-com:serviceId:SecuritySensor1", 364 "serviceStateTable": { 365 "Armed": { 366 "value": "1", 367 "comparisson": "=" 368 } 369 }, 370 "argumentList": [ 371 { 372 "id": 1, 373 "dataType": "boolean", 374 "allowedValueList": [ 375 { 376 "Yes": "1", 377 "HumanFriendlyText": { 378 "lang_tag": "hft_sensor_tripped", 379 "text": "_DEVICE_NAME_ is Tripped" 380 } 381 }, 382 { 383 "No": "0", 384 "HumanFriendlyText": { 385 "lang_tag": "hft_sensor_not_tripped", 386 "text": "_DEVICE_NAME_ is not Tripped" 387 } 388 } 389 ], 390 "name": "Tripped", 391 "comparisson": "=", 392 "prefix": {}, 393 "suffix": {} 394 } 395 ] 396 } 397 ], 398 "DeviceType": "urn:schemas-micasaverde-com:device:MotionSensor:1" 273 399 }
Note: See TracChangeset
for help on using the changeset viewer.