XML data import Cumulus

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.

Hi thanks for all your help but I’m still not getting there. I have been able to find the data.xml file in my eventslog but I didn’t see it in command windows so I have no idea in wich of all my experimental configurations it worked. Type is what microsoft call an internal command witvin command.com file which is found in c:\windows\system32 and that folder is in the system path so I can write the actual command whitin any folder to revieve data.xml output. I also tried to make a .bat file that do just that type c:\Cumulus\data.xml. but when Openhab is about to lanch command in some difrent configurations says commandline executed type c:\cumulus\data.xml but nothings happens whitin ghe logfile or att commandprompt or else i just get error messeage sayin index 0 size 0 which I assume is only saying it couldnt find file or something. It seems like most usees use Openhab in some kind of Linux system and windows users is a small community.

And here’s my rule as written I’ve tried diffrent approaches for instance replace space with @@ no diffrence and tried with specified path for command.com tried to place command.com whitin openhab root folder and replace \ with \ or /. It so frustating to know trhat I had it working but really couldn’t figure out how.

rule “Väderstations temp”

		Item exec changed
		if(exec.state==ON)  {
		val results = executeCommandLine("C:\\Windows\\System32\\type C:\\Cumulus\\data.xml", 5000)
		logInfo("ExecTest", results)


error message look like this
2016-11-25 06:42:18.732 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'Londonborg.rules’
2016-11-25 06:42:25.612 [WARN ] [g.openhab.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program “C:\Openhab\type” (in directory “.”): CreateProcess error=2, Det går inte att hitta filen)
2016-11-25 06:42:25.612 [INFO ] [.openhab.model.script.ExecTest] -

Log message when successfull output exist in openhab.log
2016-11-24 06:31:36.125 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'Londonborg.rules’
2016-11-24 06:31:47.450 [INFO ] [.openhab.model.script.ExecTest] -
C:\Openhab>type C:\Cumulus\data.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

This specific error means that OH is trying to run type in the default folder as opposed to its real location. So supplying the full path to it is needed.

For Windows paths you usually have to provide \ as the path separator but that is also the string escape character so you need to escape that as well resulting in all your \ becoming \\.

Hi again

I really couldn’t get this to work I think I tried everything error messeage below is the same even if I have @@ instead of space. So frustrating to see in the logfile that it has worked but I never realised that. I guess this is error message thjat it tries to look for a file named “type” bute theres no such file it’s an internal command thta built into command.com standard commands.

2016-11-26 08:14:26.352 [ERROR] [g.openhab.io.net.exec.ExecUtil] - couldn’t execute commandLine 'C:\Windows\System32\type C:\Cumulus\data.xml’
java.io.IOException: Cannot run program “C:\Windows\System32\type”: CreateProcess error=2, Det går inte att hitta filen
at java.lang.ProcessBuilder.start(Unknown Source) ~[na:1.8.0_111]
at java.lang.Runtime.exec(Unknown Source) ~[na:1.8.0_111]

And heres my rule hav tried to rpelace spacde between type and C: with @@ but makes no diffrent.

rule “Väderstations temp”

		Item exec changed
		if(exec.state==ON)  {
		val results = executeCommandLine("C:\\Windows\\System32\\type C:\\Cumulus\\data.xml")
		logInfo("ExecTest", results)
		postUpdate(exec, OFF)


Ah, that would explain the problem. I’m not sure there is a way to make this work on Windows then short of installing something like Mingw or something like that which will give you access to the Posix commands (mainly cat).

Yes that would be well above my skills, but as I can see in my log I have had this thing working but cant make it work again, I I says in the log how the command where executed and typed output of data.xmlll into Openhab commandline. So I schould be able to do this again, so bad that I didnt realize to look into logfiles between each new try. I don’t know if this helps to figure out how it schould be written, I have placed a copy of command.com in C:\Openhab


2016-11-24 06:31:36.125 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'Londonborg.rules’
2016-11-24 06:31:47.450 [INFO ] [.openhab.model.script.ExecTest] -
C:\Openhab>type C:\Cumulus\data.xml

<?xml version="1.0" encoding="ISO-8859-1"?> 2016-11-23 dynamic The current date 06:30 on 23 november 2016 dynamic The current time


Could there be a workaround for this to mqtt publish xml data or doesn’t mqtt brokers support xml data sources?

If you are up for writing something (or finding something) that will read in the file and publish the contents to MQTT then that would be an option. My sensorReporter could be a place to start. I’d love for someone to contribute a file watcher. :wink:

You will also have to run a broker and I don’t know what brokers will run on Windows.

But XML is just text and MQTT handles that with no problem.


I made a dirty sollution to this I upload the xml file to my webserver and make a http binding and it works. So now I get my data as I need to but gett erroes when I try to configure my item as Number but i works ok with String, The value I would like to show is yeterdays rain in mm any ideas of how I should format my item to be able to have it like that?

To use a Number you must make sure that the value is just the number and noting else. This means there can’t be any HTML headers, or white space, or units or anything else.

For example:

  • " 123.45" - error, leading white space
  • "123.45 " - error, trailing white space
  • “1234.45 mm” - error, " mm" is not part of a numer

Hi there

XML file looks like this


and log file looks like this
2016-12-19 03:18:17 - ws_regn state updated to 0,0

If I understood you right then the xml file header makes this diffcult is it possible to “wash” data with a rule or something?

Use code fences so the XML tags are preserved.

code goes here

Yes, you can use the REGEX, XPATH, or XSLT transformation to extract just the number.

See: https://github.com/openhab/openhab/wiki/Transformations

Sorry my bad I’ll make a new try for xml tag


XPATH Could be nice since I used that in my old automation software that had builtins support for handling local files. But If I read on your suggested page there’s noting about XPATH yet. If I form my item as Number and [%.1f ] with diffrent units at the end for instance celcius degrees or mm should work. But I get this in my logg

05:51:54.520 [DEBUG] [.i.s.XsltTransformationService:89 ] - transformation resulted in '0,0’
05:51:54.520 [DEBUG] [.o.b.http.internal.HttpBinding:197 ] - transformed response is '0,0’
05:51:54.520 [DEBUG] [.o.b.http.internal.HttpBinding:262 ] - Couldn’t create state of type ‘class org.openhab.core.library.items.NumberItem’ for value '0,0’
05:51:54.521 [DEBUG] [ore.internal.items.ItemUpdater:73 ] - Received update of a not accepted type (StringType) for item ws_regn

I’m not sure how deeply localization goes. You might need to replace the , with a ..

I thought that was handled but its the only thing I could think of to explain that error.

Ofcourse you were right, is there any transformation I could do with this since output in xml file from my otger software isn’t really changeable. When I replace comma with dot it all worked out nice but displays as comma in sitemap which is totally okey.

You could use XSLT which you should be able to get to replace the , as it extracts the value. Though XSLT is a bear to work with.

You could use the JS transform but you will have to do the string manipulation yourself.

Ultimately it might just be easier to use a rule.

Thanks four your advice I’m not really sure wath I getting into bute tried to experiment with numberformat in xslt file but it seem like xslt transform will be a totally own file just to convert comma to a dot thats the bad thing about beeing witihin the european system right now. Otherwise ther migt be one method to try with xslt translate. But as you say a rule will be the easiest way of doing that, but in my opinion its best to wash data as cloes to the source as possible. But how would an rule look like.

Look here for an example.