Shell Commands Not Working in Venv?

I am trying to get a series of shell commands to work for my pi user inside my virtual environment. Basically, I am trying to launch mkchromecast and then start pianobar. If I run each one of commands inside the virtual environment by themselves, they work and music plays through the required casting group. But when I try and run them through HASS and the Scripts, no music plays. Is there any clear reason as to why the commands aren’t working?

clear_existing_cast: 'sudo rm -f /tmp/'
launch_cast: 'sudo -H -u pi mkchromecast -n {%- if is_state("input_select.media_player", "home_group") -%} "Home Group" {%- elif is_state("input_select.media_player", "living_room") -%} "Living Room" {%- elif is_state("input_select.media_player", "upstairs") -%} "Upstairs" {%- endif -%}'
set_default_output: 'sudo -H -u pi pacmd set-default-sink mkchromecast'
launch_pianobar: 'sudo -H -u pi pianobar'

stop_pianobar: 'sudo -H -u pi /home/pi/.config/pianobar/ quit'
pandora_variable_on: sudo -H -u pi sed -i "s/\${u}/{{ states('variable.username') }}/;s/\${p}/{{ states('variable.password') }}/;s/\${n}/{{ states('variable.autostart') }}/;"  /home/pi/.config/pianobar/config
pandora_variable_off: sudo -H -u pi sed -i "s/{{ states('variable.username') }}/\${u}/;s/{{ states('variable.password') }}/\${p}/;s/{{ states('variable.autostart')}}/\${n}/;"  /home/pi/.config/pianobar/config

alias: “Pandora On”
- service: shell_command.pandora_variable_on
- service: shell_command.clear_existing_cast
- service: shell_command.launch_cast
- service: shell_command.set_default_output
- service: shell_command.launch_pianobar

alias: “Pandora Off”
- service: shell_command.pandora_variable_off
- service: shell_command.stop_pianobar
- service: homeassistant.turn_off
entity_id: media_player.home_group

When you tested them, did you test them as the homeassistant user?

Yes, I ran them inside the venv as the homeassistant user. The only error I get is a return code 1 for the launch_pianobar shell command, which gives me an return code 1. However, my Home Group appears to be casting MKChromecast, although I never heard the Chromecast Audio connection “chime”

edit: in my template for launch_pianobar, how do I get it to render a space between -n and the template result. For example, it is rendering this for Home Group sudo -H -u pi mkchromecast -n"Home Group", when there should be a space between the -n and Home Group

edit #2: So the problem resides with the launching of mkchromecast. Again the above command works when I launch within the venv, but when I try with shell command or even a command line switch, it fails. I removed all templating and hardcode “Home Group”. Is the double quotes giving it trouble? Should it be single?

edit #3: Solved the launching of mkchromecast by using root user instead of pi