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.