A simple python script to control a fan from Home Assistant.
Note: I have replaced this Raspberry based solution with an Wemos/ESPHome based one you can find here:
https://gist.github.com/SqyD/38d10391c2e21988406d2bdaec24f031
- Installing dependencies on a stock Raspbian install:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip python3-dev python3-gpiozero
sudo pip3 install paho-mqtt
- Create the python script as /home/pi/mqtt_fan.py
- Create a systemd service definition file as /lib/systemd/system/mqtt_fan.service
- Set permissions:
sudo chmod 644 /lib/systemd/system/mqtt_fan.service
- Enable and test the service:
sudo systemctl daemon-reload
sudo systemctl enable mqtt_fan.service
sudo systemctl start mqtt_fan.service
Hi.
Thanks for the great code.
Please tell me how to properly connect the fan to the GPIO? It needs to be connected directly or through a transistor.
Please give me the connection diagram.
Thank.