- Location:
- /trunk
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk/D_CurrentCostEnviR1.json
r1 r3 84 84 { 85 85 "ControlGroup": "2", 86 "ControlPair": " 1",87 "ControlHeader": " 0",86 "ControlPair": "2", 87 "ControlHeader": "2", 88 88 "ControlType": "label", 89 89 "Label": { … … 100 100 { 101 101 "ControlGroup": "2", 102 "ControlPair": " 1",103 "ControlHeader": " 0",102 "ControlPair": "2", 103 "ControlHeader": "2", 104 104 "ControlType": "variable", 105 105 "Display": { … … 107 107 "Variable": "CurrentTemperature", 108 108 "Top": 90, 109 "Left": 145, 110 "Width": 75, 111 "Height": 20 112 } 113 }, 114 { 115 "ControlGroup": "2", 116 "ControlPair": "2", 117 "ControlHeader": "2", 118 "ControlType": "label", 119 "Label": { 120 "lang_tag": "dayssincebirth", 121 "text": "Days since birth:" 122 }, 123 "Display": { 124 "Top": 120, 125 "Left": 50, 126 "Width": 75, 127 "Height": 20 128 } 129 }, 130 { 131 "ControlGroup": "2", 132 "ControlPair": "2", 133 "ControlHeader": "2", 134 "ControlType": "variable", 135 "Display": { 136 "Service": "urn:futzle-com:serviceId:CurrentCostEnviR1", 137 "Variable": "DaysSinceBirth", 138 "Top": 120, 139 "Left": 145, 140 "Width": 75, 141 "Height": 20 142 } 143 }, 144 { 145 "ControlGroup": "2", 146 "ControlPair": "2", 147 "ControlHeader": "2", 148 "ControlType": "label", 149 "Label": { 150 "lang_tag": "time", 151 "text": "Console time:" 152 }, 153 "Display": { 154 "Top": 150, 155 "Left": 50, 156 "Width": 75, 157 "Height": 20 158 } 159 }, 160 { 161 "ControlGroup": "2", 162 "ControlPair": "2", 163 "ControlHeader": "2", 164 "ControlType": "variable", 165 "Display": { 166 "Service": "urn:futzle-com:serviceId:CurrentCostEnviR1", 167 "Variable": "Time", 168 "Top": 150, 169 "Left": 145, 170 "Width": 75, 171 "Height": 20 172 } 173 }, 174 { 175 "ControlGroup": "2", 176 "ControlPair": "2", 177 "ControlHeader": "2", 178 "ControlType": "label", 179 "Label": { 180 "lang_tag": "version", 181 "text": "Version:" 182 }, 183 "Display": { 184 "Top": 180, 185 "Left": 50, 186 "Width": 75, 187 "Height": 20 188 } 189 }, 190 { 191 "ControlGroup": "2", 192 "ControlPair": "2", 193 "ControlHeader": "2", 194 "ControlType": "variable", 195 "Display": { 196 "Service": "urn:futzle-com:serviceId:CurrentCostEnviR1", 197 "Variable": "Version", 198 "Top": 180, 109 199 "Left": 145, 110 200 "Width": 75, … … 201 291 } 202 292 } 203 } ,293 } 204 294 }, 205 "DeviceType": "urn:schemas-futzle-com:device:CurrentCostEnvi r:1"295 "DeviceType": "urn:schemas-futzle-com:device:CurrentCostEnviR:1" 206 296 } -
/trunk/D_CurrentCostEnviR1.xml
r1 r3 6 6 </specVersion> 7 7 <device> 8 <deviceType>urn:schemas-futzle-com:device:CurrentCostEnvi r:1</deviceType>8 <deviceType>urn:schemas-futzle-com:device:CurrentCostEnviR:1</deviceType> 9 9 <staticJson>D_CurrentCostEnviR1.json</staticJson> 10 10 <serviceList> 11 <service> 12 <serviceType>urn:schemas-futzle-com:service:CurrentCostEnviR:1</serviceType> 13 <serviceId>urn:futzle-com:serviceId:CurrentCostEnviR1</serviceId> 14 <SCPDURL>S_CurrentCostEnviR1.xml</SCPDURL> 15 </service> 11 16 <service> 12 17 <serviceType>urn:schemas-micasaverde-com:service:EnergyMetering:1</serviceType> -
/trunk/I_CurrentCostEnviR1.xml
r1 r3 3 3 <settings> 4 4 <protocol>crlf</protocol> 5 5 <handleChildren>1</handleChildren> 6 6 </settings> 7 7 <functions> 8 8 9 9 -- Power used/consumed by each appliance (0 is the "whole house" appliance). 10 APPLIANCE_POWER = { 11 ["0"] = 0, 12 ["1"] = 0, 13 ["2"] = 0, 14 ["3"] = 0, 15 ["4"] = 0, 16 ["5"] = 0, 17 ["6"] = 0, 18 ["7"] = 0, 19 ["8"] = 0, 20 ["9"] = 0 21 } 10 APPLIANCE_POWER = { } 22 11 SERVICE_ID = "urn:futzle-com:serviceId:CurrentCostEnviR1" 23 12 ENERGY_SERVICE_ID = "urn:micasaverde-com:serviceId:EnergyMetering1" … … 28 17 function initialize(lul_device) 29 18 luup.log("Initializing CurrentCost EnviR") 19 -- Help prevent race condition 20 luup.io.intercept() 30 21 31 -- Compute total power use using this formula. 22 -- Create child devices for the attached appliances. 23 local childDevices = luup.chdev.start(lul_device) 24 for child = 0, 9 do 25 if (luup.variable_get(SERVICE_ID, "Appliance" .. tostring(child), lul_device) or "0" ~= "0") then 26 luup.chdev.append(lul_device, childDevices, "Appliance" .. tostring(child), 27 "Appliance " .. child, "urn:schemas-futzle-com:device:CurrentCostEnvirAppliance:1", 28 "D_CurrentCostEnviRAppliance1.xml", "", "", false) 29 end 30 end 31 luup.chdev.sync(lul_device, childDevices) 32 33 -- Compute total power use for the parent device using this formula. 32 34 -- Formula string contains sequences of +n or -n, 33 35 -- adding or subtracting the appliance to compute a total. … … 44 46 end 45 47 luup.log("Power formula: " .. FORMULA) 48 49 -- Automatically detect appliances and create child devices 50 -- the next time that the Luup engine is reloaded. 51 AUTO_DETECT = luup.variable_get(SERVICE_ID, "ApplianceAutoDetect", lul_device) 52 if (AUTO_DETECT == nil) then 53 luup.variable_set(SERVICE_ID, "ApplianceAutoDetect", "1", lul_device) 54 end 46 55 end 47 56 … … 51 60 for sign, appliance in formula:gfind("([+-])%s-(%d)") do 52 61 if (sign == "+") then 53 total = total + APPLIANCE_POWER[appliance]62 total = total + (APPLIANCE_POWER[appliance] or 0) 54 63 elseif (sign == "-") then 55 total = total - APPLIANCE_POWER[appliance]64 total = total - (APPLIANCE_POWER[appliance] or 0) 56 65 end 57 66 end … … 72 81 watts = tostring(tonumber(watts)) 73 82 if (DEBUG) then luup.log("Sensor " .. sensor .. ": " .. watts .. " W") end 83 84 -- Log the child device's power (if there is a child device). 85 for k, v in pairs(luup.devices) do 86 if (v.device_num_parent == lul_device and v.id == "Appliance" .. sensor) then 87 luup.variable_set(ENERGY_SERVICE_ID, "Watts", watts, k) 88 end 89 end 90 91 -- Note this appliance number, if permitted. 92 if (AUTO_DETECT or "0" ~= "0") then 93 luup.variable_set(SERVICE_ID, "Appliance" .. sensor, id, lul_device) 94 end 95 96 -- Compute parent device's reading. 74 97 APPLIANCE_POWER[sensor] = watts 75 98 luup.variable_set(ENERGY_SERVICE_ID, "Watts", calculateFormula(), lul_device) 99 100 -- Store the EnviR's firmware version. 101 luup.variable_set(SERVICE_ID, "Version", source, lul_device) 102 103 -- Store the EnviR's concept of the date. 104 luup.variable_set(SERVICE_ID, "DaysSinceBirth", tonumber(dsb), lul_device) 105 luup.variable_set(SERVICE_ID, "Time", time, lul_device) 106 107 -- Log temperature. We get it for free. 76 108 luup.variable_set(TEMPERATURE_SERVICE_ID, "CurrentTemperature", tmpr, lul_device) 77 109 end
Note: See TracChangeset
for help on using the changeset viewer.