Trying to lower the volume on a tablet

Hello all. I’m still pretty new to HA and just now starting to get serious about the setup. One of the things I’m trying to do is use a slider to control the volume on a remote tablet.

So far, I can lower the volume on the tablet by using a script. The problem with this is that it’s a static number (volume is 0-10) and so I’ll need to tie the slider on the dashboard to the volume number. Here’s the script that works:

service: notify.mobile_app_tablet_01
data:
  message: command_volume_level
  data:
    media_stream: music_stream
    command: 5

The next step I’m trying to do is use a input number. This works with the following adjustment:

service: notify.mobile_app_nora_tablet_01
data:
  message: command_volume_level
  data:
    media_stream: music_stream
    command: ‘{{ states("input_number.norapadvolumelevel") | round }}’

The problem I have is that when HA sends the command, it’s sent as ‘5’ instead of just 5. Since there are single quotes in the command, the tablet just doesn’t do anything with it.

Any ideas on how I can remove the single quotes from the command? Or perhaps I’m just going at this task in a more difficult method than it should be?

Thank you all for your time.

The state is a string, so cast it.

| int(0) | round

Thank you for advice! I actually added that piece but it still shows the command as ‘5’ with the single quotes.

These look like smart quotes of some sort. Make sure it’s straight and plain ASCII quotes.

Well after doing some tinkering I was able to get it to work. Sharing the working code for anyone that may have the same issue.

service: notify.mobile_app_tablet_01
data:
  message: command_volume_level
  data:
    media_stream: music_stream
    command: "{{ states(\"input_number.padvolumelevel\") | int | round }}"

You can avoid the escaping by using both single and double quotes. You can use the one within the other — any way around. That’s also why I said you must fix those smart quotes you had originally.