Need help - Value template inside of a shell command

As I understand you can use value template inside of a shell command. Here is my shell command:

    shell_command:
      totalconnect_zonestatus: "curl -X GET 'https://rs.alarmnet.com/TC21API/TC2.asmx/GetPanelMetaDataAndFullStatusByDeviceID?SessionID={{states.sensor.totalconnect_sessionid.state}}&DeviceID=1706447&LastSequenceNumber=0&LastUpdatedTimestampTicks=0&PartitionID=1' > /home/homeassistant/.homeassistant/totalconnect/zonestatus.xml"

When I click call service from the UI the command is never run. But if I run this command as the homeassistant user the command works and I see the zonestatus.xml created in the correct directory. Not really sure why it works from the command line and not from the UI.
Thanks in advance.

Did you try to use single quotes?

eg.

 shell_command:
      totalconnect_zonestatus: 'curl -X GET "https://rs.alarmnet.com/TC21API/TC2.asmx/GetPanelMetaDataAndFullStatusByDeviceID?SessionID={{states.sensor.totalconnect_sessionid.state}}&DeviceID=1706447&LastSequenceNumber=0&LastUpdatedTimestampTicks=0&PartitionID=1" > /home/homeassistant/.homeassistant/totalconnect/zonestatus.xml'

I’ve done single quotes and double quotes in every way you can imagine.

How did you set up HA? Is it running as a system service?

It is a system service installed via the AIO installer

Could you paste your service definition? I had similar problems which were related to environment variables set up incorrectly.

 home-assistant.service - Home Assistant
   Loaded: loaded (/etc/systemd/system/home-assistant.service; enabled)
   Active: active (running) since Tue 2017-07-04 14:52:13 EDT; 1h 36min ago
 Main PID: 10902 (hass)
   CGroup: /system.slice/home-assistant.service
           └─10902 /srv/homeassistant/homeassistant_venv/bin/python3 /srv/hom...

Could you please post the content of this file?

/etc/systemd/system/home-assistant.service
[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=homeassistant
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target

That looks fine, sorry. It was just a straw.

I’m sure you checked permissions and such?

Could you please try this:

shell_command:
  print_curl: 'which curl > ~/curl.txt'

and let me know if it works?

/usr/bin/curl

Actually nothing happened, this was the result from running the command from the command line. I deleted the curl.txt and ran the shell command from home assistant and nothing happened. This has to be a permissions issue right?

Ok, let’s see that environment.

print_env: 'echo $PATH > ~/env.txt'

Also, try the following to see if you can write to /tmp.

print_tmp: 'curl -h > /tmp/curl.txt'

And it might make sense to raise the log level and have a look if it says something.

I have to run, but writing to the tmp directory did work yay! But the print_env had no output.

Ok, we can continue tomorrow.

I tried the following lines and it worked as expected.

shell_command:
  curl_test: 'curl -o ~/curl_test.txt -X GET "https://rs.alarmnet.com/TC21API/TC2.asmx/GetPanelMetaDataAndFullStatusByDeviceID?SessionID=1&DeviceID=1706447&LastSequenceNumber=0&LastUpdatedTimestampTicks=0&PartitionID=1"'

Can you test this on your end?

Works as expected when run from the command line, but nothing happens with run from home assistant.

Running this from the command line:

curl -o /tmp/curl.txt -X GET "https://rs.alarmnet.com/TC21API/TC2.asmx/GetPanelMetaDataAndFullStatusByDeviceID?SessionID=1&DeviceID=1706447&LastSequenceNumber=0&LastUpdatedTimestampTicks=0&PartitionID=1"

Result Warning: Failed to create the file /tmp/curl.txt: Permission denied

I changed the permissions of the output folder like so:
sudo chmod 777 /home/homeassistant/.homeassistant/totalconnect

and now this works from home assistant:
curl_test: 'curl -X GET "https://rs.alarmnet.com/TC21API/TC2.asmx/GetPanelMetaDataAndFullStatusByDeviceID?SessionID=1&DeviceID=1706447&LastSequenceNumber=0&LastUpdatedTimestampTicks=0&PartitionID=1" > /home/homeassistant/.homeassistant/totalconnect/zonestatus.xml'

but when I insert the template no file is created:
totalconnect_zonestatus: 'curl -X GET "https://rs.alarmnet.com/TC21API/TC2.asmx/GetPanelMetaDataAndFullStatusByDeviceID?SessionID={{states.sensor.totalconnect_sessionid.state}}&DeviceID=1706447&LastSequenceNumber=0&LastUpdatedTimestampTicks=0&PartitionID=1" > /home/homeassistant/.homeassistant/totalconnect/zonestatus.xml'

any ideas?