RESTful Switch: ERROR No route to resource/endpoint, when endpoint is available via CURL

Hello,

I am trying to utilize the RESTful switch to read and control my garage door status based on a custom hardware I have built. I have used a Particle Photon form particle.io to build a garage door controller. HA provides me the below error on startup and never creates a ‘garage_opener’ entity.

2022-01-08 13:24:45 ERROR (MainThread) [homeassistant.components.rest.switch] No route to resource/endpoint: https://api.particle.io/v1/devices/<device-id-removed>/door?access_token=<access-token-removed>

I am able to use CURL on my PC and from the Terminal plugin in HA to access this endpoint.

My current configuration is this:

switch:
  - platform: rest
    resource: https://api.particle.io/v1/devices/<device-id-removed>/door?access_token=<access-token-removed>
    state_resource: https://api.particle.io/v1/devices/<device-id-removed>/garageOpen?access_token=<access-token-removed>
    name: garage_opener
    method: POST
    body_on: '{"args": "open"}'
    body_off: '{"args": "close"}'
    is_on_template: "{{ value_json.result }}"
    headers:
      Content-Type: application/json

I don’t fully understand why on startup HA is even accessing the ‘resource’ endpoint. Shouldn’t it be accessing the ‘state_resource’ endpoint to get the status?

Here is the output of the CURL commands showing this endpoint responding:

jason@MacBook-Air ~ % curl "https://api.particle.io/v1/devices/<device-id-removed>/garageOpen?access_token=<access-token-removed>"
{"cmd":"VarReturn","name":"garageOpen","result":0,"coreInfo":{"last_heard":"2022-01-08T22:26:20.508Z","connected":true,"last_handshake_at":"2022-01-08T16:26:59.310Z","deviceID":"<device-id-removed>","product_id":6}}%
jason@MacBook-Air ~ % curl -X POST "https://api.particle.io/v1/devices/<device-id-removed>/door?access_token=<access-token-removed>" -d "{\"args\":\"close\"}" -H "Content-Type: application/json"
{"id":"<device-id-removed>","connected":true,"return_value":0}%

This is a fresh HA install on a Raspberry Pi 3B if that helps. My searching has only led me to workarounds resolving this issue.

I currently am able to read the door status with a binary_sensor which is configured as below. The key here is that I am trying to add control functionality:

binary_sensor:
  - platform: rest
    resource: https://api.particle.io/v1/devices/<device-id-removed>/garageOpen?access_token=<access-token-removed>
    method: GET
    name: garage_door
    value_template: "{{ value_json.result }}"

Any tips tricks or suggestions would be really helpful for me! Thank you!

I don’t think it is. The error message seems to be a bit misleading:

Ah good point. It appears that the log of that try/catch returns ‘resource’ even though the get_device_state uses the state_resource.

There does not appear to be an option to enable a more detailed debug log to see what specific error my request is returning. Is my only option to use the remote python debugger?

More than likely the error that is occurring is that as you point out - on startup Home Assistant is accessing that URL, but is likely not sending any body with the request, it’s just verifying that the resource exists. The remote API however, probably is returning an error because there is no post data with the request.

To debug further I setup a Home Assistant development environment with the intention of debugging the RESTful Switch initialization to see the detailed error. That turned out to be unnecessary. Upon startup my test environment was able to access the RESTful Switch.

I added a 60 second timeout to the environment on my Raspberry Pi 3 and this resolved the issue.

It must be that on startup the Pi is taking too long to send / receive the response which causes a timeout. Then RESTful Switch never retries to connect after the first timeout.