I was able to get this to work…didn’t realize there are a few other differences with HassOS.
Here is what I did:
The Python3 path is different /usr/local/bin/python3. Edit the first line of both the launch_speed_test.sh and the speedtest-cli-2ha.py to have the path /usr/local/bin/python3
Path to the speedtest files is /config/shell_commands/ so change the 2nd line in the launch_speed_test.sh file to account for this and in the speedtest-cli-2ha.py change the SPEEDTEST_PATH to /config/shell_commands/speedtest.bin
The URL to reach homeassistant can NOT be http://homeassistant.local. However http://homeassistant works fine.
Many thanks for your work and inspiration. I’ve made it a bit simpler - only the python script exists which is called directly from HA command_line sensor. It populates the state and additional attributes based on output in json format made by the script. Here is my fork of your repo:
Looking forward to any comments, especially explaining why I should not do it this way
Where do you find your HA token which they ask for in speedtest-cli-2ha.py?
I can’t find python anywhere when I use ssh in the terminal and go to the different locations. Even doing a “which python” or “python -version” returns that python doesn’t exist. Is it “hidden” as a Home Assistant install and not seen as python the app itself? OR do I need to install it?
I’m running Home Assistant on a Raspberry Pi 4.
Thanks.
Oh also, @jmart518 you said it wasn’t in usr/local/bin but then you say to use usr/bin.
So where you wrong the first time around?
To generate a long lived access token: Click on your profile in the sidebar (at the very bottom) which will then bring up your profile page. From there, scroll down to the “Long-Lived Access Tokens” and click “Create Token”. Give it a name and it will generate the token that you will need to copy/paste into the script.
As far as how it works for me (I am still on the older version, I noticed today that things may have changed a bit).
I created this shell command in configuration.yaml:
Where /usr/local/bin/python3 is the path to where python is in my HA instance (HAOS VM on ESXi) and /config/shell_commands/speedtest-cli-2ha.py is the path to the speedtest script.
I then call that shell command using an automation that runs every 30 min:
I have also tried replacing python3 in the command above with /usr/local/bin/python3, python3.8 and python3.9 with the same results.
If I run ./speedtest-cli-2ha.py from the command line with debugging switched on I get:
[core-ssh shell_commands]$ ./speedtest-cli-2ha.py
./speedtest-cli-2ha.py: line 4: import: command not found
./speedtest-cli-2ha.py: line 5: import: command not found
./speedtest-cli-2ha.py: line 6: import: command not found
./speedtest-cli-2ha.py: line 7: import: command not found
./speedtest-cli-2ha.py: line 8: import: command not found
./speedtest-cli-2ha.py: line 11: SPEEDTEST_SERVERID: command not found
./speedtest-cli-2ha.py: line 12: SPEEDTEST_PATH: command not found
./speedtest-cli-2ha.py: line 15: DEBUG: command not found
./speedtest-cli-2ha.py: line 16: CONSOLE: command not found
./speedtest-cli-2ha.py: line 18: syntax error near unexpected token `('
./speedtest-cli-2ha.py: line 18: `_LOGGER = logging.getLogger(__name__)'
I had to play around with this for quite some time until I got it running. The command line you have (python3) works for me. What I had to change was set the path to the speedtest binary in the py file: SPEEDTEST_PATH = '/config/shell_commands/speedtest.bin'
You should also remove the serverid that’s entered in the script or replace it by a suitable one.
I’m running this in a VirtualBox image, so the hass.io I can reach via ssh doesn’t have python accessible from the commandline, but it works from the sensor without problems.
What I also had to look up as a HA newbie was that the commandline sensor had to go unter a section sensor: in configuration.yaml, and the template sensor under a section template:.
Thanks very much for the suggestion, I have change the SPEEDTEST_PATH to match your suggestion and I’ve double checked the server ID but it is still not working. I have got the config yaml layout right as I already have other command line and template sensors that work.
I’ve figured out the problem - the server ID that I had chosen from this list doesn’t seem to work, if I leave the server ID blank and let it get chosen automatically then it’s working fine
I’m newbie in HA and installed speedtest add-on via UI. It works.
I want to change the default server which is not displayed in the list list and the 1h-cycle of test.
where can I change the server_ID ? where can I find it on HA UI ? I don’t see this in module configurtation. I presume this in in a specific file, but where can I find it ?
I read also:
By default, a speed test will be run every hour. You can disable polling using system options and use the update_entity service to automate the speed test frequency.
which is weird for me: where can I find the step-by-step to configure this and become more HA user
To turn off Polling
UI->Settings->Devices & Services
Find the Speed Test Integration
click on the 3-dots
click on System Options
You should see Enable polling for updates
Changing the Server-id not in the UI pull down list,
I’m not sure you can.
You could take a chance and change it n the the /config/.store/core.config_entries but be aware that these files are really not suppose to be changed, so I don’t recommend it.
Instead, I suggest going through this thread above and also this thread, where the speedtest-cli is used, and there you should be able to specify the server-id yourself. The speedtest-cli is essentially a binary executable that is run outside of HA and returns bandwidth/delay results. There are different ways that the speedtest-cli can be used with HA, and you’ll see in these threads a few ways to do it.