I can easily read out the kWh reading out of the rest resource for the year 2019.
But for next year it should change automatically to 2020.
I tried out {{ now().year }} instead of the 2019 in the resource URL. But it didn’t work.
Is there a way to put together an automated URL?
This is my code for now:
platform: rest
resource: https://smart-me.com:443/api/MeterValues/XXXXXXX?date=2019-1-1T12%3A00%3A01Z
username: XXXXXXXXXXX
password: XXXXXXXXXXX
authentication: basic
name: Einspeisung Buholzer Anfang Jahr
value_template: ‘{{ value_json.CounterReadingExport }}’
unit_of_measurement: “kWh”
headers:
Content-Type: application/json
User-Agent: Home Assistant REST sensor
You can try using a Command Line Sensor with a curl command instead. The Command Line Sensor supports templating in the command configuration variable.
sensor:
- platform: command_line
name: Get Date
command: curl -s http://date.jsontest.com
value_template: "{{ value_json.date }}"
If you need to specify username/password, control headers, etc., then you should read up on how to use curl. It’s a very flexible command with lots of options. It might seem a bit overwhelming at first, but it’s a learning curve worth climbing.
One way I’ve used it is to put most of the “static” options in a text file, and then use curl’s -K option to point to it. E.g., the file might contain entries like the following in your scenario:
I’m not exactly sure what you’re asking here. Do you mean you want to have an element in the frontend where the user can select a date, and then use that in the curl command in the command_line sensor? And by date do you mean YYYY-MM-DD, or just YYYY? Or do you mean something else?