Setting up simple GET request and storing value as numeric logic object

Hi everyone. Hope someone more familiar with GET requests can help me out here, as I’m new to the syntax required to setup GET responses.

I’m trying to setup a logic GET-request in one of my flows in order to periodically collect data on currency exchange rate USD_NOK. I’ve found several websites that offer free API’s for this. As an example: https://free.currconv.com/api/v7/convert?q=USD_NOK&compact=ultra&apiKey=ab47037514ac4157626c

This url returns a simple response like the example below:

{“USD_NOK”:8.670104}

How can I setup either logic GET request or HTTPS flow cards in order to fetch the second parameter, which today is “8.670104” - as a numeric logic object, in order to use it for logic calculations in other flows?

Help much appreciated, thanks

Maybe this post can lead you in the right direction

Make a flow and at the THEN part

Insert your api request at the first sentence and a name for this trigger e.g USDNOK

Make a better logic numeric variable.
Make a flow at the WHEN part insertvthe triggername eg USDNOK

At the THEN part

At the first sentence; $.USD_NOK[0]
At the second sentence your better logic variable name e.g USDNOK

1 Like

Definitely getting closer, but I get a “object not found” error then testing the second flow.

Below are my input

I’ve made a better logic numeric variable named “usdnok” and named the trigger “USDtrigger”.

Why not " GET Json path better logic" ?

Thanks. It looks like that solved it!

Many thanks everyone :grin::+1:

1 Like

Hi everyone!

I have the same problem. I’d like to setup a GET JSONpath Better Logic.

Schermafbeelding 2022-04-06 om 20.40.18

When I enter this GET URL in my browser, I get the response below. The information I want to extract is battery level, which is “level”: 56.0 in the text. I’ve tried every combination, but get “Value not found” as Homey’s error message.

