Raspberry Pi Central Heating Controller, part 2 – Software

If you haven’t seen part 1, the hardware build, you can find that at https://blog.pgregg.com/blog/2018/11/building-a-raspberry-pi-based-central-heating-controller/

Software installation (Incomplete: I really need to figure out how to use wordpress properly)

  • Raspian Lite
  • python3-dev

When the Pi boots up, the GPIO pins will not be configured – but the relay board is getting 5V and 3V3 feeds.
This causes a little bleed on current – so we can fix this by pulling the GPIO pins we are using High (3.3V) – you’ll see this on the little leds on the relay board – they will be very slightly lit.


cat - > /usr/local/bin/relayreset.py
#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM) # GPIO Numbers instead of board numbers
GPIO.setwarnings(False)

GPIO_RELAY1 = 17
GPIO_RELAY2 = 18
GPIO_RELAY3 = 27
GPIO_RELAY4 = 22

GPIO.setup(GPIO_RELAY1, GPIO.OUT)
GPIO.output(GPIO_RELAY1, GPIO.HIGH)
GPIO.setup(GPIO_RELAY2, GPIO.OUT)
GPIO.output(GPIO_RELAY2, GPIO.HIGH)
GPIO.setup(GPIO_RELAY3, GPIO.OUT)
GPIO.output(GPIO_RELAY3, GPIO.HIGH)
GPIO.setup(GPIO_RELAY4, GPIO.OUT)
GPIO.output(GPIO_RELAY4, GPIO.HIGH)
time.sleep(1)
GPIO.cleanup()

chmod a+x /usr/local/bin/relayreset.py

HomeAssistant Install: https://www.home-assistant.io/docs/installation/raspberry-pi/

sudo apt-get install python3 python3-venv python3-pip python3-dev
sudo useradd -rm homeassistant -G dialout,gpio
cd /srv
sudo mkdir homeassistant
sudo chown homeassistant:homeassistant homeassistant

sudo -u homeassistant -H -s
cd /srv/homeassistant
python3 -m venv .
source bin/activate

python3 -m pip install wheel
pip3 install homeassistant

And run HomeAssistant:
hass

Or Install hass as a service:
cat - > /etc/systemd/system/home-assistant@homeassistant.service
[Unit]
Description=Home Assistant
After=network-online.target
[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"
[Install]
WantedBy=multi-user.target
CTRL-D

If you prefer systemV style init scripts:

TODO

Make it run at startup:
sudo systemctl --system daemon-reload
sudo systemctl enable home-assistant@homeassistant

Start the hass service:
sudo systemctl start home-assistant@homeassistant

View the homeassistant logs:
sudo journalctl -f -u home-assistant@homeassistant

Visit the hass web interface:
https://yourpi:8123

Updating HomeAssistant
sudo -u homeassistant -H -s
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistant

I used a Google Calendar as a scheduler.

TODO: More config on homeassistant.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

All content © Paul Gregg, 1994 - 2024
This site http://pgregg.com has been online since 5th October 2000
Previous websites live at various URLs since 1994