[SOLVED] Google Geocode Problems

Dear Community!

I have been using a rule from here, but it stopped working…

I get this error:

Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null

Here is the whole rule, if that matters:

val String GoogleAPIKey = "My API key"

rule LocationString
    Item KristofIPhone_Location changed or
    Item EdinaIPhone_Location changed or
    Item ReKaIPhone_Location changed
    val PointType location = (triggeringItem.state) as PointType
    val nameParts = triggeringItem.name.toString.split("_")
    val triggeringiPhoneName = nameParts.get(0) + "_LocationString"
    val Latitude = location.latitude
    val Longitude = location.longitude
    val geocodeURL = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + Latitude + "," + Longitude + "&sensor=true&key=" + GoogleAPIKey
    val String gecodeResponse = sendHttpGetRequest(geocodeURL)
    val String formattedAddress = transform("JSONPATH", "$.results[0].formatted_address", gecodeResponse)
    postUpdate(triggeringiPhoneName, formattedAddress)

I think that the rule is ok, because it used to work. Now I only get ‘null’ for return value.
What I have tried so far:

  • Restarting openHab
  • Reinstalling the JSONPATH transformation

What I’m missing?


Log your payload before transforming…

logInfo("something", gecodeResponse)

Oh thanks!
It seems that it also null before transforming…

2018-03-30 15:41:19.874 [INFO ] [thome.model.script.Location Response] - null

So that’s what’s causing the error. Try logging the URL, then use that URL on a browser so you can further debug…

Make it a habit to use the logging mechanism. It just makes debugging so much easier.

Thanks, I’ll try that!

It seems that the generated URL works, it returns the current location, and the “formatted_address” is there. It seems that the sendHttpGetRequest where it becomes ‘null’

Now it worked for just 1 device for 1-2 minutes… it seems like it couldn’t connect to the internet sometimes…

[.smarthome.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.TimeoutException

You may have hit the daily limit of API calls

Dont think so, because if I open the link in my browser it returns the location…

Ps.: seems to be the timeout was the problem. I have added extra timeout (5000 ms), now it works