XML data import Cumulus

Hi everybody, I’m quite new to openhab but realise it got huge potential. I’m trying to import XML data from xml file generatde by Cumulus weather station software files i pasted in below or atleast the most interesting parts, file is located in localhost c:\cumulus\data.xml i really hope someone could help me come up with a solution or just not a solution also giving me som new knowledge. And offcourse did I have to destroy some <tags i order to make pasted file visible.

/<?xml version="1.0" encoding="ISO-8859-1"?>
!–Cumulus WebTag XML Data file - version 1.8–>
weatherdata>
raintags>
item name=“TrrateYM”>
value>00:00/value>
unit>/unit>
image>/image>
class>dynamic/class>
description>Time of Yesterday’s maximum rain rate/description>

If you use code fences it preserves your code.

```
<your xml goes here>
```

There is no file binding that I’m aware of, though I could see how that would be useful. Since you are on Windows I think the easiest thing will be to use the Exec binding and either XSLT or XPath Transformation to extract the value you want.

The following Item will execute a command to echo the contents of data.xml every five minutes and pass that text to trrateym.xsl to extract the value.

String TrrateYM "Time of Yesterday's maximum rain rate [%s]" <rain> {exec="[type c:\\cumulus\\data.xml:300000:XSLT(trrateym.xsl)]"}
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
        <xsl:template match="/">
                <xsl:value-of select="//weatherdata/raintags/item/unit"/>
        </xsl:template>
</xsl:stylesheet>

NOTE: you have no indentation nor end tags so I’m just guessing on the path to <value>.

Hi thanks for your reply so the string lin will be in item file qnd the rest code will be i transform file? I hope i understood correctly but how do i display thos with sitemap file and call value from rules?

I think yes. Save the XSLT to a file name trrateym.xsl in the transformations folder.

sitemap:

Text item=TrrateYM 

In a Rule:

TrrateYM.state

Thanks one more I’ve now put in those things in files but couldnt see any outpu thought i will try to attach complete xml file, One basic question also do I need to install som other binding or import diffrent things in rules file?.data.xml (61.6 KB)

To use the above you need the Exec binding and if on OH 2 you need to install the XSLT transform as well.

Given the full and properly formatted XML the select should be:

"//weatherdata/raintags/item[@name='rrateYM']/value"

Hello Rik you rock but still there’s no value in my item should it really be to \ in the path?

I finally got xsl transformation to work on a web servcie by adding version=“1.0” to xsl:stylesheet tag, but it seems like I have some problem witch execution of string item there’s no event i debug log for this command.

I don’t know if I’ll be of any more help. The XML I’ve dealt with thus far is far simpler than this one.

I think that xsl file is correct since I could validate tha code and pull the correct data from xml file. Its just that I dont see any events for execution of script in my logs and i dont get any data. So probably I have some problem with exec binding or item configuration.

Given your description I would agree. What is are your Item definition?

Do you see any errors in the logs?

