Need help with Command_line with state_attr

I have this in my configuration section:

- platform: command_line
    switches:
      vswitch5:
        command_on: curl "http://192.168.0.100:80/password/sw/dim/5/{{ state_attr('light.virtual_hal_hw', 'brightness') | int * 0.4}}"
        command_off: curl "http://192.168.0.100:80/password/sw/dim/5/0"
        command_state: 'true'
        value_template: '{{ state_attr("sensor.hwstatus", "response").switches[0].dimlevel }}'
        unique_id: 12345678987654326543245678987671

When I run the line

curl "http://192.168.0.100:80/password/sw/dim/5/{{ state_attr('light.virtual_hal_hw', 'brightness') | int * 0.4}}"

in the developers toolkit for templates it gives me what I except:

"http://192.168.0.100:80/password/sw/dim/5/40.800000000000004"

But when it accutually sends the command to the host I get an error. The log says:

Logger: homeassistant.components.command_line.switch
Source: components/command_line/switch.py:133
Integration: command_line (documentation, issues)
First occurred: 20:28:31 (1 occurrences)
Last logged: 20:28:31
Command failed: curl "http://192.168.0.100:80/password/sw/dim/5/{{ state_attr('light.virtual_hal_hw', 'brightness') | int * 0.4}}"

which makes it look like

{{ state_attr('light.virtual_hal_hw', 'brightness') | int * 0.4}}

isn’t translated the way I expected. Does that mean this can’t be achieved at this moment or is there yet another way to dim the light. Or do I need more {,",’ or )? I already tried some combinations without success

The command_on and command_off options do not support templates.

Create shell commands (these do support templates) for on and off and call these commands as your switch actions in a template switch.

Thanks Tom_I. It’s working now!