Raspberry Pi Home Automation
Config
sudo apt-get install git-core
sudo apt-get update
sudo apt-get upgrade
raspi-config
hostname
ssh enable
GPIO over network
update
crontab or rc.d
Check
sudo crontab -e
for demons to be started.
* I removed them and added them to
/etc/init.d/
*
init.d vs. cron
*
rc2.d is the user level stuff
Atention
: Don’t forget to set the LSB header.
> ### BEGIN INIT INFO
# Provides: sshd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: OpenBSD Secure Shell server
### END INIT INFO
User
Create User and Delete old one
Create new user and delete old one:
sudo adduser USERNAME
User rights
sudo usermod USERNAME -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio
sudo visudo
Wi-Fi Setup
- Scan networks
sudo iwlist wlan0 scan
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
- Add this:
network={
ssid="YOURNETWORK" psk=BIGHASH
}
To create psk
go with
wpa_passphrase "YOURNETWORK"
- internationalization Options of
raspi-config
, you have to choice the country for Wi-Fi for DE
- edit the interfaces file using this command
sudo nano /etc/network/interfaces
and add the following lines:
auto wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
no ssh while not eth0
- https://unix.stackexchange.com/questions/50602/cant-ifdown-eth0-main-interface
- https://raspberrypi.stackexchange.com/questions/10035/cannot-connect-to-raspi-by-ssh-with-wifi-interface-only
GPIO
433
DHT22
„Der linke Pin des Sensors wird an 3V3 von Pi (Pin1) angeschlossen, der zweite Sensor Pin über einen Pull-Up Widerstand (
4.7k – 10kΩ) mit einen freien GPIO des Raspberrys (bei mir GPIO4, Pin7) und der rechte Senior Pin kommt an GND (Pin6) vom Pi. Der zweite Pin von rechts des Sensors bleibt frei.“
Backup da Pi
Script
wget http://www.linux-tips-and-tricks.de/de/downloads/raspibackup-sh/download -O raspiBackup.sh
- move to
/usr/local/bin
mv raspiBackup.sh /usr/local/bin
sudo chmod 755 /usr/local/bin/raspiBackup.sh
Stick
/mnt/USBBkp
– sudo mkdir /mnt/USBBkp
– lsblk -o KNAME,TYPE,SIZE,MODEL
– sudo mkfs.ext4 /dev/sdc
– modify /etc/fstab/
/dev/sdc /mnt/USBBkp ext4 defaults 0 0
Hint: add nofail
to options, so the Raspberry won’t fail at boot.
crontab
# Jeden Tag um 4 Uhr ein Backup nach usbstick im tar Format der ganzen SD-Karte und 4 Versionen vorhalten
00 4 * * * /bin/bash --login /usr/local/bin/raspiBackup.sh -p /mnt/USBBkp -t tar -k 4
set up smtp for sending mails
Notice:
not active at the moment
- http://blog.wenzlaff.de/?p=2412
sudo apt-get install mutt msmtp ssmtp nano mailutils mpack ca-certificates apt-show-versions
Important notice
- take care of
-o "service cron stop" -a "service cron start"
as described here.
Services
Time Maschine Backup
Find external drive
lsblk -o KNAME,TYPE,SIZE,MODEL
Format drive
sudo mkfs.ext4 /dev/sda
Install netatalk
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install netatalk
Create a mount point
sudo mkdir /mnt/TimeMachine
Add mount to file system table (fstab)
sudo nano /etc/fstab
/dev/sda /mnt/TimeMachine auto defaults, nofail 0 2
Mount device
sudo mount /dev/sda
Make it accessible
sudo chmod 777 /mnt/TimeMachine
Make the drive known to netatalk
sudo nano /etc/netatalk/AppleVolumes.default
/mnt/TimeMachine "Time Machine" options:tm
# End of File
Restart netatalk & Raspi
sudo service netatalk restart & sudo reboot
Mac: Allow unsupported devices
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
cartoonify
Notice:
not active at the moment
Homebridge
- https://github.com/nfarina/homebridge
Installation
Node
Using Debian, as root
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs
Run
sudo apt-get install -y nodejs
to install Node.js 11.x and npm
You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
npm
Useful commands:
–
List them allnpm list -g --depth=0
to list all installed packages
- Start with boot
sudo npm install -g pm2 --unsafe-perm
pm2 startup
pm2 start homebridge
( pm2 stop homebridge to disable or exit )
pm2 save
Homebridge
sudo npm install -g --unsafe-perm homebridge
Plugins
Camera
- https://www.npmjs.com/package/homebridge-camera-ffmpeg
ffmpeg
- https://www.denniswilmsmann.de/2018/04/ffmpeg-unter-raspbian-installieren/
Plugin
npm install -g homebridge-camera-ffmpeg
- Edit
config.json
and add the camera.
,{
"platform": "Camera-ffmpeg",
"cameras":
[
{
"name": "Camera Name",
"videoConfig": {
"source": "http://videostream.asf?user=basti&pwd=basti123&resolution=32&rate=0",
"maxStreams": 2,
"maxWidth": 1280,
"maxHeight": 720,
"maxFPS": 30
}
}
]
}
People
- https://www.npmjs.com/package/homebridge-people
RCF Outlet
- https://www.npmjs.com/package/homebridge-rfoutlets-protocol
sudo npm install -g homebridge-rfoutlets-protocol
Update your homebridge configuration
You need to compile codesend for your CPU architecture (raspberry-remote repo) and replace …/node/lib/node_modules/homebridge-rfoutlets-protocol/codesend with your self compiled version.
In
/usr/lib/node_modules/homebridge-rfoutlets-protocol
create a symlink
sudo ln -s /home/basti/raspberry-remote/send send
Modify /usr/lib/node_modules/homebridge-rfoutlets-protocol
to match send
instead of codesend
(params)
DHT
sudo npm install -g homebridge-dht
for DHT22 sensor (humidity and temperature)
update config.json
with
{
"accessory": "Dht",
"name": "dht22",
"name_temperature": "Temperature",
"name_humidity": "Humidity",
"service": "dht22"
}
sudo apt-get install pigpio python-pigpio python3-pigpio
sudo cp /usr/lib/node_modules/homebridge-dht/dht22 /usr/local/bin/dht22
sudo chmod a+x /usr/local/bin/dht22
2nd sensor, if needed
Infrared lirc
sudo apt-get install lirc --yes
Receiver GPIO: 26
Sender GPIO: 22
Cam_Web_Interface
Twitter Bot
433 Mhz Remote Control
Equipment
- [x] 2 Raspberry Pi’s (zur Not geht auch eines)
- [x] 433 MHz Sender-Empänger Set (falls beide Pi’s senden und empfangen sollen brauchst du 2 Sets)
git clone git://git.drogon.net/wiringPi && cd wiringPi &&./build
Jetzt brauchen wir noch eine Bibliothek, die es uns einfach ermöglicht unsere Daten über den Sender zu verschicken und über das Empfängermodul zu empfangen.
git clone https://github.com/ninjablocks/433Utils.git --recursive
Diese Bibliothek enthält sowohl für das Arduino, also auch für den Pi entsprechende Skripte. Wir wechseln nun in den Ordner mit den Skripten für das Raspberry Pi und kompilieren diese
cd 433Utils/RPi_utils
make all
Lights
array("systemcode", "group" , "plug", "description");
Systemcode ist sozusagen der Schlüssel um die Steckdose ansprechen zu können und sollte somit bei allen Steckdosen gleich sein
Systemcode
11111
- array(„1“, „11111“, „16“, „Ess 1“),
- array(„1“, „11111“, „08“, „Ess 2“),
- array(„1“, „11111“, „04“, „Wohn 1“),
- array(„1“, „11111“, „02“, „Wohn 2“),
Beispiel:
/send 11111 4 1
schaltet die 4. Steckdose ein.
- https://jankarres.de/2015/04/raspberry-pi-funksteckdosen-einrichten/
Tips & Tricks
How to SSH into your Raspberry Pi with a Mac and Ethernet Cable
how-to-ssh-into-your-raspberry-pi-with-a-mac-and-ethernet-cable
remote editor
ssh -R 52698:localhost:52698 USER@PI
rsub xxx
Get IP address B8:27:EB
All raspberry devices MAC addresses started with B8:27:EB
So, on *nix systems, this can be accomplished by executing the following command:
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
where 192.168.1.* will be your local network mask. You will get an answer like:
Nmap scan report for raspberrypi.localnetwork.lan (192.168.1.179)
UUID for /etc/fstab
- verify mounting
cat /etc/mtab
- UUID discovery
ls -l /dev/disk/by-uuid/