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

@chuckles,

I’ve got only one Ubi and I’m trying to use your device type. I’m not getting any data from the portal through to the Mobile App. Might I need to change child numbers?

@chrisb - that would be my best guess, the same as for @xneo1. If one of you get it working could you please post back here so others with only one Ubi can also know the appropriate value.

Hmm… I think I’m having a bigger issue… I’m not 100% sure I’m getting any data from the portal. :frowning:

I’ve got the Device Type pulled up in the IDE and I’ve added my Ubi as a device. When I “install” it in the simulator I don’t see anything showing up in the logs. I haven’t done much at all with Device Types, so I might be completely off base, but I would expect this line:

log.debug “Request was successful, $response2.status”

To put something in the log after I hit the “poll” button in the tools section, but I’m not seeing anything. If I put something in the Speech Synth area that DOES work,

Apparently IDE logging wasn’t working earlier - it’s meant to be working again now though.

http://status.smartthings.com/

Woot!! Got it working. Thanks for the info and assist @chuckles

@xneo1, I was getting the same error you were and here’s what I did to fix it:

Leave the doc line alone. That should remain:

doc[0].children[1].children[7].children[1].writeTo(x)

Find the first v.temp line that reads like this:

v.temp = linesAsList[(ubiOffset + 4)].minus("document.write(").minus(".toFixed(2));")

This line needs to change. First, change the offset modifier to 6:

v.temp = linesAsList[(ubiOffset + 6)].minus("document.write(").minus(".toFixed(2));")

Next, you may need to change what is “subtracted” from the text. For me, being in the US, I was getting modifiers adding toFarhenheit. So I further changed this line to look like this:

v.temp = linesAsList[(ubiOffset + 6)].minus("document.write(").minus("toFahrenheit(").minus("));") //temp in C

This of course gave me the temp in C, so I had to convert this to F. (On a side note… why can’t the US get it’s head out of the sand and just switch already to the metric scale?!?) Obviously if you’re a meteric country don’t do this step. But my next v.temp line now looks like this:

v.temp = Math.round((Double.parseDouble(v.temp) * 1.8 + 32)) // Temp in F

Finally, I needed to clean up the temp tile at the top. Again, if you’re a “civilized” country when it comes to units of measure, skip this step. For the rest of us: Near the top (around line 50), find this section:

state("temperature", label: '${currentValue}°', unit:"C", backgroundColors: [
                    [value: 0, color: "#153591"],
                    [value: 7, color: "#1e9cbb"],
                    [value: 15, color: "#90d2a7"],
                    [value: 25, color: "#44b621"],
                    [value: 30, color: "#f1d801"],
                    [value: 35, color: "#d04e00"],
                    [value: 40, color: "#bc2323"]

First, replace the unit from C to F. Then, change the values to:
31, 44, 59, 74, 84, 95, 99 (or where ever you’d like to see color changes based on what temp it is).

Save and publish, and that should do it.

Thank you for your time but I changed everything and I cant get the sensor values.
It keeps saying in the logs:
java.lang.NullPointerException: Cannot get property ‘children’ on null object @ line 152 with children[6]
I used 5 and 1 and both throw errors on the v.temp.If I comment out these 2 lines it goes to humidity sensors lines and so on.

Can anyone post the initial code but updated with SpeechSynthesis and so on, “JUST for 1 UBI” users?

@xneo1, did you try 7? That first line should be as chuckles original posted it:

doc[0].children[1].children[7].children[1].writeTo(x)

If that still doesn’t work, the original device type should be higher up in this thread.

I put 7 and nothing.
I used again the original code from github and nothing!

Hmm… well, crap.

Okay… so, you started over with the original Github code from Chuckles, then made the changes I posted above, right? (Just want to make sure I understand correctly.)

Are running the device in the simulator and getting the error there?

Follow up question: If you are running this in the simulator, are you using a virtual device or your actual Ubi added to ST?

I used both Ubi and virtual device but nothing.
One more question:
Since I have only one Ubi I will white number “1” in the app right?or nothing?
On line 158 says:

int ubiOffset = (ubinumber.toInteger() - 1) * 15;

so probably sth is happening with the “Ubi number”

I’ve entered ‘1’ for my Ubi number.

I don’t think I ever got the error though that you did. When do you see this error? When you first try to save the Device Type? Or when you “install” the device in the simulator and then poll?

I only have one Ubi myself, but my guess is that multiple Ubi’s are listed 15 Lines? Columns? apart from each other on the page. So if we’re talking the first Ubi, that’s off set by zero (1-1 = 0 * 15 = 0) while each next Ubi is pushed down 15 lines.

Another thing to check… the line right above the “doc[0].children[1].children[7].children[1].writeTo(x)” is a line that commented out. Remove the the // in front so this logs the text in the simulator that the app is pulling from the Ubi site. This is what my log looks like:


The DenTemperature

document.write(toFahrenheit(16.7));

°F
Humidity41.8%
Air Pressure99.3KPa
Sound level45.4dB
Light level60.0lux
Last updated var t = 1415827778021; document.write(moment(t).format(“MM/DD HH:mm”));Retry SetupMy SmartThingsHello, Smart HomeAdd Apps or Devices


If you’re seeing something like this, then we know we’re at least getting to the Ubi portal okay and logging in okay and grabbing data okay. If you don’t see any of this, then it might be a connectivity issue.

Yeah, sorry guys this device type was never meant to be a long term solution, since I was hoping the api would be open by now.

Since my UBI is dead and needs to be RMA’d, I’m unable to fix (plus short on time)…

My code for the smartapp discovery of ubis and devicetype for ubi via api are in my github and just bug ubi for api access.

I have completed an ubi connect smart app and device type that uses the actual API. I will do a bit more testing and submit it for approval via ST. If you already have an ubi API Key, me know and you can test the code.

2 Likes

If anybody is still using this device type, here are the new values to work with Ubi’s updated portal page…

Line 152:

    doc[0].children[1].children[4].children[1].writeTo(x)

Note that this is based upon having more than one Ubi. If you only have one Ubi you may need to change the value “4” to something else (I don’t know what, sorry).