Hi all, newbie here trying to figure out how to integrate an outside API into HA. This will be for Toggl, which I use for time tracking and it would be amazing if HA could make decisions based on it, since it gives very accurate readings of what I’m doing.
I want to fetch this data with REST sensors, but I unfortunately need to make 2, one after the other. I’ve already got the first one sorted:
#toggl
#get current time entry
- platform: rest
resource: https://www.toggl.com/api/v8/time_entries/current
name: Toggl
json_attributes:
- data
username: !secret TOGGL_TOKEN
authentication: basic
password: api_token
value_template: '{{ value_json["data"]["description"]}}'
- platform: template
sensors:
toggl_description:
friendly_name: 'Description'
value_template: '{{ states.sensor.Toggl.attributes.data.description }}'
toggl_project_id:
friendly_name: 'Project ID'
value_template: '{{ states.sensor.Toggl.attributes.data.pid }}'
toggl_duration:
friendly_name: 'Duration'
value_template: '{{ (states.sensor.Toggl.attributes.data.duration + (states.sensor.seconds_since_epoch.state|float))|timestamp_custom("%-H:%M", false) }}'
That returns me lots of good info, the most relevant of which is the project_id. I need this to make my second REST request, to get the project name. But for that, the URL needs to take the form of https://www.toggl.com/api/v8/projects/[PROJECT_ID]
.
I can’t figure out how to generate this URL on the fly. My failing attempt is below, although I’m now fairly sure that’s a dead end attempt.
- platform: rest
resource: https://www.toggl.com/api/v8/projects/{{sensor.toggl_project_id}}
name: Toggl Project
json_attributes:
- data
username: !secret TOGGL_TOKEN
authentication: basic
password: api_token
value_template: '{{ value_json["data"]["name"]}}'
Any advice/tricks on how to accomplish this easily without too much convolution? I’ve researched and can’t find a good way to make an appended string like this on the fly.
Any help is greatly appreciated.