Graph your Z-Wave mesh (Python, auto-update)

That fixed it - Thanks!

I’m struggling to get this working correctly in a venv deployment. I have setup the various yaml files and everything is working except the automation calling the shell_command which looks like this in my log:

Error running command: `/usr/local/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py`, return code: 1
11:07 AM /srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/shell_command.py (ERROR)

Running the script from my venv works as expected, it reads the log and updates the JSON and the ipanel is updated and everything functions correctly.

administrator@hass:~$ sudo su -s /bin/bash homeassistant
homeassistant@hass:/home/administrator$ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hass:/home/administrator$ cat /home/homeassistant/.homeassistant/shell_commands/z-wave-graph.yaml
z_wave_graph: python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py
(homeassistant) homeassistant@hass:/home/administrator$ python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py
(homeassistant) homeassistant@hass:/home/administrator$

Your single quotes look wrong to me they should be ’ not `, unless it’s the error formatting :stuck_out_tongue:

I’m not sure I follow. The only quotes I’m seeing are from the copy/paste output of the log which came from the home assistant web interface log function. The z-wave-graph.yaml has no quotes in the file.

What’s the output of which python3 from within your venv?

(homeassistant) homeassistant@hass:~$ which python3
/srv/homeassistant/bin/python3
(homeassistant) homeassistant@hass:~$ ls -la /srv/homeassistant/bin/python3
lrwxrwxrwx 1 homeassistant homeassistant 22 Nov  7 17:48 /srv/homeassistant/bin/python3 -> /usr/local/bin/python3
(homeassistant) homeassistant@hass:~$ ls -la /home/homeassistant/.homeassistant/bin/z-wave-graph.py
-rwxrwxr-x 1 homeassistant homeassistant 9945 Feb 11 10:49 /home/homeassistant/.homeassistant/bin/z-wave-graph.py
(homeassistant) homeassistant@hass:~$ date
Tue Feb 13 19:42:51 EST 2018
(homeassistant) homeassistant@hass:~$ /srv/homeassistant/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py
(homeassistant) homeassistant@hass:~$ ls -la /home/homeassistant/.homeassistant/www/z-wave*
-rw-rw-r-- 1 homeassistant homeassistant  3155 Feb 11 10:50 /home/homeassistant/.homeassistant/www/z-wave-graph.html
-rw-rw-r-- 1 homeassistant homeassistant 14185 Feb 13 19:42 /home/homeassistant/.homeassistant/www/z-wave-graph.json
(homeassistant) homeassistant@hass:~$

I thought this was going to be easy, but nope. :slight_smile:

I wonder if you change the action in the shell_command to use the /srv/homeassistant/bin/python3 path if it would work? Maybe the venv isn’t getting activated by the /usr/local/bin/python3 path?

Same result :frowning:

(homeassistant) homeassistant@hass:~/.homeassistant/shell_commands$ cat z-wave-graph.yaml
z_wave_graph: /srv/homeassistant/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py
(homeassistant) homeassistant@hass:~/.homeassistant/shell_commands$ date
Tue Feb 13 19:52:18 EST 2018
(homeassistant) homeassistant@hass:~/.homeassistant/shell_commands$ tail -n 8 /home/homeassistant/.homeassistant/home-assistant.log
2018-02-13 19:40:00 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/usr/local/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py`, return code: 1
NoneType: None
2018-02-13 19:45:00 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/usr/local/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py`, return code: 1
NoneType: None
2018-02-13 19:48:47 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/usr/local/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py`, return code: 1
NoneType: None
2018-02-13 19:50:00 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/usr/local/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py`, return code: 1
NoneType: None
(homeassistant) homeassistant@hass:~/.homeassistant/shell_commands$

This isn’t really high priority to me, just weird. Don’t feel any obligation to spin too many cycles on it.

The shell_command seems to be about 90% of the issues. Just too many configurations out there I guess. Realistically though, it’s probably completely unnecessary. I’m pretty sure the Z-Wave network only changes when additional nodes are added. Maybe re-graphing after a network heal would be a good thing, but the whole every 5 minutes is overkill.

Agreed, that’s pretty much where I’ve landed on this. The graph is nice for occasional troubleshooting, and I can just kick it off manually should I feel compelled to do so. Thanks for all your work on this!

@luma You came up with the answer and didn’t realize it.

You need to use the output of which python3 when run from within your venv.

So the shell command would be;

shell_command:
  z_wave_graph: /srv/homeassistant/bin/python3 /home/homeassistant/.homeassistant/python_scripts/z_wave_graph.py

WORKS GREAT!!!

@luma If “z_wave_graph.py” resides in “/home/homeassistant/.homeassistant/bin/” your Shell Command would be:

 shell_command:
  z_wave_graph: /srv/homeassistant/bin/python3 /home/homeassistant/.homeassistant/bin/z_wave_graph.py

I’m not sure I understand. It looks like the 2nd example you posted lines up exactly with the current contents of my z-wave-graph.yaml:

(homeassistant) homeassistant@hass:~$ cat ~/.homeassistant/shell_commands/z-wave-graph.yaml
z_wave_graph: /srv/homeassistant/bin/python3 /home/homeassistant/.homeassistant/bin/z-wave-graph.py

Am I missing some detail?

Are you saying, this is not working for you?

Correct. It works when pasted on the command line while su’d as homeassistant and with the venv activated. It returns rc 1 when run from home assistant.

That’s weird, the missing piece for me was “/srv/homeassistant/bin/python3”

Did you create the “bin” directory?
If so, you may need to check the permissions.

Did you make the script executable?
chmod 755 ~/bin/z-wave-graph.py

This post here covers what you’re asking and provides a bit of context.

administrator@hass:/home/homeassistant/.homeassistant$ sudo su -s /bin/bash homeassistant
homeassistant@hass:~/.homeassistant$ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hass:~/.homeassistant$ ls -la /home/homeassistant/.homeassistant/ | grep bin
drwxrwxr-x  2 homeassistant homeassistant       4096 Feb 12 12:46 bin
(homeassistant) homeassistant@hass:~/.homeassistant$ ls -la /home/homeassistant/.homeassistant/bin
total 24
drwxrwxr-x  2 homeassistant homeassistant 4096 Feb 12 12:46 .
drwxr-xr-x 12 homeassistant homeassistant 4096 Feb 13 21:44 ..
-rwxrwxr-x  1 homeassistant homeassistant  543 Feb 13 09:13 bandwidth.php
-rwxrwxr-x  1 homeassistant homeassistant 9945 Feb 11 10:49 z-wave-graph.py
(homeassistant) homeassistant@hass:~/.homeassistant$

FYI: I was experiencing the same issue as you, until I added the python path.
“return code: 1 NoneType: None”

Here’s a question - does the user account you’re using for homeassistant have a default shell assigned? Mine doesn’t as a security measure. I wonder if there are issues running shell commands as a user with no shell?

1 Like

Not sure, how would I check, I’m not too savvy when it comes to shell and scripts.

The default shell for a user is stored in the /etc/passwd file (which doesn’t actually contain passwords and is world readable by default).

grep "homeassistant" /etc/passwd
homeassistant:x:999:999::/home/homeassistant:

The default shell is the last field, where fields are separated by :. In this case, the last field is empty, meaning this user has been explicitly denied a login shell. This is the general approach used when running applications under a service account to prevent people from logging in with that account.