but cant get it together, i want to read the PowerUsage of the CloseInBoiler out of an xml and send data to domoticz.
i`m doing something wrong but cant figure it out.
heres the xml:
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>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FF596</macaddress>
<name>Magnetron</name>
<currentpowerusagewatts>1</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FEEA4</macaddress>
<name>MediaCenter</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FE4C3</macaddress>
<name>Multimedia</name>
<currentpowerusagewatts>32</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FEE89</macaddress>
<name>ongebruikt</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FE733</macaddress>
<name>Ongebruikt2</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FEDFC</macaddress>
<name>PcEd</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FE4E9</macaddress>
<name>Router</name>
<currentpowerusagewatts>27</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FF6D1</macaddress>
<name>Senseo</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FEF52</macaddress>
<name>Televisie</name>
<currentpowerusagewatts>87</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FE4E0</macaddress>
<name>TvSlaapkamer</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FD7C2</macaddress>
<name>VijverPomp</name>
<currentpowerusagewatts>2</currentpowerusagewatts>
</appliance>
<appliance>
<macaddress>000D6F00003FD2F9</macaddress>
<name>Wasmachine</name>
<currentpowerusagewatts>0</currentpowerusagewatts>
</appliance>
</appliances>
Code: Select all
------------------------------------------------------------------------------------------
-- Version 2b 20160430
--
-- Domoticz lua script to convert XML output from FP4All_PVLogger
-- Reads the status based on the unique IP of the PVLogger and passes values
-- to virtual sensor(s) in Domoticz
-- Complete for Power & Energy, prepared for Temperature, Voltage and Current
--------------------------------------------------------------------------------------------------
-- Original script by RATA1 at Domoticz-forum, adapted by Toulon7559 (c)2016
--------------------------------------------------------------------------------------------------
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
-- Line 26: Set debug to true to print to log file.
debug = true
-- Line 29: Define the idx of your virtual sensors - i.e. what you have called your sensors and their IDX numbers
CloseInBoiler = 211
-- Line 37: Define your device IP-address
Device_IP = "192.168.2.197:7778"
if debug == true then
print("Reading values from: 'http://"..Device_IP.."/xml/appliances.xml'")
end
-- Line 45: Read the XML data from the device
XML_string=XML_Capture("curl -s 'http://"..Device_IP.."/xml/appliances.xml'",1)
valid = string.find(XML_string, "<response>") -- check we are looking in the right place
if debug == true then
print(XML_string)
end
if valid == nil then
print ("Bad XML status read - info NOT updated")
else
-- Line 59: Find in the XML_string the info-fields based on their labels
-- Determine start/stop-positions of the values within the substrings
p = string.find(XML_string,"PowerUsage=") -- read position of power string
-- Line 82: Extract the values and process for upload to Domoticz
-- Line 115
-- Line 127: Upload to Domoticz; to be expanded for upload of other values to related IDXes
commandArray[1] = {['UpdateDevice'] = CloseInBoiler.."|0|"} -- send updated values to Domoticz
if debug == true then
print("CloseInBoiler = )
end
end
return commandArray