Fhem Temperaturmessung mit 1wire & RaspberryPi

Ich verwende einen Maxim DS18S20 Temperatursensor mit folgender Belegung:

DS18S20 Belegung

Dieser wird folgendermaßen mit dem Raspberry Pi verbunden:

DS18S20 VDD an +3,3V vom Pi (Pin 1)
DS18S20 DQ an GPIO04 (Pin 7)
DS18S20 GND an GND vom Pi (Pin 6)

RaspberryPi P1 Header

Ausserdem ist noch ein Pullup-Widerstand von 4,7 kOhm zwischen Pin 1 und Pin 7 zu schalten.

Sobald der Sensor richtig verkabelt ist können wir uns der Software zuwenden und probeweise folgende Kernelmodule laden:

Wenn das ohne Fehler klappt können diese Module auch in die /etc/modules eingetragen werden, damit sie nach jedem Neustart automatisch geladen werden:

Update: Ab Kernel 3.18.3 bitte stattdessen dtoverlay=w1-gpio-pullup in die config.txt einfügen

Nun kann der 1Wire sensor unter Fhem eingebunden werden. Dazu zuerst das GPIO Modul aus dem contrib Ordner in den FHEM Ordner kopieren:

und in Fhem mit

einladen und den Raspberry Pi als Busmaster definieren:

Die Sensoren sollten dann beim nächsten Neustart automatisch erkannt werden.

CUL Firmware am Radxa Rock aktualisieren

Leider ließ sich die neue CUL firmware bei mir nicht direkt per Fhem mit
CULflash CUL_0 CUL_V3 einspielen, weil der dfu-programmer: no device present meldete. Vermutlich weil der user fhem nicht die nötigen Rechte zum flashen hat aber egal, dann halt manuell.

Zuerst den dfu-programmer installieren:

dann die CUL mit gedrücktem Button einstecken und folgende Befehle ausführen:

Nun kann in Fhem usb scan ausgeführt werden, dann sollte die frisch aktualisierte CUL wieder auftauchen.

Pair Phillips LivingWhites Luminaire Control Plug with HueBridge

I wanted to control my Phillips LivingWhites Luminaire Control Plug with Fhem, sadly the manual doesn’t even say a single word on how to hook it up to the HueBridge. Fortunately there is a little app called LampStealer doing exactly this. So here is what to do:

1. Download the LampStealer app
2. Unzip it
3. Run the LampStealer.app
4. Click „find bridge“ and select your bridge
5. Make sure your plug is really close to your bridge and click „start linking“

Bildschirmfoto 2014-10-10 um 10.12.00

Now it should already show up in your hue app and can be used in Fhem with:

where 5 is the id of the plug on the HueBridge.

The id’s of the devices on the HueBridge can be shown with:

How to keep your Raspberry Pi up to date

A question I find myself googling again and again is how to keep my Raspberry Pi up to date. Here is a short recipe:

Pushover message on motion event

sudo mkdir /home/motion
sudo nano /home/motion/pushover.sh
#!/bin/bash
curl -s \
-F "token=xxx" \
-F "user=xxx" \
-F "device=xxx" \
-F "title=$1" \
-F "message=$2" \
https://api.pushover.net/1/messages

sudo chmod +x /home/motion/pushover.sh
sudo nano /etc/motion.conf and edit line
; on_movie_end value
to
on_movie_end ~/pushover.sh Bewegungsmeldung „Eine Bewegung wurde festgestellt.“

Setup Motion on Raspberry Pi with Email Motion Alert

As postfix config use „Direct SMTP“ option, if necessary enable TLS:

You can test if everything works correctly with:

Now its time to get a version of motion tailored for the raspicam:

Add the freshly created motion user and yourself to the video group just for good measure:

Otherwise the motion service may fail silently with * failed to open vchiq instance

Enable and start the motion daemon with

Create a directory for motion’s videos and log files:

Make some adjustments to motion.conf, especially the paths for logs and videos:

and change
;on_picture_save
to
on_picture_save echo ‚Motion alert‘ | mail -a %f -s „Motion alert“

and reload the config file:

Create a directory for motion’s videos and log files:

Check if the motion process is running by

motion 7676 82.4 2.6 91488 23656 ? Sl 13:00 1:33 /usr/bin/motion

If there is no running motion process, check the service status for additional details why motion exited:

The output should look like:

tatsch@raspberrypi3
● motion.service - LSB: Start Motion detection
Loaded: loaded (/etc/init.d/motion)
Active: active (running) since Sat 2016-06-11 13:00:30 CEST; 1s ago
Process: 7662 ExecStop=/etc/init.d/motion stop (code=exited, status=0/SUCCESS)
Process: 7669 ExecStart=/etc/init.d/motion start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/motion.service
└─7676 /usr/bin/motion

Jun 11 13:00:30 raspberrypi3 motion[7669]: Starting motion detection daemon: motion.
Jun 11 13:00:30 raspberrypi3 systemd[1]: Started LSB: Start Motion detection.
Jun 11 13:00:30 raspberrypi3 motion[7676]: [0] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion.conf
Jun 11 13:00:30 raspberrypi3 motion[7676]: [0] [NTC] [ALL] motion_startup: Motion mmaltest Started
Jun 11 13:00:30 raspberrypi3 motion[7676]: [0] [NTC] [ALL] motion_startup: Logging to file (/home/tatsch/motion/motion.log)

If motion is setup correctly, you should be able to see the web stream:

http://raspberrypi3:8081

If you are unable to open the stream, check if motion is listening on the port:

Mask for motion

If you get a lot of false positives from the motion detection with your webcam or raspicam you should consider masking out the susceptible parts (busy streets, moving leaves etc.).

Simply take a false positive frame from your motion setup e.g. with VLC -> Video -> Snapshot. The mask must have exactly the same size as the image:

frame

Select the area where the motion should be masked out, fill it with black, invert the selection and fill the rest white. Save as jpeg and convert to pgm with imagemagick

or a jpeg-to-pgm converter.

mask

Now you can transfer the mask via scp or directly download the pgm file with:

and add the mask in your motion config file by:

and adjusting the mask_file path as follows:

# PGM file to use as a sensitivity mask.
# Full path name to. (Default: not defined)
mask_file /home/motion/mask.pgm

Finally restart the motion daemon:

and you should get a lot less false positive motion detections.