Command line sensor command character limit?

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.

Why not write a bash script to send the curl command and call the bash command in the commandline sensor?

Short answer is, I don’t know how to do that for Hassio.

Oh dear, another hassio limitation.

All thanks to @pergola.fabio for the following solution.

Add double quotes around your web address. They will need to be double as you already have singles around your command.
You may need to escape the double quotes ie:

command: 'curl \"http://&lt;INVERTER IP&gt;/solar_api/v1/GetArchiveData.cgi?Scope=System&amp;SeriesType=DailySum&amp;StartDate=&lt;TODAYDATE&gt;&amp;EndDate=&lt;TODAYDATE&gt;&amp;Channel=EnergyReal_WAC_Plus_Absolute&amp;Channel=EnergyReal_WAC_Minus_Absolute\"'

Merry Xmas :christmas_tree:

That worked! Thank you! Merry Christmas! This was driving me nuts and I gave up and parked it.

Here’s the final working code for anyone interested:

- 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=") ~ (now().strftime("%d.%m.%Y")) ~ ("&EndDate=") ~ (now().strftime("%d.%m.%Y")) ~ ("&Channel=EnergyReal_WAC_Plus_Absolute&Channel=EnergyReal_WAC_Minus_Absolute") }}\"'
  value_template: '{{ value_json["Body"]["Data"]["meter:17313109"]["Data"] }}'

And then secondary templates to extract the data for this one since it’s nested:

- platform: template
  sensors:
    solar_exported_today:
      value_template: '{{ ( states.sensor.fronius_meter_archive.attributes.Body["Data"]["meter:17313109"]["Data"]["EnergyReal_WAC_Minus_Absolute"]["Values"]["0"] | float /1000 ) | round(1) }}'
      friendly_name: "Solar Exported Today"
      unit_of_measurement: "kWh"

  platform: template
  sensors:
    grid_imported_today:
      value_template: '{{ ( states.sensor.fronius_meter_archive.attributes.Body["Data"]["meter:17313109"]["Data"]["EnergyReal_WAC_Plus_Absolute"]["Values"]["0"] | float /1000 ) | round(1) }}'
      friendly_name: "Grid Imported Today"
      unit_of_measurement: "kWh"

platform: template
sensors:
  energy_used_today:
    value_template: '{{ ((states.sensor.solar_gen_today.state |float)-(states.sensor.solar_exported_today.state |float) + (states.sensor.grid_imported_today.state |float)) |float | round(1) }}'
    friendly_name: "Energy Used Today"
    unit_of_measurement: "kWh"