Export OpenWrt Data to Home Assistant

I am interested in getting information from my two OpenWRT devices into Home Assistant sensors. I am not:

  • Trying to install home assistant on my OpenWRT devices. There are a lot of topics on this.
  • Do device_tracking, which lets you determine if you phone is home or not. The two OpenWRT integrations on home assistant (one luci based and the other ubus based) seem to be focused on device tracking.

I used to use DD-WRT and I was able to scrape some information from the passwordless status page. I was mainly interested in load average (whenever things were bananas, the load average was very high).

My Home Assistant server does run an mqtt server.

I know how to code. I am an experienced Linux desktop user. I am not looking for a second job though. But something scripty like python would probably be more fun than difficult (until it broke).

There are a lot of home assistant integrations. Glances seems particularly interesting.

I am interested in seeing these things:

  • Load average
  • uptime
  • Free memory (which will be lower because of this script, :slight_smile:)
  • Number of "Associated Stations" (devices connected) for each wireless network (wlan0, wlan1, wlan1-1)
  • WAN Bytes sent and received. A rate would probably be the most useful.
  • Number of DHCP clients.
  • Number of DHCP clients that aren't using static leases.

If I can get these values into home assistant, I can keep histories over time, add automations, or just have a nice interface to glance at when someone complains that "the internet isn't working".

So I think these are my choices:

  1. Make luci publish a page and then scrape it. Ideally a no-password interface/web server with some usable statistics. If it was just json, that would be easy to scrape.
    a. Similarly, is there a REST API that I can use? Maybe I can configure a read only user to get this info without running too much extra code on my routers?
  2. Run a premade service on OpenWRT (connectd, snmp, glances?) that would collect this information and publish it.
  3. Run custom code on OpenWRT to publish the data. Run a python script from cron and have it publish the result?
  4. Run custom code on another machine that would connect to a running service on OpenWRT
    a. ubus? I've seen some information on this. Seems reasonable.

What would you recommend? Have you done anything like this before? I'm looking for opinions and direction before I start trudging down one of these directions to learn all I can.

You might want to take a look at something like https://github.com/lukdwo/OpenWRT-collectd-MQTT-HA, rather than starting from scratch.

Disclaimer: I have not tried this, it's just what I found from a quick Google search.

2 Likes

I'm on the same boat (but have not been able to advance, due to a cronic lack of time), and option 3 would by my first choice.

1 Like