Calling an external service and receiving the Response in a variable?

Hi Erik,

I am trying to follow your receipt in order to get the hourly forecast from this site:
https://api.met.no/weatherapi/locationforecast/2.0?lat=58.945370&lon=5.573560

I would like to store all the parameters (i.e air_temperature, wind_speed, ) for the next 12 hours in variables for use in other flows. However, I am struggling to get it to work (I am not very experienced with programming unfortunately). Do you have any ideas how I can make it work?
How would you store the data in variables for instance? Would you make one air_temperature variable in better logic for each hour, or is it possible to store all 12 hours in an array?
Also, when I try to run I get a flow card error in the second step saying value not found. Can you see what I am doing wrong?

Any help would be greatly appreciated :slight_smile:

All the best,
Eirik

Hi @thudelicious

If you like to have the current hour temperature, the JSONpath expression for that is

$.properties.timeseries[0].data.instant.details.air_temperature

The next hour is

$.properties.timeseries[1].data.instant.details.air_temperature

and so on…

There isn’t any array possibility in better logic or Homey variables, so you have to use separate variables. I think in Homey script there are possibility for arrays if you want to dive into that.

In http://jsonpath.com/ you can evaluate the JSONpath syntax by copying your source to the page etc.

I see! Thank you so much.
The link was also very useful to check out the syntax :slight_smile:
I still get an error message when trying to test the flow however, but I am guessing that the card needs some sort of input which should be given from the other card. So when I try to test it I have to give it the input ({“a”:1,“b”:“some text”})? What should I put in here in order to test the card?

Think I will have to look into Homey Script eventually, but as I just got my homey I think I will start with trying to get a better understanding of the flows first :slight_smile:

Thanks again!

1 Like

It seems to be running fine when I checked the variables, so I guess the best way is to verify the JSONpath first.

1 Like

Hello @Erik,

I would like to add a condition to my sprinkler that if the predicted amount of rain from the national weather service is greater than 0, the sprinkler will not start.

I have the url for the query to the weather service for the next 5 days:

http://daten.buergernetz.bz.it/services/weather/district/6/bulletin?format=json&lang=de

This is the result, where I need the value marked in yellow:

I created 2 flows, the first calls the weatherdata, the second should write the betterlogic variable:

I also created a betterlogic variable:

If i try to test the second flow i always get this error:

Thanks a lot

Tip: test your expression with jsonpath.com
With $.forecasts[0].rainTo it should take the rainTo value of the first forecast in the dataset.

i’m getting this error?

image

thanks

This is not an Error, this is a Test command.

1 Like

Hello @erik,

thanks ist works.
could you help me to extract the variable in yellow?

Thanks a lot

Hello,

how can i visualize the extracted variabale to controll if the variable is right?

is there any other way instead of using betterlogic, there are now the logics of homey, i always use them and want to continue using them?

@Erik : do you think to realize this in your app für http requests?

thanks

hello,

for what can i use this? what is trigger for T80?

thanks

That would be $.forecasts[0].symbol.description
(agian, its easy to check you jsonpath expression on jsonpath.com)

1 Like

I tried to implement native homey variables, but the App toolkit didn’t allowed it (at least it wasn’t a year ago)

maybe you could retry? :slight_smile:

Unfortunantly nothing has changed, so its still not possible to retreive and set native variables from an app.
(https://github.com/athombv/homey-apps-sdk-issues/issues/27)

1 Like

hello @Erik,

if i use the JSONpath for trigger ist possbile to eliminate the betterlogic an wrtite in the standard logics from homey? What ist the trigger for T80?

thanks a lot and fpr your patience :slight_smile:

@Erik or with this variable?

Could this be a solution? I don’t know how to realise that:

Thanks

Looks like the existing condition card C22

Extract and check a specific value from a JSON or XML formatted GET response. This card expects a JSONpath expression.

could you help me to test this, i’m not able to isner the correct expressions?

What is the exact condition you want to evaluate?