What am I doing wrong, cannot use sensor for API requests

Guys,

So this works…

- platform: rest
  
  resource: https://api.open-meteo.com/v1/forecast?latitude=38&longitude=-77&current_weather=true&timezone=auto
  method: GET
  scan_interval: 1260
  name: "openmeteo_current_weather GNSS test 1"
  value_template: '{{ value_json["current_weather"].temperature }}'

BUT this does not:

- platform: rest
  
  resource: https://api.open-meteo.com/v1/forecast?latitude={{ states('sensor.esp_32_ver_1_gps_latitude') }}&longitude={{ states('sensor.esp_32_ver_1_gps_longitude') }}&current_weather=true&timezone=auto
  method: GET
  scan_interval: 1260
  name: "openmeteo_current_weather GNSS test 1"
  value_template: '{{ value_json["current_weather"].temperature }}'

So here’s the thing, I copy and paste the resource API request to the template editor and a legitimate and coordinate populated URL comes up. I copy and paste that generated URL and I get values.

BUT when I check the STATES under developer tools, a centigrade temperature goes to UNKNOWN when I use the sensor input to generate the URL for the API request, even when the template tool gives me a correct URL and the copy and paste method works.

How can open meteo tell the difference in the URL API request from an actual number coordinate to a coordinate that has been generated by a sensor, and the template return correct coordinates and copy and paste generates JSON.

I don’t understand.

The plan is to have weather updates generated by GPS sensor input.

Thanks to all.

Always check the integration documentation.

To use templates in your resource you need to use the second option:
https://www.home-assistant.io/integrations/sensor.rest#sensor-rest-configuration-variables

Replace

resource: https://api.open-etc...

with

resource_template: https://api.open-etc...
1 Like

OMG, that fixed it so fast! Thank you very much!

That resource_template is the magic word!

Thank you again!

1 Like