Command with multiplication not working

Hi, why this shell command isn’t working:

denon_level_center: echo -e "PSCLV {{ '%03d'|format(((states('input_number.denon_level_center')*10)+500)|int) }}\n"

I have a slider from -12 to 12 dB, with step 0.5, the expected value I need to send is “PSCLV 500\n” - the value 500 can vary from 380 to 620 (that’s why I need to multiply by 10 and then add 500.

Thanks!

States are strings. You need to convert them to numbers before doing mathematical operations:

denon_level_center: echo -e "PSCLV {{ '%03d'|format(((states('input_number.denon_level_center')|float*10)+500)|int) }}\n"
1 Like

Do you know why this automation is working, but Shell command not working?
Automation:

This code is for automation, I added a push to see if value is OK and it’s perfect:

- id: '1625292860475'
  alias: Denon Level Bass
  description: ''
  trigger:
  - platform: state
    entity_id: input_number.denon_level_bass
  condition: []
  action:
  - service: shell_command.denon_level_bass
  - service: notify.mobile_app_galaxy_note_10
    data:
      title: Denon
      message: Bass PSSWL {{ '%03d'|format(((states('input_number.denon_level_bass')|float*10)+500)|int) }}
  mode: single

This code is for shell_command.denon_level_center (other commands there working fine)

denon_level_center: echo -e "PSCLV {{ '%03d'|format(((states('input_number.denon_level_center')|float*10)+500)|int) }}\n"

This code is for input_number.denon_level_center

denon_level_center:
  name: Level Center
  min: -12
  max: 12
  step: 0.5
  unit_of_measurement: 'dB'

All I can see in logs (debug enabled) is this:

2021-07-03 09:04:59 INFO (MainThread) [homeassistant.components.automation.denon_level_center] Denon Level Center: Executing step call service
2021-07-03 09:04:59 DEBUG (MainThread) [homeassistant.components.shell_command] Stdout of command: echo -e "PSCLV {{ '%03d'|format(((states('input_number.denon_level_center')|float*10)+500)|int) }}\n", return code: 0:
b’PSCLV 465\n\n’
2021-07-03 09:04:59 INFO (MainThread) [homeassistant.components.automation.denon_level_center] Denon Level Center: Executing step call service
2021-07-03 09:04:59 INFO (MainThread) [homeassistant.components.mobile_app.notify] mobile_app push notification rate limits for Galaxy Note 10+: 3 sent, 500 allowed, 0 errors, resets in 8:55:00
2021-07-03 09:05:20 INFO (MainThread) [homeassistant.components.websocket_api.http.connection] [547792080320] Connection closed by client

No idea but this template needs to be in quotes:

message: "Bass PSSWL {{ '%03d'|format(((states('input_number.denon_level_bass')|float*10)+500)|int) }}"