i added the xml file and the script file
please help
thanks.
xml file:
Code: Select all
<appliances>
<appliance>
<macaddress>000D6F00003FF4FA</macaddress>
<name>CloseInBoiler</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FEC94</macaddress>
<name>CV-ketel</name>
<currentpowerusagewatts>9</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FF1DD</macaddress>
<name>Droger</name>
<currentpowerusagewatts>3</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F0000384709</macaddress>
<name>HsProServer</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FEE9C</macaddress>
<name>Koelkast</name>
<currentpowerusagewatts>92</currentpowerusagewatts>
</appliance>
Code: Select all
commandArray = {}
function XML_Capture(cmd,flatten)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if flatten then
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
end
return s
end
--zet up TRUE op in logfile weer te geven
debug = true
--vul hier de idx in van domoticz en hun namen
CloseInBoiler = 219
--CVketel = 216
--Droger = 217
--HsProServer = 218
--HWTemp_Flow = 108
--HWTemp_Return = 109
--HWTemp_Tank_Top = 110
--HWTemp_Tank_Bottom = 111
--vul hier de id`s of mac adressen in op volgorde
--kunnen nog meer bij gezet worden
sensorID_1 = "000D6F00003FF4FA"
--sensorID_2 = "000D6F00003FEC94"
--sensorID_3 = "000D6F00003FF1DD"
--sensorID_4 = "000D6F0000384709"
-- plaats hier het ipadres van plugwise
Device_IP = "192.168.2.167:xx"
if debug == true then
print("Reading values from: 'http://"..Device_IP.."/xml/edwin.xml'")
end
-- de xml file van plugwise
XML_string=XML_Capture("curl -s 'http://"..Device_IP.."/xml/edwin.xml'",1)
valid = string.find(XML_string, "<response>") -- controle
if debug == true then
print(XML_string)
end
if valid == nil then
print ("Xml word niet goed gelezen,Geen Update")
else
--vind de eerste sensor op zijn unieke id
i = string.find(XML_string,sensorID_1) -- vind de eerste sensor op uid
p = string.find(XML_string,"<currentpowerusagewatts>",i) --zoek voor de eerste verschijning van <currentpowerusagewatts> na uid
CloseInBoiler=string.sub(XML_string,p+0,p+0) --het verbruik is 5 karakters na <currentpowerusagewatts> - i.e. 24-26
commandArray[1] = {['UpdateDevice'] = CloseInBoiler.."|0|"..CloseInBoiler} --stuur geupdate waardes naar Domoticz
if debug == true then
print("temp returned = ".."'"..CloseInBoiler.."'")
end
end
return commandArray