We have moved at community.getvera.com

Author Topic: Help with Item/Binding of FreeBox into openHAB  (Read 2105 times)

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Help with Item/Binding of FreeBox into openHAB
« on: December 22, 2014, 05:53:55 pm »
For one of my Vera plugins (Freebox), I am setting a variable with a XML data.

I need in openHAB to set an item taking one information from this XML data. So I need to write a IN transformation file.
Any advice / example how to do that ?
If I do it using JavaScript, do you think I could re-use a big part of my JavaScript code from the Vera plugin UI that loads this XML using window.DOMParser ?
XSLT could be more appropriate in this case ?

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Help with Item/Binding of FreeBox into openHAB
« Reply #1 on: December 22, 2014, 07:46:51 pm »
For one of my Vera plugins (Freebox), I am setting a variable with a XML data.

I need in openHAB to set an item taking one information from this XML data. So I need to write a IN transformation file.
Any advice / example how to do that ?
If I do it using JavaScript, do you think I could re-use a big part of my JavaScript code from the Vera plugin UI that loads this XML using window.DOMParser ?
XSLT could be more appropriate in this case ?

Your transform will either be of the form:
    ...,in:XPATH(/rootNode/next/next2/stuffToExtract),...     OR;
    ...,in:XSLT(yourFile.xsl),...       OR;
    ...,in:JS(yourFile.js),...

...depending upon the complexity of the data-extraction.  I would guess that running XPath is going to be the easiest for most simple cases, with XSLT and JS just being a preference (and potentially performance, but I've never measured their cost)

These are all built into openHAB, but there's not a lot of documentation to go on.  There is this page, but it's minimalist.  The XSLT Transformation has some examples.


NOTE: The fileName forms (XSLT and JS) should work without too much headache, but it's possible that my Binding parse code could break on more complex XPath expressions.... If you try this path, and it breaks, let me know and I'll tighten up that parsing logic.

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Help with Item/Binding of FreeBox into openHAB
« Reply #2 on: December 23, 2014, 05:08:57 am »
Your transform will either be of the form:
    ...,in:XPATH(/rootNode/next/next2/stuffToExtract),...     OR;
    ...,in:XSLT(yourFile.xsl),...       OR;
    ...,in:JS(yourFile.js),...

...depending upon the complexity of the data-extraction.  I would guess that running XPath is going to be the easiest for most simple cases, with XSLT and JS just being a preference (and potentially performance, but I've never measured their cost)

Ok, I tried with XPath after adjusting a little my Vera plugin.

Here is my item definition in openHAB:
Code: [Select]
String FreeboxTeleviseur "T?l?viseur [%s]" (GVera) {mios="unit:house,device:437/service/urn:freebox-fr:serviceId:Freebox1/PeripheriquesReseau, in:XPATH(/net_devices/device[@mac=\"XX:XX:XX:XX:XX:XX\"])"}

At openHAB, I get this error:
Code: [Select]
2014-12-23 11:06:06.585 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type 'mios' of item ?FreeboxTeleviseur? could not be parsed correctly.
org.openhab.model.item.binding.BindingConfigParseException: Config for item 'FreeboxTeleviseur' could not be parsed.  Bad general format 'unit:house,device:437/service/urn:freebox-fr:serviceId:Freebox1/PeripheriquesReseau, in:XPATH(/net_devices/device[@mac="00:1B:D3:D2:65:02"])'

Any idea ? Is my declaration wrong ?

Edit: I tried with that item definition too but no better result:
Code: [Select]
String FreeboxTeleviseur "T?l?viseur [%s]" (GVera) {mios="unit:house,device:437/service/urn:freebox-fr:serviceId:Freebox1/PeripheriquesReseau, in:XPATH(/net_devices/device[@mac='XX:XX:XX:XX:XX:XX'])"}

Edit2: fixed by suppressing the space in the mios string 8)
« Last Edit: December 23, 2014, 07:24:45 am by lolodomo »

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Help with Item/Binding of FreeBox into openHAB
« Reply #3 on: December 23, 2014, 07:04:18 am »
I have done another test using transformation (no XPath in this case) and I got a similar issue. I probably missed something that is obvious for you.

Here is my item definition:

Code: [Select]
Switch FreeboxWifi "Wifi [MAP(fr.map):%s]" (GVera) {mios="unit:house,device:437/service/urn:freebox-fr:serviceId:Freebox1/WifiActif,in:MAP(miosBooleanIn.map),command:MAP(miosFreeboxWifiCommand.map)"}
Edit: fixed by reversing in and command in the string.
Code: [Select]
Switch FreeboxWifi "Wifi [MAP(fr.map):%s]" (GVera) {mios="unit:house,device:437/service/urn:freebox-fr:serviceId:Freebox1/WifiActif,command:MAP(miosFreeboxWifiCommand.map),in:MAP(miosBooleanIn.map)"}

Here is the error at startup:
Code: [Select]
2014-12-23 13:00:11.853 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type 'mios' of item ?FreeboxWifi? could not be parsed correctly.
org.openhab.model.item.binding.BindingConfigParseException: Config for item 'FreeboxWifi' could not be parsed.  Bad general format 'unit:house,device:437/service/urn:freebox-fr:serviceId:Freebox1/WifiActif,in:MAP(miosBooleanIn.map),command:MAP(miosFreeboxWifiCommand.map)'
« Last Edit: December 23, 2014, 08:11:28 am by lolodomo »

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Help with Item/Binding of FreeBox into openHAB
« Reply #4 on: December 23, 2014, 01:02:51 pm »
... yes, my Parsing code is a little touchy...  ;)