OpenWrt (ubus)
This is a presence detection scanner for OpenWrthostapd.*
, which will detect and report changes in devices connected to the access point on the router.
Before this scanner can be used, you have to install the ubus RPC packages on OpenWrt (versions older than 18.06.x do not require the uhttpd-mod-ubus
package):
Add a new system user hass
(or do it in any other way that you prefer):
- Add line to /etc/passwd: hass:x:10001:10001:hass:/var:/bin/false
- Add line to /etc/shadow: hass:x:0:0:99999:7:::
Edit the /etc/config/rpcd
and add the following lines:
Then, create an ACL file at /usr/share/rpcd/acl.d/hass.json
for the user hass
:
Restart the services. This ACL file needs to be recreated after updating/upgrading your OpenWrt firmware.
Check if the file
namespaces is registered with the RPC server.
After this is done, add the following to your configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file.
After changing the configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes. The integration is now shown on the integrations page under Settings > Devices & services. Its entities are listed on the integration card itself and on the Entities tab.
See the device tracker integration page for instructions how to configure the people to be tracked.
Troubleshooting
If you find that this never creates known_devices.yaml
, or if you need more information on the communication chain between Home Assistant and OpenWrt, follow these steps to grab the packet stream and gain insight into what’s happening.
Increase log level
-
On your Home Assistant device, stop Home Assistant
-
Adjust
configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] to log more detail for thedevice_tracker
integration. -
In another window, tail the logfile in the configuration directory:
-
If you see a Python stack trace like the following, check your configuration for correct username/password.
-
If you see lines like the following repeated at intervals that correspond to the check interval from the configuration (12 seconds by default), then Home Assistant is correctly polling the router, and you’ll need to look at what the router is sending back.
Inspect packets with TCPDump
These steps require that tcpdump
is installed on your Home Assistant device, and that you have a utility such as Wireshark
-
On your Home Assistant device, stop Home Assistant
-
In another shell on your Home Assistant device, start tcpdump
- In this example we are only looking for traffic to or from port 80, and we are writing the packet stream out to
/var/tmp/dt.out
- In this example we are only looking for traffic to or from port 80, and we are writing the packet stream out to
-
Start Home Assistant
-
After a few seconds you should see a line like
Got xx
wherexx
is an incrementing number. This indicates that it has captured packets that match our filter. After you see this number increment a few times (>20), you can hitCtrl-C
to cancel the capture. -
Transfer
/var/tmp/dt.out
to the machine where you’re running Wireshark and either drag/drop it onto the Wireshark window or use File/Open to open the capture file. -
In the window that opens, look for the first line that reads
POST /ubus
. Right click on this line, choose Follow and then HTTP Stream to view just the HTTP stream for this connection. -
The first
POST
will show Home Assistant logging into ubus and receiving a session identifier back. It will look something like this: -
In the response above, the portion that reads
"result":[0,
indicates that ubus accepted the login without issue. If this is not0
, search online for what ubus status corresponds to the number you’re receiving and address any issues that it brings to light. -
Otherwise, back in the main Wireshark window click the
x
in the right side of the filter bar where it readstcp.stream eq 0
. Scroll down until you find the nextPOST /ubus
line and view the HTTP stream again. This request is Home Assistant actually requesting information and will look something like the following: -
In this case we are actually receiving a valid response with no data. The request says that we are looking for ARP information from
hostapd.*
, which is the access point on the router. In my environment I don’t use the AP on the router, and so it was correctly returning no data. Armed with this information, I know that I cannot use this integration for device tracking or presence.
Cleanup
When you’re done troubleshooting, remember to reset your logging configuration and delete any capture files that contain sensitive information.