RestFul: How to send time in GET request

Hi

I have a URL that requires a start and end time (in epoch format) to be sent as part of the URL. I am having trouble working out how to send these, and any help appreciated.

For example, the full url should be something like:

http://192.168.1.110/api/start=1628824140&end=1629035460

his is a part of my configuration, but instead of sending the time, it sends the actual text:

   - platform: rest
     method: GET
     scan_interval: 15
     resource: http://192.168.1.110/api/
     params:
       start: '{{ now() -900 }}'
       end: "{{ now() }}"

Can anyone help on how to actually send the time value as a parameter in the GET request?

Thanks!

Use

as_timestamp(now())

Thanks.

I did work out that as_timestamp(now)) displays epoch.

The problem is that the rest platform does not like the template format and instead sends the actual text and not the converted time.

For example, on the server side, I see this in apache2 logs: (not exactly the same request as above as I’ve been mucking around with the format, but I think you get the point)

GET /api/?start=%7B%7B%20(as_timestamp(now())%20%7C%20int)%20%7D%7D

Ah, right.
params do not take templates :roll_eyes:

You’ll have to use resource_template rather than resource

resource_template: 'http://192.168.1.110/api?start={{ as_timestamp(now()) - 900 }}&end={{ as_timestamp(now()) }}'
1 Like

Perfect. Thanks!