Command line sensor python3 missing module

Hi all,
I’m running a Home Assistant supervised on debian 11 O.S. on raspberry PI4.

I need to configure two sensor to display the status of a GeekWork X728 UPS Hat (Raspberry Pi X728 (Max 5.1V 8A) 18650 UPS & Power Management Board – Geekworm).
The battery status can be read via I2C and basing on some example I created a
python3 script to run via command_line sensor.

The script return battery voltage and battery capacity in json format and work great if i run in a ssh console, but fail to run under docker because the module smbus is missing under homeassistant docker.

I also create a test script that return the json structure with some fixed values without retrieve data from I2C to test the sensors in the configuration.yaml and it works great.

Then my issue is only related to smbus. How I can add the python3 module smbus under homeassistant docker?

Thanks

The module might not be enough, because the smbus might simply not be available at all in a virtual enviroment, like docker.
You should maybe set HA up to make the SSH connection to the host and then run it like your test.

Aside what @WallyR wrote (I have no clue if smbus will work or not)… when you add it into the container, it will be gone with the next upgrade.
However, I chose to do so as the other option was not working out fine for my package.
So, I went into the container to do a "pip install [package]’ … which I now do about once a month (I donot upgrade to each release)

Another option, this may work sometimes, is to put the package in the same set of folders as the py you run and do a import from there. I got this working once in a while from my config/python_scripts

Thanks for the reply!
I configured ‘SSH & Web Terminal’ add-on disabling the Protection Mode option, as suggested in SSH'ing from a command line sensor or shell command.

Calling the script from SSH all is good.

I’m only sorry that the add-on cant start in home assistant supervised, I suppose because on debiab O.S. a ssh service is already running. But in the post is reported that the add-on is required to configure docker to allow calling ssh service. I shall left it stopped but configured with protected mode disabled.

HAOS systems also often have two ssh services running since you can enable host ssh. Doesn’t cause an issue.

But host ssh runs on port 22222 when you enable that for HAOS instead of the usual port 22. Are you trying to use port 22 for both services? If so then that won’t work, one of them has to use a different port.

My homeassistant is the supervised installation running on debian system.
I figured out that the “raspbian 64bit edition lite” is simply a debian 64bit as reported in etc/os-release:

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

By this, the O.S. already offers a standard ssh service on port 22. If the add-on try to add another ssh on the same port, the operation cannot be done. For my use, that’s not a problem since I already had a ssh service, manually configured to accept only ssh keyfile connections on standard 22 port. In this way, if the guide is true, the add-on is used only to enable the homeassistant docker container to allow ssh connection without restrictions. To start the add-ons at all I need to change the port used by the addon.

Raspbian isn’t Debian, it’s a derivative of Debian. Which means it does not meet the requirements for a supported supervised install:

Debian Linux Debian 11 aka Bullseye (no derivatives)

So if you’re running on Raspbian then that probably explains why some things aren’t working as expected. You are likely to run into a number of strange issues on an unsupported OS.