Getting Ubi Sensor Data the Hard Way... Or how I stopped worrying and learned to love the XMLslurper


(Patrick Stuart [@pstuart]) #1

https://github.com/pstuart/smartthings/blob/master/Get%20Ubi%20Sensors

Yeah, this ain’t pretty, but it is a proof of concept on how to get a web page data and parse it.

Someone might want to refine this a bit, but I wanted to get it out there, and see if we can force the Ubi guys to make a much more official way to get this data.

Anyway, its ugly, its not going to work for everyone, could break at any time… But it is proof that you can grab almost any data off a website and use it for a devicetype…

Enjoy…


Website Parsing via HTTPGET?
(Edward Pope) #2

Excellent, I thought about parsing the info from their site as well. I was hoping that they would expose the information and allow us to pull it in without doing this. Like you have stated, let’s hope that this gets them moving in that direction.


(Patrick Stuart [@pstuart]) #3

Also why I didn’t refine this. This is a HACK of the roughest sort. BUT, it works. For me at least.

This also opens up potentials for stupid IoT devices that don’t have a proper api but at least display the data on a page.

The only thing I have to say, is it shouldn’t have been this hard. Probably isn’t but this is how I finally got it working…

Why regex.matcher isn’t allowed is beyond me…

Now off to hack my sleepnumber bed with sleepIQ so smartthings knows when I’m asleep and when I wake up…


(swanny) #4

@pstuart There is a regex syntax that is allowed and may clean up what you were wanting to do.

http://groovy.codehaus.org/Regular+Expressions

def info = (commandData.params =~ /vendor=(.*)&model=(.*)/)
if ((info[0][1] != null) && (info[0][2] != null)) {
    log.trace "vendor = " + info[0][1]
    log.trace "model = " + info[0][2]
}

(Chrisb) #5

@pstuart,

Nice work! Thanks for doing this.


(Chrisb) #6

Am I correct in assuming this is a Device Type? After adding it as a device type and publishing it, how do I add it to my things?


(Patrick Stuart [@pstuart]) #7

@chrisb
Not sure what you mean. Yes it is a devicetype, it creates a device that has the sensors from the Ubi.

Temp, humidity, luminance, Air Pressure and Sound Level.

These can then be accessed and updated on Poll()

This device will create tiles to display the data from the Ubi.

Your things are already on ST…


(Chrisb) #9

I must be missing something here. I added this as a device type in the IDE. No issues there. Now how do I access this device? Does just adding the devicetype automatically create a device in SmartThings?


(tduffy) #10

This is beautiful. Thanks @pstuart!


(Patrick Stuart [@pstuart]) #11

No you then need to create a device and select this devicetype either in the ide devices or in the app.


(Coolcatiger) #12

Will this refresh regularly or only on demand update when I refresh app tile ?


(Patrick Stuart [@pstuart]) #13

It will not update regularly, devices have no built in access to schedules. Smartapps can do this. There is a Polling app

That can be used to get this data updated on a regular basis.


(Nicholas Wilde) #14

This is sweet. Nice hack job!


(Patrick Stuart [@pstuart]) #15

Some minor updates to allow sensor data to be logged via my Xively logger.

https://github.com/pstuart/smartthings/blob/master/Get%20Ubi%20Sensors


(Darc Ranger) #16

How do I use this if I have more than one UBI device?


(Patrick Stuart [@pstuart]) #17

You don’t. Official API calls now support getting all sensor data in json.

Just waiting on Ubi to allow everyone the ability to access the api


(Jody) #18

What do you use for the device_id @pstuart, I am getting java.lang.NullPointerException: Cannot invoke method writeTo() on null object @ line 137


(Patrick Stuart [@pstuart]) #19

DeviceID isn’t used, so you can set it to anything unique.

Code’s working for me, is it possible your username and password are wrong? Also, how many ubi’s do you have? If you have more than one, it might be the issue.


(Jody) #20

Must have had a typo in there somewhere. I double checked all the settings and it is working. Do you have API access for the UBI yet? I have requested it, but have not heard anything back from them.


(Patrick Stuart [@pstuart]) #21

Yes, I have it, waiting to release code until others will have it. PM me an email address, and I can set you up with the API code and see if it will work using my API access.