I have created a Flask Python app to do the tracking of devices per floor:
from flask import Flask
import json
app = Flask(__name__)
import os
routers = {'24:XX:XX:XX:XX': 'Bedroom', '24:XX:XX:XX:XX': 'Main', '24:XX:XX:XX:XX': 'Study', '24:XX:XX:XX:XX': 'Livingroom'}
map_to_floor = {'Bedroom': 'Second Floor', 'Study': 'First Floor', 'Main': 'Downstairs', 'Livingroom': 'Downstairs'}
types = ['2G', '5G']
def clients_by_identifier(identifier_fnc):
with open(os.environ.get('CLIENTFILE')) as file:
clients_by_id = {}
data = json.load(file)
for mac, location in routers.items():
for t in types:
if t in data[mac]:
if location in clients_by_id:
clients_by_id[location].extend(identifier_fnc(data[mac][t]))
else:
clients_by_id[location] = identifier_fnc(data[mac][t])
return clients_by_id
def find_location_of_client(identifier_fnc, client):
response = clients_by_identifier(identifier_fnc)
for router in response:
if client in response[router]:
return map_to_floor[router]
return 'Away'
@app.route('/')
def fetch_all():
return clients_by_identifier(lambda dict: [v['ip'] for _,v in dict.items()])
@app.route('/<mac>')
def fetch_by_mac(mac):
return find_location_of_client(lambda dict: list(dict.keys()), mac.replace('-', ':'))
@app.route('/ip/<ip>')
def fetch_by_ip(ip):
return find_location_of_client(lambda dict: [v['ip'] for _,v in dict.items()], ip)
Im running it on the server through the services-start file in /jfss/scripts:
#!/bin/sh
CLIENTFILE=/tmp/clientlist.json FLASK_APP=/tmp/mnt/usbdrive/client-exporter/app.py nohup flask run --host=0.0.0.0 &
This gives me the option to create a restful sensor in HA:
sensor:
- platform: rest
resource: http://192.168.2.1:5000/ip/192.168.2.69
name: "GJ Location Wifi"
So I can track exactly where a certain device is in my house, on which floor. This is not your exact use case, but with some modifications you can create a device tracker as well I guess.