Rest Sensor Get API Call Error

Hi

I am having some difficulty getting a sensor to work.

I understand how to use a Restful sensor but my problem lies it with my GET API call.

This is the call APIKEY removed.

GET call ‘https://backend.senzodata.com/api/sensor/live/4442?apikey=mykey

I am able to call it and get the JSON details from my web browser and from postman.
But when I use it in a Rest Sensor is get the following error in HA ‘Error fetching data: <PreparedRequest [GET]>’

Is it possiably that it is https not http

I ve been googling for hours now with no success.

Could anyone help?

Thank you

And how does the configuration for the sensor look like?

Thank you for your response.

This is my current configuration

sensor:
  - platform: rest
    name: Senzo
    resource: https://backend.senzodata.com/api/sensor/live/4442?apikey=mykey
    method: GET
    value_template: '{{ value_json.inuse }}'

Thank you

Try it with quotes around the URL.

resource: "https://backend.senzodata.com/api/sensor/live/4442?apikey=mykey"

Could be that there are some chars in the API key which YAML don’t like. There could also be an issue with the certificate. We do validation per default.

So I tried the quotes now getting a new error

Unable to fetch data from https://backend.senzodata.com/api/sensor/live/4442?apikey=mykey

You say there could be an issue with the certificate could you help me look further into this?

thanks

you’re sure you need the GET?
the rest sensors in use here all look like:

  - platform: rest
    resource: !secret se_inventory_resource
    value_template: '{{ value_json.Inventory.inverters[0].cpuVersion}}'
    name: 'SolarEdge Cpu rest'
    unit_of_measurement: 'Cpu'
    scan_interval: 3600

btw, the resource in my secrets file is without quotes and has the exact same format as yours with the ?apikey=

So I 've removed the GET.

Thought I would also try moving the resource to the secrets file but I still seem to be getting an error.

Error fetching data: <PreparedRequest [GET]>

Could you please explain further on what you said “There could also be an issue with the certificate. We do validation per default” is there something I could do to check or fix this?

Have you tried using curl from a shell on the platform on which you are running HA? If it works from there, but not from the REST sensor in HA, it could be an issue of the root certificate authority. I had an issue a while ago (when I was using SmartThings) where an HTTPS URL worked on my browser, but it didn’t work on ST, because the root certificates that ST had didn’t support the root authority of the site. (Sorry if I’m using incorrect terms. Not an expert on this topic.) Bottom line, if it works with curl in a shell of the HA platform, then you could change from a REST sensor to a shell command sensor that uses curl.

Thanks for the response.
I tried using Curl and that came back with the certificate error.

debug1: permanently_set_uid: 0/0
core-ssh:~# curl -X GET ‘https://backend.senzodata.com/api/sensor/live/4442?apike=mmykey
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: curl - SSL CA Certificates

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Ok, not surprisingly it would seem curl and HA are using the same root certificates. My guess is you’re going to need to update the root certificates on your HA platform to support the certificate of this particular site. But, unfortunately, I really don’t know how to do that.

1 Like

If it’s just a certificate error that’s stopping you and you trust the source, you could add
verify_ssl: false
That will ignore the cert error. It solved my problem recently.
Correcting the certificate error is of course the best solution.

2 Likes

Hi Sampson

Your a champ! That sorted it!

Thank so much!