script help

Pop your questions regarding Home automation Domotica hardware here.....
Post Reply
Edwin
Member
Member
Posts: 447
Joined: Sat Oct 20, 2007 6:37 am
Location: Netherlands

script help

Post by Edwin »

h i need some help withthis lua script, "i get the error xml word niet goed gelezen" what is my mistake?
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>
lua script:

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
yjb
Member
Member
Posts: 211
Joined: Fri Apr 17, 2009 1:15 pm
Location: Venhuizen, Netherlands

Re: script help

Post by yjb »

Without looking further it seems that you are missing the closing quote of the appliances branch:

Code: Select all

</appliances>
Edwin
Member
Member
Posts: 447
Joined: Sat Oct 20, 2007 6:37 am
Location: Netherlands

Re: script help

Post by Edwin »

Thanks for your help,
But where you mean?
yjb
Member
Member
Posts: 211
Joined: Fri Apr 17, 2009 1:15 pm
Location: Venhuizen, Netherlands

Re: script help

Post by yjb »

Hi,

Since you start the entire definition with the following tag (appliances):

Code: Select all

<appliances>
Everything that follows is part of that definition, but at some point XML expects an "ending" tag as well. As definitions are balanced, the 1st tag is also the closing tag of the entire definition

Code: Select all

</appliances>
There might be other stuff wrong, but from an XML perspective you are missing a closing delimiter.
Edwin
Member
Member
Posts: 447
Joined: Sat Oct 20, 2007 6:37 am
Location: Netherlands

Re: script help

Post by Edwin »

Sorry this is the xml file:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<appliances>
<%
if ((Request.get["mac"] != undefined) && (Request.get["mac"] != ''))
$macfilter = Request.get["mac"]
else
$macfilter = ''
/if

foreach Plugwise.Appliances
$appliance = $_Value
if (($macfilter == '') || ($macfilter == $appliance.Module.MacAddress))
echo "<appliance>"
echo "<macaddress>",$appliance.Module.MacAddress,"</macaddress>"
echo "<name>",$appliance.Name.Replace("'","`").Replace("&","+").Replace("<","("),"</name>"
echo "<currentpowerusagewatts>",$appliance.PowerUsage,"</currentpowerusagewatts>"
echo "</appliance>\n"




/if
/foreach
%>
</appliances>


The one in my first post is the outcome in internet explorer.
I think its something else or am i wrong?
yjb
Member
Member
Posts: 211
Joined: Fri Apr 17, 2009 1:15 pm
Location: Venhuizen, Netherlands

Re: script help

Post by yjb »

I'm sorry, I can't help you with the lua stuff, as I do not really have experience. I would; check again in a flatfile editor that the trailing /appliances is really part of the xml (as it should be).
Last edited by yjb on Fri Jan 06, 2017 10:06 am, edited 1 time in total.
Edwin
Member
Member
Posts: 447
Joined: Sat Oct 20, 2007 6:37 am
Location: Netherlands

Re: script help

Post by Edwin »

Ok
Thanks for youre help
Post Reply

Return to “Questions & Discussions Forum”