{“embedded”: null, “links”: {"_self": {“deprecation”: null, “href”: “https://api.groupe-psa.com/connectedcar/v4/user/vehicles//status”, “hreflang”: null, “name”: null, “profile”: null, “templated”: null, “title”: null, “type”: null}, “vehicle”: null}, “battery”: {“current”: 0.0, “voltage”: 97.5}, “doors_state”: null, “energy”: [{“updated_at”: “2022-04-06 18:22:45+00:00”, “autonomy”: 146.0, “battery”: null, “charging”: {“charging_mode”: “Slow”, “charging_rate”: 0, “next_delayed_time”: “PT0S”, “plugged”: true, “remaining_time”: “PT7H10M”, “status”: “InProgress”}, “consumption”: null, “level”: 56.0, “residual”: null, “type”: “Electric”}], “environment”: null, “ignition”: null, “kinetic”: {“acceleration”: null, “moving”: null, “pace”: null, “speed”: null}, “last_position”: {“type”: “Feature”, “geometry”: {“coordinates”: [null, null, null], “type”: “Point”}, “properties”: {“heading”: null, “signal_quality”: null, “type”: null, “updated_at”: null}}, “preconditionning”: {“air_conditioning”: {“failure_cause”: null, “programs”: null, “status”: “Disabled”, “updated_at”: “2022-04-06 18:22:45+00:00”}}, “privacy”: {“state”: “None”}, “safety”: null, “service”: {“type”: “Electric”, “updated_at”: “2022-04-06 18:22:45+00:00”}, “timed_odometer”: {“updated_at”: null, “mileage”: 563.5}}

Thanks for your help!

Please format the JSON using the </> button.

Thanks @robertklep for your quick reply. Could you be more specific? When I change the URL to I get “Cannot read property “indexOf” null” from Homey.

The JSON you pasted in your forum post :sweat_smile: It’s hard to read right now.

Hahaha!

http://10.0.0.2:33208/get_vehicleinfo/VR3<knip>?from_cache=1

This URL does work in my browser.

No, this:

{"embedded": null, "links": …
1 Like
{"embedded": null, "links": {"_self": {"deprecation": null, "href": "https://api.groupe-psa.com/connectedcar/v4/user/vehicles/<knip>/status", "hreflang": null, "name": null, "profile": null, "templated": null, "title": null, "type": null}, "vehicle": null}, "battery": {"current": 0.0, "voltage": 97.5}, "doors_state": null, "energy": [{"updated_at": "2022-04-06 18:22:45+00:00", "autonomy": 146.0, "battery": null, "charging": {"charging_mode": "Slow", "charging_rate": 0, "next_delayed_time": "PT0S", "plugged": true, "remaining_time": "PT7H10M", "status": "InProgress"}, "consumption": null, "level": 56.0, "residual": null, "type": "Electric"}], "environment": null, "ignition": null, "kinetic": {"acceleration": null, "moving": null, "pace": null, "speed": null}, "last_position": {"type": "Feature", "geometry": {"coordinates": [null, null, null], "type": "Point"}, "properties": {"heading": null, "signal_quality": null, "type": null, "updated_at": null}}, "preconditionning": {"air_conditioning": {"failure_cause": null, "programs": null, "status": "Disabled", "updated_at": "2022-04-06 18:22:45+00:00"}}, "privacy": {"state": "None"}, "safety": null, "service": {"type": "Electric", "updated_at": "2022-04-06 18:22:45+00:00"}, "timed_odometer": {"updated_at": null, "mileage": 563.5}}

From what I can see, the JSONPath should be $.energy[0].level

You can test here: https://jsonpath.com/

2 Likes

Awesome, that did the trick. Never would have guessed that, but now I get the format. Thanks a lot!!!

I am almost there, just missing the last bits, who can help me so I can complete the tutorial:

Usecase: I want to retrieve from weatherunderground the precipitation (neerslag) for the coming 5 days. And store the 5 day values in the below created variables in Logic.

I took these steps:

  1. Create Numeric tags in Logic

  2. Create the API call via weatherunderground:

  • Selected Geocode API, followed the instructions here:
  • Selected format JSON
  • Selected units M (metric)
  • Selected language (nl-NL)
  • Inserted secret API Key from my profile

That resulted in this API request:
https://api.weather.com/v3/wx/forecast/daily/5day?geocode=52.03,5.16&format=json&units=m&language=nl-NL&apiKey=xxxxxxx

  1. Fetch the JSON file (via browser)
    That resulted in this JSON output:
{"calendarDayTemperatureMax":[16,14,17,14,13,15],"calendarDayTemperatureMin":[4,2,3,4,5,4],"dayOfWeek":["Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag","Zondag"],"expirationTimeUtc":[1650988944,1650988944,1650988944,1650988944,1650988944,1650988944],"moonPhase":["Asgrauwe maan","Asgrauwe maan","Asgrauwe maan","Asgrauwe maan","Nieuwe maan","Nieuwe maan"],"moonPhaseCode":["WNC","WNC","WNC","WNC","N","N"],"moonPhaseDay":[25,26,27,28,29,0],"moonriseTimeLocal":["2022-04-26T05:23:16+0200","2022-04-27T05:37:40+0200","2022-04-28T05:50:18+0200","2022-04-29T06:02:22+0200","2022-04-30T06:15:06+0200","2022-05-01T06:29:45+0200"],"moonriseTimeUtc":[1650943396,1651030660,1651117818,1651204942,1651292106,1651379385],"moonsetTimeLocal":["2022-04-26T15:40:50+0200","2022-04-27T16:59:14+0200","2022-04-28T18:15:30+0200","2022-04-29T19:31:19+0200","2022-04-30T20:45:57+0200","2022-05-01T22:00:55+0200"],"moonsetTimeUtc":[1650980450,1651071554,1651162530,1651253479,1651344357,1651435255],"narrative":["Regenbuien vroeg. Minimaal 2C.","Gedeeltelijk bewolkt. Maximaal 13 tot 15C en minimaal 2 tot 4C.","Gedeeltelijk bewolkt. Maximaal 16 tot 18C en minimaal 3 tot 5C.","Bewolkt. Maximaal 13 tot 15C en minimaal 4 tot 6C.","Ochtendbuien. Maximaal 13 tot 15C en minimaal 3 tot 5C.","Gedeeltelijk bewolkt. Maximaal 14 tot 16C en minimaal 3 tot 5C."],"qpf":[0.03,0.0,0.0,0.0,0.5,0.0],"qpfSnow":[0.0,0.0,0.0,0.0,0.0,0.0],"sunriseTimeLocal":["2022-04-26T06:19:29+0200","2022-04-27T06:17:29+0200","2022-04-28T06:15:30+0200","2022-04-29T06:13:32+0200","2022-04-30T06:11:36+0200","2022-05-01T06:09:42+0200"],"sunriseTimeUtc":[1650946769,1651033049,1651119330,1651205612,1651291896,1651378182],"sunsetTimeLocal":["2022-04-26T20:55:53+0200","2022-04-27T20:57:36+0200","2022-04-28T20:59:19+0200","2022-04-29T21:01:02+0200","2022-04-30T21:02:44+0200","2022-05-01T21:04:26+0200"],"sunsetTimeUtc":[1650999353,1651085856,1651172359,1651258862,1651345364,1651431866],"temperatureMax":[null,14,17,14,14,15],"temperatureMin":[2,3,4,5,4,4],"validTimeLocal":["2022-04-26T07:00:00+0200","2022-04-27T07:00:00+0200","2022-04-28T07:00:00+0200","2022-04-29T07:00:00+0200","2022-04-30T07:00:00+0200","2022-05-01T07:00:00+0200"],"validTimeUtc":[1650949200,1651035600,1651122000,1651208400,1651294800,1651381200],"daypart":[{"cloudCover":[null,19,54,21,30,66,90,58,70,51,61,36],"dayOrNight":[null,"N","D","N","D","N","D","N","D","N","D","N"],"daypartName":[null,"Vanavond","Morgen","Morgenavond","Donderdag","Donderdagnacht","Vrijdag","Vrijdagnacht","Zaterdag","Zaterdagnacht","Zondag","Zondagnacht"],"iconCode":[null,45,30,29,30,27,26,29,39,29,30,29],"iconCodeExtend":[null,6100,3000,2900,3000,2700,2600,2900,6103,2900,3000,2900],"narrative":[null,"Regenbuien vroeg. Minimaal 2C. Wind uit het N van 10 tot 15 km/u. Kans op regen 30%.","Gedeeltelijk bewolkt. Maximaal 14C. Wind uit het N van 10 tot 15 km/u.","Gedeeltelijk bewolkt. Minimaal 3C. Wind uit het N van 10 tot 15 km/u.","Gedeeltelijk bewolkt. Warmer. Maximaal 17C. Wind uit het NO van 10 tot 15 km/u.","Overwegend bewolkt. Minimaal 4C. Wind uit het NNO van 10 tot 15 km/u.","Bewolkt. Maximaal 14C. Wind uit het NNO van 15 tot 25 km/u.","Gedeeltelijk bewolkt. Minimaal 5C. Wind uit het NNO van 15 tot 25 km/u.","Ochtendbuien. Maximaal 14C. Wind uit het NNO van 15 tot 25 km/u. Kans op regen 40%.","Gedeeltelijk bewolkt. Minimaal 4C. Wind uit het N van 15 tot 25 km/u.","Gedeeltelijk bewolkt. Maximaal 15C. Wind uit het NNO van 10 tot 15 km/u.","Gedeeltelijk bewolkt. Minimaal 4C. Wind uit het N van 10 tot 15 km/u."],"precipChance":[null,33,22,15,14,10,10,21,36,12,19,12],"precipType":[null,"rain","rain","precip","rain","precip","rain","rain","rain","precip","rain","precip"],"qpf":[null,0.03,0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.0,0.0,0.0],"qpfSnow":[null,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"qualifierCode":[null,null,null,null,"Q630",null,null,null,null,null,null,null],"qualifierPhrase":[null,null,null,null,"Warmer.",null,null,null,null,null,null,null],"relativeHumidity":[null,75,63,80,62,71,61,73,63,76,60,76],"snowRange":[null,"","","","","","","","","","",""],"temperature":[null,2,14,3,17,4,14,5,14,4,15,4],"temperatureHeatIndex":[null,13,14,13,16,15,14,12,13,12,15,14],"temperatureWindChill":[null,3,4,2,2,2,2,3,4,3,4,4],"thunderCategory":[null,null,null,null,null,null,null,null,null,null,null,null],"thunderIndex":[null,0,0,0,0,0,0,0,0,0,0,0],"uvDescription":[null,"Laag","Gemiddeld","Laag","Gemiddeld","Laag","Laag","Laag","Gemiddeld","Laag","Gemiddeld","Laag"],"uvIndex":[null,0,4,0,5,0,2,0,3,0,4,0],"windDirection":[null,349,353,10,34,30,33,18,14,6,13,0],"windDirectionCardinal":[null,"N","N","N","NO","NNO","NNO","NNO","NNO","N","NNO","N"],"windPhrase":[null,"Wind uit het N van 10 tot 15 km/u.","Wind uit het N van 10 tot 15 km/u.","Wind uit het N van 10 tot 15 km/u.","Wind uit het NO van 10 tot 15 km/u.","Wind uit het NNO van 10 tot 15 km/u.","Wind uit het NNO van 15 tot 25 km/u.","Wind uit het NNO van 15 tot 25 km/u.","Wind uit het NNO van 15 tot 25 km/u.","Wind uit het N van 15 tot 25 km/u.","Wind uit het NNO van 10 tot 15 km/u.","Wind uit het N van 10 tot 15 km/u."],"windSpeed":[null,16,11,13,14,16,19,20,18,18,16,16],"wxPhraseLong":[null,"Buien vroeg","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt","Overwegend bewolkt","Bewolkt","Gedeeltelijk bewolkt","Ochtendbuien","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt"],"wxPhraseShort":[null,"","","","","","","","","","",""]}]}

Screenshot:

  1. Copy paste Json txt in https://jsonpath.com to extract Jsonpath

Copy paste the Json file in Inputs, find the data you need, in my case qpf and play with the path, when you execute it correct you see the value you want to fetch and store

You can also use https://jsonpathfinder.com and clean up the code, you get something like this in return:

  1. Set up the flow in Homey via Get

-1. If statement: After 04 o clock the Underground API seems to be updated therefore 04:15
-Select the Logic card “Maak een webverzoek”
-Select GET request
-2. Copy Paste the url from weatherUnderground
-3. Select Headers, I filled in the example text, Content-type: json
-4. Select Body, I did something but doesn’t result in a variable

So in the last steps I need some help… @robertklep ? :slight_smile:

You can’t use Logica for this, you need the HTTP Request Flow Cards app. Logica can’t be used to extract information from web requests (you are sending the JSONPath expression to the Wunderground server now :wink: )

1 Like

Usecase: I want to retrieve from weatherunderground the precipitation (neerslag) for the coming 5 days. And store the 5 day values in the below created variables in Logic.

Pre-requisites:
1.Better Logic App
2. HTTP Request App
3. Weatherunderground Api Key (for free)

I took these steps:

  1. Create Numeric tags in Better Logic

  2. Create the API call via weatherunderground:

  • Selected Geocode API, followed the instructions here:
  • Selected format JSON
  • Selected units M (metric)
  • Selected language (nl-NL)
  • Inserted secret API Key from my profile

That resulted in this API request:
https://api.weather.com/v3/wx/forecast/daily/5day?geocode=52.03,5.16&format=json&units=m&language=nl-NL&apiKey=xxxxxxx

  1. Fetch the JSON file (via browser)
    That resulted in this JSON output:
{"calendarDayTemperatureMax":[16,14,17,14,13,15],"calendarDayTemperatureMin":[4,2,3,4,5,4],"dayOfWeek":["Dinsdag","Woensdag","Donderdag","Vrijdag","Zaterdag","Zondag"],"expirationTimeUtc":[1650988944,1650988944,1650988944,1650988944,1650988944,1650988944],"moonPhase":["Asgrauwe maan","Asgrauwe maan","Asgrauwe maan","Asgrauwe maan","Nieuwe maan","Nieuwe maan"],"moonPhaseCode":["WNC","WNC","WNC","WNC","N","N"],"moonPhaseDay":[25,26,27,28,29,0],"moonriseTimeLocal":["2022-04-26T05:23:16+0200","2022-04-27T05:37:40+0200","2022-04-28T05:50:18+0200","2022-04-29T06:02:22+0200","2022-04-30T06:15:06+0200","2022-05-01T06:29:45+0200"],"moonriseTimeUtc":[1650943396,1651030660,1651117818,1651204942,1651292106,1651379385],"moonsetTimeLocal":["2022-04-26T15:40:50+0200","2022-04-27T16:59:14+0200","2022-04-28T18:15:30+0200","2022-04-29T19:31:19+0200","2022-04-30T20:45:57+0200","2022-05-01T22:00:55+0200"],"moonsetTimeUtc":[1650980450,1651071554,1651162530,1651253479,1651344357,1651435255],"narrative":["Regenbuien vroeg. Minimaal 2C.","Gedeeltelijk bewolkt. Maximaal 13 tot 15C en minimaal 2 tot 4C.","Gedeeltelijk bewolkt. Maximaal 16 tot 18C en minimaal 3 tot 5C.","Bewolkt. Maximaal 13 tot 15C en minimaal 4 tot 6C.","Ochtendbuien. Maximaal 13 tot 15C en minimaal 3 tot 5C.","Gedeeltelijk bewolkt. Maximaal 14 tot 16C en minimaal 3 tot 5C."],"qpf":[0.03,0.0,0.0,0.0,0.5,0.0],"qpfSnow":[0.0,0.0,0.0,0.0,0.0,0.0],"sunriseTimeLocal":["2022-04-26T06:19:29+0200","2022-04-27T06:17:29+0200","2022-04-28T06:15:30+0200","2022-04-29T06:13:32+0200","2022-04-30T06:11:36+0200","2022-05-01T06:09:42+0200"],"sunriseTimeUtc":[1650946769,1651033049,1651119330,1651205612,1651291896,1651378182],"sunsetTimeLocal":["2022-04-26T20:55:53+0200","2022-04-27T20:57:36+0200","2022-04-28T20:59:19+0200","2022-04-29T21:01:02+0200","2022-04-30T21:02:44+0200","2022-05-01T21:04:26+0200"],"sunsetTimeUtc":[1650999353,1651085856,1651172359,1651258862,1651345364,1651431866],"temperatureMax":[null,14,17,14,14,15],"temperatureMin":[2,3,4,5,4,4],"validTimeLocal":["2022-04-26T07:00:00+0200","2022-04-27T07:00:00+0200","2022-04-28T07:00:00+0200","2022-04-29T07:00:00+0200","2022-04-30T07:00:00+0200","2022-05-01T07:00:00+0200"],"validTimeUtc":[1650949200,1651035600,1651122000,1651208400,1651294800,1651381200],"daypart":[{"cloudCover":[null,19,54,21,30,66,90,58,70,51,61,36],"dayOrNight":[null,"N","D","N","D","N","D","N","D","N","D","N"],"daypartName":[null,"Vanavond","Morgen","Morgenavond","Donderdag","Donderdagnacht","Vrijdag","Vrijdagnacht","Zaterdag","Zaterdagnacht","Zondag","Zondagnacht"],"iconCode":[null,45,30,29,30,27,26,29,39,29,30,29],"iconCodeExtend":[null,6100,3000,2900,3000,2700,2600,2900,6103,2900,3000,2900],"narrative":[null,"Regenbuien vroeg. Minimaal 2C. Wind uit het N van 10 tot 15 km/u. Kans op regen 30%.","Gedeeltelijk bewolkt. Maximaal 14C. Wind uit het N van 10 tot 15 km/u.","Gedeeltelijk bewolkt. Minimaal 3C. Wind uit het N van 10 tot 15 km/u.","Gedeeltelijk bewolkt. Warmer. Maximaal 17C. Wind uit het NO van 10 tot 15 km/u.","Overwegend bewolkt. Minimaal 4C. Wind uit het NNO van 10 tot 15 km/u.","Bewolkt. Maximaal 14C. Wind uit het NNO van 15 tot 25 km/u.","Gedeeltelijk bewolkt. Minimaal 5C. Wind uit het NNO van 15 tot 25 km/u.","Ochtendbuien. Maximaal 14C. Wind uit het NNO van 15 tot 25 km/u. Kans op regen 40%.","Gedeeltelijk bewolkt. Minimaal 4C. Wind uit het N van 15 tot 25 km/u.","Gedeeltelijk bewolkt. Maximaal 15C. Wind uit het NNO van 10 tot 15 km/u.","Gedeeltelijk bewolkt. Minimaal 4C. Wind uit het N van 10 tot 15 km/u."],"precipChance":[null,33,22,15,14,10,10,21,36,12,19,12],"precipType":[null,"rain","rain","precip","rain","precip","rain","rain","rain","precip","rain","precip"],"qpf":[null,0.03,0.0,0.0,0.0,0.0,0.0,0.0,0.5,0.0,0.0,0.0],"qpfSnow":[null,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"qualifierCode":[null,null,null,null,"Q630",null,null,null,null,null,null,null],"qualifierPhrase":[null,null,null,null,"Warmer.",null,null,null,null,null,null,null],"relativeHumidity":[null,75,63,80,62,71,61,73,63,76,60,76],"snowRange":[null,"","","","","","","","","","",""],"temperature":[null,2,14,3,17,4,14,5,14,4,15,4],"temperatureHeatIndex":[null,13,14,13,16,15,14,12,13,12,15,14],"temperatureWindChill":[null,3,4,2,2,2,2,3,4,3,4,4],"thunderCategory":[null,null,null,null,null,null,null,null,null,null,null,null],"thunderIndex":[null,0,0,0,0,0,0,0,0,0,0,0],"uvDescription":[null,"Laag","Gemiddeld","Laag","Gemiddeld","Laag","Laag","Laag","Gemiddeld","Laag","Gemiddeld","Laag"],"uvIndex":[null,0,4,0,5,0,2,0,3,0,4,0],"windDirection":[null,349,353,10,34,30,33,18,14,6,13,0],"windDirectionCardinal":[null,"N","N","N","NO","NNO","NNO","NNO","NNO","N","NNO","N"],"windPhrase":[null,"Wind uit het N van 10 tot 15 km/u.","Wind uit het N van 10 tot 15 km/u.","Wind uit het N van 10 tot 15 km/u.","Wind uit het NO van 10 tot 15 km/u.","Wind uit het NNO van 10 tot 15 km/u.","Wind uit het NNO van 15 tot 25 km/u.","Wind uit het NNO van 15 tot 25 km/u.","Wind uit het NNO van 15 tot 25 km/u.","Wind uit het N van 15 tot 25 km/u.","Wind uit het NNO van 10 tot 15 km/u.","Wind uit het N van 10 tot 15 km/u."],"windSpeed":[null,16,11,13,14,16,19,20,18,18,16,16],"wxPhraseLong":[null,"Buien vroeg","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt","Overwegend bewolkt","Bewolkt","Gedeeltelijk bewolkt","Ochtendbuien","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt","Gedeeltelijk bewolkt"],"wxPhraseShort":[null,"","","","","","","","","","",""]}]}

Screenshot:

  1. Copy paste Json txt in https://jsonpath.com to extract Jsonpath

Copy paste the Json file in Inputs, find the data you need, in my case qpf and play with the path, when you execute it correct you see the value you want to fetch and store

You can also use https://jsonpathfinder.com and clean up the code, you get something like this in return:

  1. Set up the flow in Homey via Get

  • If statement: After 04 o clock the Underground API seems to be updated therefore 04:15
  • Select the “Get Jasonpath Better Logic” card
  • Copy Paste the url from weatherUnderground
  • Copy Paste the Jsonpath
  • Select BetterLogic tag you want to write it to

Thanks @robertklep ? :slight_smile: for the last nudge, now it works…

3 Likes