Using a template with command_line fails

Hi,

I have the following sensor:

 - platform: command_line
    name: Router_FW_Current
    command: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'cat /etc/motd'"

The sensor works fine and I can see the output of the command in the Overview screen.

However, when I add a template to extract the FW version, like in the following excerpt:

  - platform: command_line
    name: Router_FW_Current
    command: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no [email protected] 'cat /etc/motd'"
    value_template: "{{ states('sensor.Router_FW_Current')|regex_findall_index(find=' [0-9._]+')|trim }}"

it fails with the following message: https://pastebin.com/zst95bER

The template works, I tested it myself in the Developer Tools tab under Templates.

Any idea what could be wrong ?

BTW, the following template fails in Developer Tools:

{{ states('sensor.Router_FW_Current')|regex_findall_index(find=' [0-9._]+', index=0, ignorecase=False) }}

with Unknown error.

It seems that there are some problems with the command_line template.
I created another sensor (platform template) and everything works fine now.

you don’t need states(...) in your template, you have to put value there. Something like this:

value_template: "{{ value | regex_findall_index(find=' [0-9._]+') | trim }}"