OpenWRT Presence Detection

Hi guys, been reading through some older posts who have had similar issues as me but not exactly so I want to share what I have done to ensure whether I’m missing something.
I want to integrate my R7800 openwrt router and use it for presence detection.
If it helps my openwrt version 23.05.5 - r24106-10cc5fcd00
I’ve been following the instructions from:

https://www.home-assistant.io/integrations/luci/
https://www.home-assistant.io/integrations/device_tracker/
My configuration.yaml file is 
device_tracker:
    platform: luci
    host: 192.168.1.1
    username: root
    password: xxxxxxxx
    interval_seconds: 10
    consider_home: 30
    new_device_defaults:
      track_new_devices: true

My understanding is after you reboot you should have another file created called known_devices.yaml ( I dont get this, I tried creating it manually) it made no difference here is my config I created

devicename:
  name: My Phone
  mac: xx:xx:xx:xx:xx:xx
  track: true

My router had these packages already installed:

Is there additional settings to configure in the router?

Do you also (and foremost) have luci-mod-rpc installed?

I use Ubus, it works well.

1 Like

Thanks Chris…if you look at my current packages that are installed above in my image is rpcd-mod-luci is it not the same as luci-mod-rpc. I did a search within the packages and that package alone did not appear in the opwnwrt install packages?

Thanks for the suggestion, with the Ubus procedure are all those configs minus the config.yaml file are performed in openwrt router system? and can these be created within the openwrt web gui?

Yes, everything was done on the router except for the configuration.yaml.

I used ssh for the commands and winscp to access and edit the files.

With all due seriousness, use platform UBUS instead of Luci. Yes, you have to configure the RPC.D. daemon to allow a certain user, which you must create, to have access to the table of online devices… but it works surprisingly well.

Thanks Rudd, I might end up giving this a go…quick question of of the commands is to add this line * Add line to /etc/passwd: hass:x:10001:10001:hass:/var:/bin/false
Whats the x (Is that the password)

My rpcd already has an entry I’m assuming for my router
config login
option username ‘root’
option password ‘$p$root’
list read ‘
list write '

Do I add another entry just below it
so it would look like this
config login
option username ‘root’
option password ‘$p$root’
list read ‘
list write '

config login
option username ‘hass’
option password ‘$p$hass’
list read hass
list read unauthenticated
list write hass
Does it have an impact that I have my main routers wireless switched off as I’m using a Deco mesh system used as AP’s around my house physically connected to my router?

Ive completed the procedure based on my understanding what does this command suppose to do? display the file contents of what file?

ubus list | grep file

file
Still got no known_devices.yaml file created
Thanks

Still there for me on Openwrt 23.05 and 22.03

for iPhone, and I think now also Android,
keep in mind that by default is uses a random Mac address,
on your mobile device you have to disable “private wifi addres” for the specific SSID.
else you cannot know the device is the same.

next to that I coudln’t get either Luci or UBUS to work in a stable way, devices were detected only sometimes,
so I configured a static IP in my openwrt router for the devices and use PING now

Ping eats phone battery. Measurably.

You have to increase consider_home for certain phones, AND you should check if the phone keeps dropping off of Wi-Fi on the Openwrt Wireless status page. That’s the source of presence info.

I’ve managed to configure luci:

configuration.yaml

device_tracker: !include my_device_tackers.yaml

my_device_tackers.yaml

######################## Trackers ######################
- platform: luci
  host: 192.168.0.1:801
  username: !secret secret_wrt_user
  password: !secret secret_wrt_pass

Then, if I remember correctly, I checked that in “Objects” tab device_tracker objects appeared.

known_devices.yaml contains all entries in the format:

micamera360:
  name: MiCamera360
  mac: XX:XX:XX:XX:XX:XX
  icon:
  picture:
  track: true

But I’m pretty sure I’ve never edited it manually. All entries are automatically generated (and updated) based on the dhcp names configured in openwrt.
I have several automations, like “Turn on the switch when PC is online”, and I’m pretty happy with the stability and speed of the integration.

I’ve got it working, the problem was that I have my wireless switched off on my router as I’m using a Deco mesh access points around the house. As soon as I switched it on the router wireless it created the know_devices.yaml file.

Next question is there a way to get it to work with my mesh instead of my router wireless as its so poor around my house? I read somewhere(cant find the link now) for mesh you need to install this package rpcd-mod-iwinfo that was already installed

When I enable my mesh it distributes ipv6 address where my router distributes ipv4 addresses if that makes a difference.

My wife has an iPhone 11 and I have Android, UBUS is very reliable for me.

You would have to add an integration specifically for the type of router that runs your mesh, because ubus can only get data from the router that has the devices connected directly to it.

In my case, I have two different wireless routers. Both of them would open WRT. And what I did was, I set up two Ubus integrations to query both routers. The integrations are smart enough to mark a device as being present if it appears in either of the wireless routers’ associated device list.

Thanks Rudd, all working now I found a TP-Deco HACS integration thanks to all for responding and sending me in the right direction…much appreciated.

1 Like

So happy to see you collect this win!

I’ve got similar config - openwrt without wifi and keenetic mesh wi-fi.
But it is important, that openwrt is the only dhcp server, and the main mesh router is connected to owrt using LAN port, not WAN. Also dhcp in MESH is disabled.
In that scenario I’m able to use tagged VPN’s for guest wi-fi etc, and all the devices are listed and controlled (bandwith, parental control etc) by openwrt.
So no need for specific addons, I think.

Thanks Petrovich that makes sense