PiSwitch/README.md

2.5 KiB

PiSwitch

A Raspberry Pi Relay controller based on the Astral Library

Physical setup

Use physical pin numbering

Pi pinout

Switch Toggle Button:

3.3v: either pin 1 or pin 17

signal: pin 11

Astral Toggle Button / Switch:

3.3v: either pin 1 or pin 17

signal: pin 15

LED's

5v: eiter pin 2 or pin 4

signal: pin 12

ground : any ground pin

Relay

5v: eiter pin 2 or pin 4

signal: pin 38

ground : any ground pin

Installation Process

Clone the repository

git clone https://git.dennisvandermeulen.nl/dennis/PiSwitch.git
cd PiSwitch/

Setup virtual environment & install requirements (skip if you use Docker)

python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt

Setup config.ini

nano src/config.ini

Config.ini

Set up the base url for your api

[setup]
baseurl = http(s)://www.example.com:port/

setup switch id

switchid = integer

Setup whether information must be pushed to the database

storedb = 0/1

Set the apikey for this PiSwitch

apikey = string

Set the key of the PiSwitch reporting server (Do not use if storedb=0)

srvapikey = string

Setup your location info

[location]
name = name
region = region
lat = float
lon = float
timezone = Europe/Amsterdam

##Docker Use the included Docker-Compose files to build the scheduler and server container

docker-compose . -up -d

Systemd

Use the following scripts to automatically start the scripts at boot for a true headless experience

server.py

[Unit]
Description=Relay Switch Server
After=multi-user.target

[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/path/to/PiSwitch/src
ExecStart=/path/to/venv/bin/python3 path/to/PiSwitch/src/server.py

[Install]
WantedBy=multi-user.target

save as relayserver.service

scheduler.py

[Unit]
Description=Relay Switch listener
After=multi-user.target
Requires=relayserver.service

[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/path/to/PiSwitch/src
ExecStart=/path/to/venv/bin/python3 path/to/PiSwitch/src/scheduler.py

[Install]
WantedBy=multi-user.target

save as scheduler.service

Troubleshooting

Check LED color for basic status indications

White Solid = No Wi-Fi

Red Solid = Lights off

Green Solid = Lights on

Blue Flashing = Astral enabled

Off = No power / Led dead :)