Author Topic: Tools: openHAB Item file generator  (Read 25918 times)

Offline Kmitchel

  • Full Member
  • ***
  • Posts: 168
  • Karma: +1/-2
Re: Tools: openHAB Item file generator
« Reply #75 on: April 28, 2017, 11:10:10 am »
I've never opened the script file in Windows, but I tried your command below just to be safe

tr -d '\015' miosLoad.sh nmiosLoad.sh

I get the error - tr: extra operand ?miosLoad.sh?

Offline jswim788

  • Hero Member
  • *****
  • Posts: 801
  • Karma: +58/-2
Re: Tools: openHAB Item file generator
« Reply #76 on: April 28, 2017, 11:41:36 am »
tr -d '\015' miosLoad.sh nmiosLoad.sh
You are missing the < and >.  The < says get it from this input file, and the > says put the output into the named file.
Code: [Select]
tr -d '\015' < miosLoad.sh > nmiosLoad.shThere are many, many ways to do this.  Search Google for 'dos2unix' or CR/LF to LF.  Your RPI3 may have dos2unix loaded or you can install it.  Most text editors will also do this for you.  Here's one sample: https://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/

Offline Kmitchel

  • Full Member
  • ***
  • Posts: 168
  • Karma: +1/-2
Re: Tools: openHAB Item file generator
« Reply #77 on: April 29, 2017, 08:59:02 am »
Getting closer, thanks SO much for helping me!  I ran the tr command on both Load and Transform files.  The Load ran successfully and created a user_data.xml file in my scripts directory.

I'm now getting this error when I try to run the command below:

./miosTransform.sh house

INFO: Transforming MiOS Unit Metadata from user_data.xml...
./miosTransform.sh: line 15: xsltproc: command not found
ERROR: Failed to Transform, Check for bogus XML in user_data.xml.



Offline jswim788

  • Hero Member
  • *****
  • Posts: 801
  • Karma: +58/-2
Re: Tools: openHAB Item file generator
« Reply #78 on: April 29, 2017, 11:40:52 am »
Code: [Select]
sudo apt-get update
sudo apt-get install xsltproc

Offline Kmitchel

  • Full Member
  • ***
  • Posts: 168
  • Karma: +1/-2
Re: Tools: openHAB Item file generator
« Reply #79 on: April 29, 2017, 04:56:01 pm »
Thank you, thank you, thank you!!!  That worked perfect!!

Offline Srki

  • Newbie
  • *
  • Posts: 13
  • Karma: +1/-0
Re: Tools: openHAB Item file generator
« Reply #80 on: March 14, 2018, 06:02:55 am »
Hi,
Hope someone can help me out with some basic instructions on how to bind my VERA to openHAB. My openHAB is running from a Windows 10 operating system. I am able to connect to openHAB and install the binding for MIOS but that is it. I edited the mios.cfg file with correct ip number to my VERA but I am stuck with the procedure where I need to use the MiOS Item Generator. First I needed to get bash in order to run the .sh files in Windows CMD. First error is in the miosLoad.sh where the port number is incorrect. I edited the file with port number 3480 but still I receive the error that the ip is incorrect. So I skipped this step and downloaded the .xml file by command http://MIOS_IP:3480/data_request?id=user_data&output_format=xml  but I am unable to use this XML through an XSLT Processor. Is there any step-by-step instruction for using the Mios Item Generator in Windows? Before I go any further, is this even possible to create using windows platform or do I need to use Linux?
/BR

Offline liko

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Tools: openHAB Item file generator
« Reply #81 on: May 01, 2018, 09:14:43 am »
It's easiest to just use Linux.  Most (if not all) of the tools that are required are easily available on Linux and it's a bit more challenging to get these for Windows.

Offline Buxton

  • Full Member
  • ***
  • Posts: 146
  • Karma: +9/-0
Re: Tools: openHAB Item file generator
« Reply #82 on: November 28, 2018, 11:08:27 pm »
I've been able to generate an .items file for each of my two veras, but would also like to do the same for my openLuup instance as I have all of my plugins running there and would like to access some sensor data.  Has anyone managed to do this.  I get a JSON return from openLuup, that I can then transform to user_data.xml, however, the miosTransform.sh chokes on this user_data file with errors occurring after a few hundred lines in the xml file.

I also use habridge and it successfully connects to openLuup, so I don't believe my installation is the issue. 

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6206
  • Karma: +276/-70
  • "Less is more"
Re: Tools: openHAB Item file generator
« Reply #83 on: November 29, 2018, 03:03:00 am »
I have no idea how this works, but happy to try and resolve anything on the openLuup side. 

Presumably, your JSON comes from the user_data request?  There is certainly no fundamental issue there, but I could imagine that whatever the shell script is trying to do may not, perhaps, like the fact that data from any bridges Veras will also be included there (with high device numbers, too.)
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline Buxton

  • Full Member
  • ***
  • Posts: 146
  • Karma: +9/-0
