Command Line Sensor Error (Show Current Version)

I get errors when I use a command line sensor to show the current version of my Hass.

17-02-09 05:06:42 ERROR (Thread-7) [homeassistant.components.sensor.command_line] Command failed: python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"

My setup is:

  - platform: command_line
    name: "HASS Release"
    command: python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"

I copied that from the page of the command sensor, they use this example…


Anyway it does not work…

I use these two sensors to track the current and installed versions:

-  platform: command_line
   command: python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"
   name: Current HA Version

-  platform: command_line
   name: Installed version
   command: "/srv/hass/hass_venv/bin/hass --version"

And they work for me.

How did you install HA? Do you have python3 installed - if you type which python3, what do you get?

I’ve got the same command, and it works for me. I used the AIO installer on my Pi.

- platform: command_line
  command: python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"

When I installed HA a while ago, I installed it also by using the AIO

Remember that you may have one version when running as Pi or Root and another while running as the HA user in the virtual environment.

In venv as hass, I am running Python 3.4.2 but as the Pi user in a regular session I am running Python 2.x.

I installed via a pre-December 2016 version of the AIO installer.

I also installed a pre december 2016 version…

Try copying my two sensors and running with them and see if they show up without an error.

Seems this is working:

-  platform: command_line
   name: Installed version
   command: "/srv/hass/hass_venv/bin/hass --version"

The other with command the following command gives errors

python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"

It’s odd because I can do this from the command line as Pi and I get a proper version response whether I use python3 or python.

What do you get when you run:

python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"

from the command line?

I got the right value in putty and in Hass frontend, but still got errors in the log file…

I’m kinda stumped at this point. If you’re getting the right version number, then there’s no problems with getting to the URL, so that can be ruled out.

The only other thing I can think of is logging in as the HA user, activating the virtual environment and running the same command to see if you get a different result.

When logging in as hass user and the evironment, I also got the right value, without errors… So the command seems okay, but I dont understand as well, why I got some errors in my log…

Is it the same error in your first post?

When I directly run the command, I dont get errors, but in the logfiles, it showed that error… very strange…
However, the only thing I can do is, without errors, using the command: /srv/hass/hass_venv/bin/hass --version
I replaced already my sensor with that command…

Sorry I can’t come up with anything else, but maybe the troubleshooting we did will lead someone else to an answer.

1 Like

Anyway, it’s good that we have a workaround for this :slight_smile:

1 Like

I’m glad I could help in some way.

Good day, this command no longer works in Hassbian 1.3

Any suggestions?
Thank you

Found the solution need to sudo pip3 install requests

1 Like