SwiftOccupancy is designed to provide room occupancy tracking using thermopile sensors. By placing sensors at the top of a doorway two rooms can be tracked at once. Paired sensors allow quick and easy presence detection.
People are counted as they walk between rooms, so walking out of one room decreases the count there and increases it in the room you walk into. For privacy a sensor doesn't need both rooms, only the specified rooms will be counted.
SwiftOccupancy designed to be run on a cluster of Raspberry Pis, preferably a Raspberry Pi 4 or Raspberry Pi Zero 2. You can use anything you'd like so long as it:
- Can run Swift 5.5 (a 64-bit OS)
- Has I2C support
The recommended way to run SwiftOccupancy is on a Raspberry Pi Zero 2 running the 64-bit version Ubuntu Server 21.10.
- Flash the Ubuntu Server 21.10 to your SD card with Raspberry Pi Imager
- Plug the SD card back into your computer for initial config
- Add WiFi settings in
network-config
- Triple check that your editor hasn't changed the indentation because YAML is picky
- Copy the
bcm2710-rpi-3-b.dtb
file tobcm2710-rpi-zero-2.dtb
- Until Ubuntu officially supports 64-bit on the Zero 2 this needs to be done
- Boot your Pi and SSH in
- Install the Swift repository
- Select Swift 5.5 (or latest) when prompted
For now clone the repository and either build it on a Pi or use a cross-compiler toolchain.
git clone https://github.com/emorydunn/SwiftOccupancy.git
cd SwiftOccupancy
swift build
The sensor should be placed such that the top and bottom of the frame point across the door. At this time there is no rotation support and people will only be detected when walking from top to bottom and visa-versa.
SwiftOccupancy
has a number of command line options, but in order to run an instance the command to run is SwiftOccupancy occupancy i2c
. You'll need to provide a number of options to configure the instance. The required ones are:
- host
- username
- password
- address
- At least one room
- You don't technically need to provide any rooms, but it'll be a pretty useless sensor
OVERVIEW: Read data from an I2C sensor.
Data is read from an I2C sensor, occupancy changes are parsed and published to Home Assistant via MQTT.
USAGE: swift-occupancy occupancy i2c [<options>] --host <host> --address <address>
OPTIONS:
--host <host> MQTT server hostname
--port <port> MQTT server port (default: 1883)
-u, --username <username>
MQTT username
-p, --password <password>
MQTT password
--enable-camera/--disable-camera
Publish the rendered sensor view. (default: false)
--board <board> The board for connecting via I2C (default: RaspberryPi4)
--address <address> The sensor address
--top-room <top-room> The top room name (default: ether)
--bottom-room <bottom-room>
The bottom room name (default: ether)
--reset-counts Reset room counts.
--delta <delta> The delta between what is detected as foreground and background. (default: 2.0)
--size <size> The minimum number of pixels for a cluster to be included. (default: 5)
--width <width> The minimum width of a cluster's bounding box. (default: 3)
--height <height> The minimum height of a cluster's bounding box. (default: 2)
--version Show the version.
-h, --help Show help information.
Additionally there is a sample systemd
service in Support that can be used to run SwiftOccupancy
on boot.
- Copy the sample file to
/lib/systemd/system/
- Edit the file and set your desired command line options
- Copy the
SwiftOccupancy
binary to/home/ubuntu/.bin
- Add execution permission:
sudo chmod +x /lib/systemd/system/occpancy.service
- Start the service:
sudo systemctl daemon-reload
sudo systemctl enable occpancy.service
sudo systemctl start occpancy.service
Included in the Support directory is a blueprint for easily controlling lights based on occupancy and the sun. There are four states you can configure:
- Empty Room
- Occupied during the day
- Occupied in the evening
- Occupied at night after a specified time
In order to use it you'll need to import the blueprint into Home Assistant.