Here's how i set up my home controller. It will work even without an internet connection.
For this you will need:
- One raspberry pi 4 complete with sdcard (or any other hardware that runs linux or freebsd)
- A way of communicating to the remote switches
- Perhaps a google nest device so you can give verbal commands.
In my case, i do have a rfxcom trx433E and a google nest speaker, but there's other methods, including using a diy arduino RFLINK.
Setup in google home is pretty straightforward:
- Start google home on your device
- Click on the + at the left top to add a device
- Select '+ set up a device'
- Select 'works with google'
- Search for 'Homebridge' and activate it
- Select login with google and enter your password
With that, all configured devices will become visible in your google home environment once things are set up.
The raspberry couldn't be simpler:
- Get tje raspberry pi manager: from raspberrypi.org
- Stick the sdcard in a USB sdcard converter and plug it the computer
- Run the pi manager, select 'choose os', select 'raspberry pi os other', select raspberry OS lite
- Select the USB storage
- Write it
Once done, eject the sdcard and insert it in the raspberry pi.
Now boot up the pi. It will reboot once or twice, but eventually it will show up with a login prompt.
login using the default username/password: pi/raspberry
Make sure to change that default password by using the command: passwd
next, check your ip address
If SSH seems to have a problem:
reset ssh certificates
sudo rm /etc/ssh/ssh_host*
sudo dpkg-reconfigure openssh-server
Now activate ssh and set the correct timezone:
SSH can be activated under the menu 5, interfacing options. The timezone is under 4, localisation options
While logged in, might aswel update the os:
sudo apt-get update
sudo apt-get upgrade -y
#(once it finished everything)
sudo reboot
Last, set a static ip for the system:
static ip
sudo nano /etc/dhcpcd.conf
# now add the following in that file
interface eth0
static ip_address=
static routers=
static domain_name_servers=
# hit ctrl-x and save the file to exit.
With that, the basic system is finished!
To set up freebsd is described well everywhere and there are no alterations we need.
Just make sure that:
- You use the latest stable version of freebsd
- Set a static ip address
- Optionally activate firewall
We won't be using the ports tree, instead pkg is used to save time and keep things simple.
Installation is straighforward:
Domoticz install the easy way
curl -L https://install.domoticz.com | bash
Just let it run and do it's thing.
set up monitoring:
MONIT monitoring install
sudo apt-get install monit
chmod 700 /etc/monit/monitrc
Setting up homebridge
By far the easiest approach to get things to work is homebride.
It is intended for IOS devices, but with a plugin it is possible to connect it all to google home!
homebridge install commands
curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -
sudo apt install -y node.js gcc g++ make python
#verify node is installed
node -v
sudo npm install -g npm
sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x
sudo npm install -g homebridge-edomoticz
sudo npm install -g homebridge-gsh-kazari
sudo hb-service install --user homebridge
Setting up homebridge
Note: make sure to be root user to execute these commands
Setting things up on freebsd is also pretty straightforward:
domoticz install commands
pkg install domoticz
and we're done... nothing else needed!
Installing homebridge
Installing homebridge is also straightforward in freebsd:
homebridge install commands
pkg install node
pkg install node20
pkg install npm
pkg install npm-node20
npm install -g unsafe-perm homebridge homebridge-config-ui-x
npm install -g homebridge-edomoticz
npm install -g homebridge-gsh-kazari
hb-service install --user homebridge
Note that you do not use 'root' as the user for hb-service!! homebridge will fail to start if you do!
Optional: installing monit
Monit can keep tabs on what's going on and make sure that whenever domoticz decides to crash (again..) that it is restarted. It can monitor multiple services and system specific data and act according to it's setup.
install monit
pkg install monit
touch /usr/local/etc/monitrc
chmod 700 /usr/local/etc/monitrc
The configuration of monit is done via the file /usr/local/etc/monitrc, the contents of the setup here is stated below.
Optional: installing mqtt
MQTT can increase responsiveness of the system. To use it, install mosquitto:
homebridge install commands
pkg install mosquitto
As far as config goes: just copy the mosquitto.conf.sample to mosquitto.conf in the /usr/local/etc/mosquitto folder.
Starting at boot
edit the file /etc/rc.conf and add:
homebridge install commands
domoticz_enable="yes"
domoticz_user="root"
domoticz_group="wheel"
domoticz_dbdir="/usr/local/domoticz"
homebridge_enable="YES"
mosquitto_enable="YES" <-- if installed!
Domoticz should be up and running at http://<YOUR IP>:8080
it will ask for a username and password: admin/domoticz
If this does not work you can actually do a 'recovery' by stopping the domoticz service, then start it manually with a --nowwwpasswd option. You can then set the password, or exclude the network from the need for a password.
System settings
First thing to do in domoticz is setting up some system options. Go to 'setup' and next to 'settings' in that menu.
Set up your preferences in the system tab, most importantly, at first, set 'accept new hardware devices' to 'on'.
Next, go to the 'security' tab, and at least set 127.0.* as a trusted network! Else neither homebridge or mqtt will be able to function. You can also add your home network to it so you'll never have to login when checking things via your privat network.
If you were running domoticz temporary using --nowwwpasswd, save these settings, stop the temporary running domoticz and start it as a service again before continuing.
Everything else is primarily according to your own preference.
Hardware
Next, it is time to set up some hardware so domoticz can detect and use devices.
As stated, i do have a rfxcom device attached to the domoticz machine, which is a standard option in the hardware list of domoticz: rfxcomm 433. And i activate the options i need for the so-called 'klik aan klik uit' devices i have, they use 'lighting 2' protocol.
If you did install mosquitto, make sure to add the 'hardware' for it: MQTT client gateway with LAN interface.
Once added, you will see it in the hardware list with a 'setup' button. Click it to set up mqtt:
- give it a name
- set remote address to 127.0.0.1
- set port to 1883
the rest remains default.
Devices
Scan the detected devices (perhaps click 'refresh') and add any devices that you want to control by clicking the little green arrow circle, and giving it a name.
Adding a roomplan (when not using mqtt)
For homebridge to detect the devices you have, it is necessary to add them to a roomplan. To do this, click on 'setup', select 'more options' (by hovering the mouse over it) selecting 'plans' (also by hovering over it) and last select 'Room'.
Now, click 'add a plan' and give it a name. Make a note of the Idx it received..
Click on the new room plan, and a second list appears, click the 'add' button and add all the devices you want google home to be able to control.
With that, the configuration is done. If you want to add more devices, then follow the same procedure: detect the device, add it with the green circle arrow, give it a name, add it to the room plan and done.
using MQTT
When using mqtt, things change a little. Then we have to tell mqtt what devices are available instead of pushing everything to a room plan.
To so this, after adding all the devices to domoticz, go to settings and next to 'hardware'. There, the mqtt hardware is already available.
Click on the setup button in that line, then add any device to the selected options that you want to be able to control via mqtt.
Once done, click 'save'.
Homebridge should be up and running at http://<YOUR IP>:8581
Login using the default username/password: admin/admin
Homebridge domoticz plugin
In the homebridge page 'plugins' you will see the homebridge edomoticz plugin. Select settings and enter the information needed there.
If you did not add a network that does not need a password in domoticz, the host should be entered as <username>:<password>@<your ip address>, otherwise, it is just the ip address.
The port number usually is 8080 and set the room id to the idx you noted for the room plan in domoticz configuration. Alternatively, you can set it to 0, which means: load all devices available in domoticz.
Last, click 'advanced settings' and set the mqtt setting disabled or enabled, depending on if mosquitto mqtt is installed.
Homebridge google smart home plugin
Go to the plugins page and there should be a homebridge google smart home plugin.
click on 'settings' and click on 'link account'.
Now enter the google account you will use in the google home application on your phone (check phone settings, accounts).
You will get a confirmation on your phone once you do, and allow that access.
Last thing to do: restart homebridge to update everything!
the monitrc file has to be editted to set the configuration. On most linux distros, this file can be found in /etc/monit/monitrc, on freebsd this is /usr/local/etc/monitrc.
Open that file in an editor and put this information in it:
homebridge install commands
set daemon 30 # check services at 30 seconds intervals.
set log syslog # messages show up in messages syslog
set httpd port 2812
use address 0.0.0.0 # if only localhost is desired, replace 0.0.0.0 with localhost
allow 0.0.0.0/0.0.0.0 # if only localhost is desired, then just put localhost here, else just add your local network ip range and mask.
allow admin:monit # require user 'admin' with password 'monit', change if your system is accessible from internet
#if you like monit to email you:
#set mailserver port 587
#username "yourmailaddress@gmail.com" password "MYPASSWORD"
#using tlsv1
#with timeout 30 seconds
#set alert email@yourdomain.com
# monitoring the system
check system $HOST
if loadavg (1min) per core > 2 for 5 cycles then alert
if loadavg (5min) per core > 1.5 for 10 cycles then alert
if cpu usage > 95% for 10 cycles then alert
if memory usage > 75% then alert
if swap usage > 25% then alert
# monitoring Domoticz
check process domoticz with pidfile /var/run/domoticz.pid
# for linux distros, use the start/stop commands below
# start program = "/usr/bin/sudo /bin/systemctl start domoticz.service"
# stop program = "/usr/bin/sudo /bin/systemctl stop domoticz.service"
# start/stop command for older systems not using systemctl
# start program = "/etc/init.d/domoticz.sh start"
# stop program = "/etc/init.d/domoticz.sh stop"
# for freebsd these are the correct commands:
start program = "/usr/local/etc/rc.d/domoticz start"
stop program = "/usr/local/etc/rc.d/domoticz stop"
if failed
url http://127.0.0.1:8080/json.htm?type=command¶m=getversion
and content = '"status" : "OK"'
for 2 cycles
then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"
# please change start/stop programs according to your system, here only freebsd is shown. See the domoticz examples above.
check process mosquitto with pidfile /var/run/mosquitto.pid
start program = "/usr/local/etc/rc.d/mosquitto start"
stop program = "/usr/local/etc/rc.d/mosquitto stop"
check process homebridge with pidfile /var/run/homebridge.pid
start program = "/usr/local/etc/rc.d/homebridge start"
stop program = "/usr/local/etc/rc.d/homebridge stop"
## save the file and close it.
## check validity of the config:
sudo monit -t
## if it all checks out on linux:
sudo service monit start
sudo monit status
## or freebsd
/usr/local/etc/rc.d/monit start
As far as domoticz and homebridge are concerned, the names do not really matter. But they do to google! The lights being recognized does depend on wether or not google can make sense of the names of the ligts (or devices)
In the google home app, select the device and give it a name that easy to distinguish and also easy to say, so google can make sense of it.
If you really have to, you can use numbers, but write them out instead of using digits!
It sometimes takes a bit of experimenting, but to test everyting in one go, just yell: hey google, switch all lights on!
Any light that is defined and useable, will then switch on
Otherwise, just name the light and on/off/percentage to set it