My item line looks like this after translation into swedish and changed value to pull from what you supposed, But i can validate regn.xsl file on webservcies to pull correct data from data.xml, if i add < in {exec=<"type… then openhab will atleast do something but I gett an error in Swedish say something like file ended to soon or abrubted something like that. Do i nedd to provide full path to data.xml in regn.xsl?, vaule to shoe will be yesterdays rain in mm to control irrigation.

String regn “Regn igår [%.d mm]” {exec="[type c:\Cumulus\data.xml:60000:XSLT(regn.xsl)]"}

Have a nice night and today our christmas three will be installed.

And here’s error logg

016-11-20 08:14:50.621 [ERROR] [.i.s.XsltTransformationService] - transformation throws exception
javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Filen har avslutats för tidigt.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source) ~[na:1.8.0_111]
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source) ~[na:1.8.0_111]
at org.openhab.core.transform.internal.service.XsltTransformationService.transform(XsltTransformationService.java:83) ~[na:na]
at org.openhab.binding.exec.internal.ExecBinding.transformResponse(ExecBinding.java:162) [bundlefile:na]
at org.openhab.binding.exec.internal.ExecBinding.execute(ExecBinding.java:136) [bundlefile:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.8.3.jar:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.8.3.jar:na]
Caused by: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Filen har avslutats för tidigt.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(Unknown Source) ~[na:1.8.0_111]
… 7 common frames omitted
Caused by: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Filen har avslutats för tidigt.
at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(Unknown Source) ~[na:1.8.0_111]
at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(Unknown Source) ~[na:1.8.0_111]
… 8 common frames omitted
2016-11-20 08:14:50.637 [ERROR] [.o.b.exec.internal.ExecBinding] - transformation throws exception [transformation=XSLT(regn.xsl), response=]
org.openhab.core.transform.TransformationException: transformation throws exception
at org.openhab.core.transform.internal.service.XsltTransformationService.transform(XsltTransformationService.java:86) ~[na:na]
at org.openhab.binding.exec.internal.ExecBinding.transformResponse(ExecBinding.java:162) [bundlefile:na]
at org.openhab.binding.exec.internal.ExecBinding.execute(ExecBinding.java:136) [bundlefile:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.8.3.jar:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.8.3.jar:na]
Caused by: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Filen har avslutats för tidigt.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source) ~[na:1.8.0_111]
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source) ~[na:1.8.0_111]
at org.openhab.core.transform.internal.service.XsltTransformationService.transform(XsltTransformationService.java:83) ~[na:na]
… 4 common frames omitted
Caused by: javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Filen har avslutats för tidigt.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getDOM(Unknown Source) ~[na:1.8.0_111]
… 7 common frames omitted
Caused by: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Filen har avslutats för tidigt.
at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(Unknown Source) ~[na:1.8.0_111]
at com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager.getDTM(Unknown Source) ~[na:1.8.0_111]
… 8 common frames omitted
2016-11-20 08:14:50.855 [WARN ] [o.u.i.items.ItemUIRegistryImpl] - Exception while formatting value ‘’ of item regn with format ‘%.d MM’: java.util.UnknownFormatConversionException: Conversion = ‘.’

Try replacing the spaces on your exec binding steering with @@

You do not provide the path or name of the xml inside the xslt at all.

The error indicates that the command is executing but the text received by the transform is either empty or is not valid XML.

Try removing the transform entirely and see what the raw text looks like.

Hmm now I’m really lost how do i remove transform?, if i deltede XSLT binfing error could be phrased correctly. Do I have to put somethoing in excec.persits?,

Change the XSLT(regn.csl) to REGEX((.*)). I’m not sure if the updates that let you use default have made it into the baseline you are using yet.

This will just pass the whole string unchanged to the Item.

Hi

Now I’ll only gett state updated to blank, could there be something really simple thats wrong, that I will miss.

That means the exec is not returning anything.

Instead of using the Exec binding, move the call to a Rule and use:

val results = executeCommandLine("type c:\Cumulus\data.xml", 5000)
logInfo("ExecTest", results)

If there is an error perhaps that will show what the error is.

Thanks for another good idea, but I’m not getting there got this strange message, I have had Xpath conersions into another home automation software before (switch king) so source file must be ok.

2016-11-23 06:35:20.308 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Väderstations temp’: Index: 0, Size: 0

Is there anything else I need to isntall on my cpu or any binding i havent thought of or some script issues. I’ve only installed exec binding and exec persitanace binding maybe need to import som new stuff into rules file?. I follow your earlier advice tp make a aswitch for testing.

I’m not asking you to do this to test the source file. There is something going wrong with exec to load the file.

Not needed. For this the exec binding is all you need.

Can you post your rule as written?

One thing to try is replace the space with @@

val results = executeCommandLine("type@@c:\Cumulus\data.xml", 5000)
logInfo("ExecTest", results)

You also might need to provide the full path for type. I’ve no idea what that is though but I’d guess it is in c:\windows\system32.