I have this Shell command and the template variables won’t replace. If I have quotes around the URL it converts it from this:
shell_command:
call_url: 'wget --post-data "{}" "{{states("input_text.url")}}/api/emby?fromDeviceName={{states("input_text.fromdevicename")}}&toDeviceName={{states("input_text.todevicename")}}&apikey=somekey"'
To this:
'wget --post-data "{}" {{states("input_text.url")}}/api/emby?fromDeviceName={{states("input_text.fromdevicename")}}&toDeviceName={{states("input_text.todevicename")}}&apikey=somekey'
If I remove the quotes the end result is:
wget --post-data "{}" https://mydomain.com/api/emby?fromDeviceName=Some Device Name 1&toDeviceName=Some Other Device Name&apikey=somekey
Does anyone know How I can get shell_command to expand the input_text variables when they are in quotes?
tom_l
January 17, 2023, 7:14pm
2
Try this
shell_command:
call_url: >
wget --post-data "{}" "{{states('input_text.url')}}/api/emby?fromDeviceName={{states('input_text.fromdevicename')}}&toDeviceName={{states('input_text.todevicename')}}&apikey=somekey"
Unfortunately same result. I also tried with “|” As I’ve seen that in some templates as well. Neither worked.
Not sure if this is any help… today I tried left/right between command_line and shell_command (for some curl stuff with quotes as well)
In the end, only command_line worked end-2-end
What actually is the result btw? Can you set the log level to debug
for homeassistant.components.shell_command
? Then it will log stdout and stderr for the command and you can get more insight into what is really happening.
This is the result I get
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/__init__.py:115
Integration: Shell Command (documentation, issues)
First occurred: 3:00:00 PM (1 occurrences)
Last logged: 3:00:00 PM
Error running command: `wget --post-data "{}" \"{{states("input_text.url")}}/api/emby?fromDeviceName={{states("input_text.fromdevicename")}}&toDeviceName={{states("input_text.todevicename")}}&apikey=somekey\" `, return code: 1
NoneType: None
This is after I escape the quote.
Just to close the loop the answer here was to use rest_command instead of shell_command. Wish I had known about it earlier.