I think the command line sensor is truncating my GET request URL. Has anyone else encountered this?
I’m trying to grab archived data from my Fronius smart meter. It uses a GET request and requires the date to be in a specific format in the url. I can’t use a RESTful sensor because it doesn’t accept templating in the resource
parameter, so I’ve now learned to use the command_line
sensor with a curl call. This is what I want it to do:
- platform: command_line
name: Fronius Meter Archive
json_attributes:
- Body
command: 'curl http://<INVERTER IP>/solar_api/v1/GetArchiveData.cgi?Scope=System&SeriesType=DailySum&StartDate=<TODAYDATE>&EndDate=<TODAYDATE>&Channel=EnergyReal_WAC_Plus_Absolute&Channel=EnergyReal_WAC_Minus_Absolute'
value_template: '{{ value_json["Body"]["Data"]["meter:17313109"]["Data"] }}'
If I put in the date directly in (e.g. 17.11.2018), I get a proper result. But, I want that to change every day to get the latest information, which is why I’m using command line. When I try to use a template to change the date every day, it’s only sending part of the URL. I know this because I can test the URL and I know that it’s only sending up to http://<INVERTER IP>/solar_api/v1/GetArchiveData.cgi? Scope=System&SeriesT
, because the returned result isn’t including the SeriesType request. It’s only when I try to use templates.
I tried using now().strftime("%d.%m.%Y")
to get the date and inserting as a template in the command call. I’ve tried:
command: 'curl http://<INVERTER IP>/solar_api/v1/GetArchiveData.cgi?Scope=System&SeriesType=DailySum&StartDate={{now().strftime("%d.%m.%Y")}}&EndDate={{now().strftime("%d.%m.%Y")}}&Channel=EnergyReal_WAC_Plus_Absolute&Channel=EnergyReal_WAC_Minus_Absolute'`
And creating a template sensor to refer to…
- platform: template
sensors:
today:
value_template: '{{ ("http://<INVERTER IP>/solar_api/v1/GetArchiveData.cgi?Scope=System&SeriesType=DailySum&StartDate=") ~ (now().strftime("%d.%m.%Y")) ~ ("&EndDate=") ~ (now().strftime("%d.%m.%Y")) ~ ("&Channel=EnergyReal_WAC_Plus_Absolute&Channel=EnergyReal_WAC_Minus_Absolute") }}'
friendly_name: "Today"
And then in my command_line sensor…
command: curl {{ states('sensor.today') }}
This doesn’t work either. If I try to use any templates in the command call, it’s cutting off the request and it fails. Ideas, workarounds…? I’ve also tried using secrets and just about every other method. I feel like this might be a bug.