RESTful Sensor: resource_template debug / help

I am attempting to setup a rest sensor with a resource template to Toggl to update the name of my current running project using the attributes from a previous rest call, workspace_id and project_id. When I run it with a template, I get back an error from the endpoint that there is ‘Missing or invalid workspace_id’, which seems like the url isn’t being built correctly.

Here is the relevant spot in my sensors.yaml:

  - platform: rest
    # resource: https://api.track.toggl.com/api/v9/workspaces/2024073/projects/177821418
    resource_template: https://api.track.toggl.com/api/v9/workspaces/{{state_attr('sensor.toggl','workspace_id')}}/projects/{{state_attr('sensor.toggl','project_id')}}
    name: Toggl Project Name
    username: !secret TOGGL_TOKEN
    authentication: basic
    password: api_token
    value_template: '{{ value_json["name"] }}'

The commented out resource line is what I am trying to generate, and if that is switched with the resource template, then the call is successful. However, I’ll need to generate it on the fly if the project id changes.

I’ve run the template through the dev tools, and it seems to generate the correct url format

I attempted to up the logging level to see what URL it is trying to hit, but I wasn’t able to see that info in the response. (entirely might have done this part wrong but tried a few iterations to no avail.)
configuration.yaml:

logger:
  default: info
  logs:
    homeassistant.components.sensor.rest: debug

Any next debugging steps that I’m missing, or messups that I’m not seeing? I can run that URL through postman with success, and I know authentication works because this isn’t the first api that uses it. Appreciate any and all help :slight_smile:

Relevant api docs:

With the introduction of the rest integration the functionality for the sensor you configured has changed. Try this:

logger:
  default: info
  logs:
    homeassistant.components.rest: debug
1 Like

Ah, great! That helped me get more detail into the url it’s trying to hit. I get the following line in the log:

2022-11-17 22:09:40 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://api.track.toggl.com/api/v9/workspaces/None/projects/None

So None is showing up in the attributes that I’m trying to template in. I’m wondering if the previous RESTful sensor is in the middle of updating while I try to make this request, and doesn’t have all it’s attributes yet?

Since I’m triggering this so far by reloading Rest services from the server controls screen, that may very likely be the case, that they’re both updating at the same time. I’m going to keep an eye on it to see if it updates properly on it’s own when I’m not poking it.