Running "speedtest" as command_line causes errors

I am using HA in Docker on Raspberry Pi 3.
Since last few months I have been using “speedtest-cli” instead of “speedtestdotnet” integration.

The reasons of this are:

  1. I need more information which can be provided by “speedtest-cli”: IP address & ISP name.
  2. There is a DualWAN setup in my router, so I have 2 providers. I wanted to monitor speed for both providers; for this I made routing rules in the router like “host #1 uses primary interface” (i.e. ISP #1), “host #2 uses secondary interface” (i.e. ISP #2). Monitoring can be achieved by running speedtest on both hosts.

“host #1” is a Raspberry Pi 3 with HA.
“host #2” is another Raspberry Pi 3 (basically used for Kodi).

“speedtest-cli” is taken from here - GitHub - sivel/speedtest-cli: Command line interface for testing internet bandwidth using speedtest.net.

For local monitoring (i.e. on “host #1”) I am using this sensor:

sensor:
  - platform: command_line
    name: "Speedtest (local)"
    command: "/config/utils/speedtest-cli"
    value_template: "{{ ..... }}"
    command_timeout: 120
    scan_interval: 999999

For remote monitoring (i.e on “host #2”) I am using this sensor:

  - platform: command_line
    name: "Speedtest (remote)"
    command: !secret ssh_speedtest_remote_command
    value_template: "{{ ..... }}"
    command_timeout: 120
    scan_interval: 999999

The sensors are updated every 1 hour (in different time like “at 00:30” for local, “at 00:40” for remote) by automations.
Then sensors’ values are parsed in another sensors to get “DL speed”, “UL speed”, “Ping”, “ISP name”, “IP address”.

Now the important part.
First for the local sensor the command line was this: command: "/config/utils/speedtest-cli"
In the HA folder I made a subfolder with that “speedtest-cli” program and added this subfolder in the “configuration.yaml” file:

  allowlist_external_dirs:
    - /config
    - /config/utils
    - /config/lovelace

And this setup worked so far.

Some time ago because of unknown reasons the local sensor stopped working - the sensor was not updated, there was errors in the log:

Logger: homeassistant.components.command_line
Source: components/command_line/__init__.py:41
Integration: command_line (documentation, issues)
First occurred: 6:46:50 PM (1 occurrences)
Last logged: 6:46:50 PM

Command failed: /config/utils/speedtest-cli

I thought that these errors were caused by a lack of RAM - recently I started experimenting with VSCode in Docker which made my setup (Raspberry Pi 3, 1GB) very unstable (freezes sometimes).
Then I found another Speedtest CLI program - this is an official OOKLA CLI program (Speedtest CLI - Internet connection measurement for developers).
Tried to install and test it - this program seems to work faster and gives higher results))).

Now about the problem:
I decided to use that OOKLA speedtest program instead of the “speedtest-cli”.
What I did is:

  1. Changed the sensor: command: "/config/utils/speedtest"
  2. Placed the “speedtest” file into the “utils” folder.
  3. Changed a code for parsing the output.

But the result is negative - still I see that errors in the log.
What causes these errors?

The most strange thing:
In terminal, the “speedtest” program is started properly - but only if selected explicitly:

sudo ./HA/utils/speedtest

   Speedtest by Ookla

     Server: XXXXXXXX - Moscow (id = 14190)
        ISP: XXXXXXXX
    Latency:     1.60 ms   (0.09 ms jitter)
   Download:    93.64 Mbps [====|               ] 23%
   .....

If the path is not specified, then strangely the “speedtest-cli” is started:

speedtest
Retrieving speedtest.net configuration...
Testing from XXXX (XXX.XXX.XXX.XXX)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by XXXXX (Moscow) [14.94 km]: 5.069 ms
Testing download speed............

I cannot understand why the “speedtest-cli” is started instead of the new “speedtest” program.

That’s expected unless ./HA/utils is in your $PATH. Is it?
And before /usr/bin?

No, did not do it.
I thought that this is required only if I call programs w/o specifying a path.
In HA config the “speedtest” & “speedtest-cli” programs were specified with a path.

Checked “usr/bin” - there is no “speedtest” or “speedtest-cli” programs.
These programs were not installed, were just downloaded - so I called them using a path.
That is why very strange that “speedtest-cli” program is called when I call “speedtest” program w/o specifying a path.

Just do which speedtest to know the full path of speedtest in your $PATH

Thank you, I am a noob in Debian/Ubuntu (but used to be a programmer in QNX many years ago).
The output is:

which speedtest
/usr/local/bin/speedtest

Content of this folder:

ls -la
total 20
drwxr-xr-x  2 root root 4096 May 20 03:10 .
drwxr-xr-x 10 root root 4096 Feb  1 14:02 ..
-rwxr-xr-x  1 root root    9 May 19 23:36 docker-compose
-rwxr-xr-x  1 root root  404 May 20 03:10 speedtest
-rwxr-xr-x  1 root root  412 May 20 03:10 speedtest-cli

Regarding these “speedtest” & “speedtest-cli” files - I cannot understand how these files came here))).
It is a very nob thought but I am sure that I just downloaded these files into “HA/utils” folder))).

OK, should I delete the “speedtest” file from this folder - to ensure that OOKLA speedtest is started?

Also, why these programs are not started by HA?


Update:
First, I deleted that “/usr/local/bin/speedtest” file.
Then I tried to start programs “inside HA container”:

docker exec HA speedtest
Retrieving speedtest.net configuration...
Testing from XXXXXX (XXX.XXX.XXX.XXX)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by XXXXXXXXX (Moscow) [14.94 km]: 5.685 ms
Testing download speed..........................

Again - the “speedtest-cli” is started instead of OOKLA “speedtest”.
Now let’s specify the OOKLA program explicitly:

docker exec HA ./utils/speedtest
==============================================================================

You may only use this Speedtest software and information generated
from it for personal, non-commercial use, through a command line
interface on a personal computer. Your use of this software is subject
to the End User License Agreement, Terms of Use and Privacy Policy at
these URLs:

        https://www.speedtest.net/about/eula
        https://www.speedtest.net/about/terms
        https://www.speedtest.net/about/privacy

==============================================================================

To accept the message please run speedtest interactively or use the following:

    speedtest --accept-license

Seems this could be a reason why this OOKLA “speedtest” was not started by HA - it was started but probably without measuring: if you try to start the program first time from the Terminal, the program will ask you smth about license and you should type “y” (“yes”).
How to solve it - first start the program with “–accept-license” option:

docker exec HA ./utils/speedtest --accept-license
==============================================================================

You may only use this Speedtest software and information generated
from it for personal, non-commercial use, through a command line
interface on a personal computer. Your use of this software is subject
to the End User License Agreement, Terms of Use and Privacy Policy at
these URLs:

        https://www.speedtest.net/about/eula
        https://www.speedtest.net/about/terms
        https://www.speedtest.net/about/privacy

==============================================================================

License acceptance recorded. Continuing.


   Speedtest by Ookla

     Server: XXXXXXXX - Moscow (id = 14190)
        ISP: XXXXXXXX
    Latency:     1.65 ms   (0.05 ms jitter)
   Download:    93.78 Mbps (data used: 42.4 MB)
     Upload:    93.54 Mbps (data used: 42.1 MB)
Packet Loss:     0.0%
..................

Then you may start the program w/o “–accept-license” option.