Re: Tools: openHAB Item file generator
« Reply #84 on: November 29, 2018, 06:14:19 pm »
Hey Ak,

Yes, it's a user_data request:
Code: [Select]
curl --max-time 15 \
     --output ${MIOS_OUT} \
     --silent "http://${MIOS_IP}:3480/data_request?id=user_data&output_format=xml"

One thing you could help with, if you're up to it, is to acknowledge the output_format tag and produce xml from the call. The xml should of course stay true to the structure that you would normally receive from a vera.  This would definitely reduce errors in the transcription process.  Thx for taking a look.

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5300
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Tools: openHAB Item file generator
« Reply #85 on: December 01, 2018, 05:17:09 pm »
Native Vera/MiOS can be asked to provide it's Meta-data it's internal form (JSON) or in XML.   In the case of the openHAB generator, it uses the XML form of the Meta-data, so it can be transformed using any XSLT processor.   It asks for the XML format, since that's required for the XSLT processing step.

NB: In some cases, the MiOS "XML" is buggy, and not escaped correctly, forcing manual editing to get the XML processor to handle it.

PS: The scripts from the tool are simple wrappers of the same commands from a (Linux|Mac) Command line.  If you're on another platform I've found online tools (like http://xsltransform.net/) can be handy.   Just be aware that some of these tools submit to a cloud-hosted service, so any Passwords (etc) in the MiOS config file will also be pushed up.

PPS: here's a direct URL for the XSLT Transform view-source:https://raw.githubusercontent.com/openhab/openhab1-addons/master/bundles/binding/org.openhab.binding.mios/examples/scripts/miosTransform.xslt

Offline jswim788

  • Hero Member
  • *****
  • Posts: 801
  • Karma: +58/-2
Re: Tools: openHAB Item file generator
« Reply #86 on: December 03, 2018, 01:18:51 pm »
If you only need to push data for a few items into openLuup you can use a rule with the sendHttpGetRequest to a virtual sensor.  It works well for me.  I'm toying with a rule that parses out all members of a named group and does this automatically, but my time may be better spent just porting my openLuup logic to the openHAB rules.

See https://www.openhab.org/docs/configuration/actions.html#http-actions

Offline Buxton

  • Full Member
  • ***
  • Posts: 146
  • Karma: +9/-0
Re: Tools: openHAB Item file generator
« Reply #87 on: December 04, 2018, 08:35:58 pm »
Yeah, I'm basically trying to get my alarm sensor data into openHab so that I can use their Alexa broadcast plugin to announce my sensor states in a given situation.  I'd take a crack at this as a Vera plugin, but as of right now, the Amazon API does not support Lua so I imagine you're left with writing a "skill" in python/c++ that can then be accessed by a plugin through a "skill" API.  Much like what Vera currently does with their Alexa binding.  My skills are not there yet for something like that.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 801
  • Karma: +58/-2
Re: Tools: openHAB Item file generator
« Reply #88 on: December 04, 2018, 10:53:29 pm »
So you want to push from Vera/openLuup into openHAB?  For that I use this function in my startup Lua.  Then set up a device watch or scene to call it as needed.  Just give the name and value you want and it will get pushed to openHAB.  Be sure to change the IP and port as needed.

Code: [Select]
function setOpenHabItem(item, value)
  local http = require("socket.http")
  local ltn12 = require("ltn12")
  local path = "http://127.0.0.1:8090/rest/items/" .. item
  local payload = "0" -- default

  payload = value

  luup.log("setOpenHabItem payload is " .. payload)

  local response_body = { }
    local res, code, response_headers, status = http.request
    {
      url = path,
      method = "POST",
      headers =
      {
        ["Content-Type"] = "text/plain",
        ["Content-Length"] = payload:len()
      },
      source = ltn12.source.string(payload),
      sink = ltn12.sink.table(response_body)
    }
end
This could use some error checking...

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5300
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Tools: openHAB Item file generator
« Reply #89 on: December 05, 2018, 06:33:27 pm »
Yeah, I'm basically trying to get my alarm sensor data into openHab so that I can use their Alexa broadcast plugin to announce my sensor states in a given situation.  I'd take a crack at this as a Vera plugin, but as of right now, the Amazon API does not support Lua so I imagine you're left with writing a "skill" in python/c++ that can then be accessed by a plugin through a "skill" API.  Much like what Vera currently does with their Alexa binding.  My skills are not there yet for something like that.

If it'll help, I can generate out a new OpenHAB "Items" file from my Alarm system.   Mine is still running under Vera, and uses the standardized Vera UPnP Interfaces, so it should work for your Panel also.

You'd need to tweak the DeviceId's, and the Labels, but it'll give you a starting block for an OpenHAB configuration.   The runtime only uses the JSON interface, not the XML stuff, so that part should be fine against anything that has a MIOS JSON interface.


When I first build the Bridge, this is how I made the configs anyhow (lots of Copy-n-Paste) - the Item Generator is just a convenience to avoid that step.

Anyhow, let me know...