This script is a based on https://github.com/initialstate/pi-sensor-free-presence-detector
Scans MAC Addresses using arp-scan and sends message to mqtt broker to determine occupancy.
- Python 2.7
- paho-mqtt
- arp-scan
~# cd /home/pi
~# wget https://raw.githubusercontent.com/NightRang3r/Arp-Presence-Detection-MQTT/master/presence.py
You will need to adjust the script with your own parameters in the settings section:
MQTT_HOST = "127.0.0.1" - Your MQTT Broker IP Address MQQT_USER = "mosquitto" - MQTT Broker User Name MQTT_PASS = "12345678" - MQTT Broker Password MQTT_TOPIC = "presence" - MQTT Broker Topic T_SLEEP = 30 - Scan Interval INTERFACE = "eth0" - Network Interface DEVICES= {"Bob": "00:00:00:00:00:00", "Alice":"01:01:01:01:01:01"} - List of devices, you can add more devices.
~# sudo pip install paho-mqtt
~# sudo apt-get update
~# sudo apt-get install arp-scan
~# cd /etc/systemd/system/
Create a new file
~# sudo nano presence.service
Paste this into the new file and save:
[Unit] Description=Presence Wants=network.target After=network.target [Service] Type=simple ExecStart=/usr/bin/python /home/pi/presence.py User=root [Install] WantedBy=multi-user.target
~# sudo chmod 755 presence.service
~# sudo systemctl daemon-reload
~# sudo systemctl enable presence.service
~# sudo systemctl start presence.service
~# sudo systemctl status presence.service
~# sudo reboot
device_tracker.yaml:
- platform: mqtt devices: bob_arp: presence/bob alice_arp: presence/alice
known_device.yaml (devices will be generated automatically, just change track value to true):
bob_arp: hide_if_away: false icon: mac: name: Bob picture: track: true alice_arp: hide_if_away: false icon: mac: name: Alice picture: track: true