Use Selenium with custom sensor

I have:

  1. A running instance of Home Assistant with HassIO, on a Raspberry PI.
  2. A Python code that does what I need on my Ubuntu desktop, and needs Selenium to fetch some data.

Now I want to fetch this data and display it as a graph in Home Assistant. The question is: how to use Selenium on HassIO, Selenium being a dependency of a custom sensor?

By Selenium I mean any “browser + webdriver” combo that works. I’ve tried with chrome/chromium, but firefox or phantomjs (actually, deprecated) would be fine, too.

Here’s what I’ve tried:

  1. The most straightforward way would be just to install chromium and chromium-chromedriver packages from the Alpine Linux repository using the APK package manager. I enabled community repository in APK and tried to install e.g. chromium with apk add chromium, but I get this:
WARNING: Ignoring APKINDEX.0a96cc2d.tar.gz: No such file or directory
WARNING: This apk-tools is OLD! Some packages might not function properly.
ERROR: unsatisfiable constraints:
  chromium (missing):
    required by: world[chromium]

  1. I thought of creating a Home Assistant add-on, using Docker. Then I could install Selenium dependencies there. However, I’ve tried to do it, but given that I’m a novice in terms of Docker, I faced a similar problem like described above (probably the root cause is the same). Theoretically I could expose a server with a REST API, and I could tell HASS to fetch the value from this local server. But I want to avoid going this direction for now, it in favor of creating a custom Python sensor class, because I believe it should be possible and is much simpler. The main question here is whether add-ons allow exposing some Python classes, without running a server and exposing APIs?

What is the recommended way to go here?

After a revelation that chromium and Selenium driver can be downloaded straight as binaries, I hit another wall. Every binary I ran reported that the format is invalid or something similar, which probably means that it was compiled for another platform. Raspberry runs on ARM, and I even tried one binary for ARM, but no success.

The question becomes: is there a way to use chrome and webdriver without having to compile them from source code?

hi,
i didn’t try it but take a look at

https://archlinuxarm.org/forum/viewtopic.php?f=5&t=5532#p32923

see if it helps

Hi,

I recently met the same problem and I search “chromedriver armhf” in google. I got the list of available releases:

https://launchpad.net/ubuntu/xenial/armhf/chromium-chromedriver

I take the version 72.3626.0.121 corresponding to my chrome browser on my Raspberry 3B+. After installation, It works on command line but not yet via sensor.

Keep debugging on this issue.

1 Like