How To - Control Sunshades - Somfy-Telis with Raspberry Pi
This application requires decent soldering skills. Also basic familiarity with Linux command line instructions is required.
DO NOT USE THIS CODE NOW AS IT IS BEING CONVERTED FOR USE WITH RAZBERRY V2.0.X
Power off the Raspberry Pi before connecting the interface. Double check if the connections are correct! It is very easy to blow up your Pi.
For RaZberry release 1.4.1 see this description
This is a Community Supported application. This instruction is tested on OpenRemote Controller Professional v1.1.0 on Synology DS212+. Raspberry Pi 512 Mb, Razberry software version 2.0.1-rc10. Sunshade Brustor B126
Though this instruction was originally developed for use with the RaZ-OR module, it is also applicable to OpenRemote installations on Raspberry Pi that do not use the RaZberry Z-wave module. In those cases the Shell execution protocol can directly call the GPIO shell script described below (not tested).
A number of shades and window opener suppliers do use the Somfy RF protocol for control. This is a closed safe protocol, and hence impossible (or hard) to interface with home automation software. Somfy offers two solutions, a) a Z-Wave bridge, and b) the Somfy 1810493 Dry Contact Interface, which essentially is a boxed version of their Telis remote control where the buttons are replaced by four control wires, that can be connected to relays.
For this second solution I designed the interface shown on the right, which utilises some GPIO pins that are not occupied by the RaZberry Z-Wave module. The GPIO numbers in the schema refer to the physical pins on the GPIO connector. If you do use RaZberry there are 7 pins that you can use for additional control.
note: click on the images to get a larger picture
You can use the Somfy Dry Contact box, but you can also buy a second Somfy/Telis handheld remote control module as I found it on the Micasaverde Vera forum, and solder wires to the buttons yourself. You have to be careful with that. Please note that the buttons on the image here on the right are turned 90 degrees to the left in comparison to the micasaverde image. Use an Ohm meter (do remove battery from Somfy!) to determine that the green wire pin is directly connected to the corresponding pins on the other two buttons.
There ar three pieces of software (wiringPi (from Gordon Henderson), shell script, RaZ-OR function) to be installed, from which the last is optional for use by people that do have the RaZberry plugged in.
The GPIO pins can be controlled directly from the command prompt. For security reasons that function does require access as root. That is not always convenient. Therefore the WiringPi module should be installed(following Plan B) on the Raspberry. It not only deals with the "root" problem, but it also makes interfacing easier.
pi@raspberrypi ~/wiringPi-d42e831 $ gpio readall
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5V | | |
| 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 1 | ALT0 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT0 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 0 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 0 | IN | CE1 | 11 | 7 |
| 28 | 17 | GPIO.17 | IN | 0 | 51 || 52 | 0 | IN | GPIO.18 | 18 | 29 |
| 30 | 19 | GPIO.19 | IN | 0 | 53 || 54 | 0 | IN | GPIO.20 | 20 | 31 |
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
For this example we use "soft" pin numbers 12,13,14 in the first column named wPi. Those correspond to the physical pin numbers 19,21,23 as you can see in the above table, which was made using the gpio readall command. Check this for your Pi board.
If you run OpenRemote on the Raspberry Pi, the sunshades can be controlled via the OpenRemote Shell execution protocol with the following script:
/usr/local/bin/gpio mode $PIN out
/usr/local/bin/gpio write $PIN 1
/usr/local/bin/gpio write $PIN 0
If you do not run OpenRemote on the Raspberry, you can control the shades using this script via the RaZ-OR module (see below)
For the further description it is assumed the file is called GPIO.sh. It is called with a single numerical parameter that is interpreted as follows if you use the above wiring diagram and the wiringPi module:
up : 14
down : 12
stop : 13
The script makes the GPIO temporarily go high, which makes the Somfy remote button close for a short while.
In this script the wiringPi PIN numbers are used. See more detail on those pin assignments here.
Using with RaZ-OR
If you installed RaZberry on your Pi, it is possible to control these shades via an extra function in the RaZ-OR http interface
where the possible actions are: up, down, stop
- The GPIO.sh script should be saved on the Raspberry in directory /opt/z-way-server/automation/storage, because that directory survives software updates
Finally make the GPIO.sh shell script executable:
system("/opt/z-way-server/automation/storage/GPIO.sh " + WPi);
The function does return the requested action as a "soft" status information.
To control the screen you need to make the three commands for upward, downward, and stop. Click on the image at the right to get a full view on the specification.
The Somfy / Telis remote has the option to define the "stop button" also into a move to a preset position. With the control buttons move the screen to that position and stop it. Wait a while, and press the stop button once more for 5 seconds. From now on, while the screen is moving a short push on the stop button will make it stop. If the screen is stopped, a push on the stop button will make it move to your preferred position.
There are a number of factors like windspeed, rain, inside/outside temperatures, time, that determine whether it is desirable to raise/lower sunshades or open/close windows.
The Brustor sunshades in this test are rated for usage up to Beaufort 5-6. The end of the windforce 5 range is about 38 km/h. The following OpenRemote rule lets the screen go up at higher wind gust levels.
global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
rule "Sunshades Up" when
CustomState( source == "SunScreenDocked", value=="false")
(CustomState( source == "isItRaining", value=="true") or
CustomState( source=="isNight_sensor", value=="true") or
Event( source == "WindGust", value > 38 )
execute.command( "SunScreenUP" );
The WindGust sensor data is derived from XML data of a nearby wheather station. It is of course safer to have a wind meter of your own. The document OpenRemote 2.0 How To - Use XML Data Sources will help you to get WindGust data for your location.
The rule is extended with a second "OR" clause that instructs the screens to be raised at night time. The images on the right specify the Command and the Sensor (of type:Custom) used in this example. For further detail see the OpenRemote 2.0 How To - DateTime Protocol page. Again click on the images for a bigger picture. In the fields for the command, you must fill in the lattitude and longitude of your location. If you leave the time zone blank, the protocol takes the default zone set in your operating system.
Attention: Make sure you did use the correct spelling for the name of the sensor. Designer does not check that for you!
The Rule has a rain sensor as the third clause. The Rainsensor is described here.
Finally a fourth sensor SunScreenDocked has been defined. If the sun screen is in its docking position there is no need to instruct it to move to that position. The fourth parameter prevents such commands. Consequently it improves the lifetime of the remote controller battery. This sunshade position sensor is also described in the document about the rain sensor
using Z-Way Automation Engine
Alternatively automation can be done with Z-Way automation modules. Configuration is done with a still (version 2.01) rudimentary graphical user interface. For many user that is easier than the Drools approach.
For the day/night sensor the Daylight module must be installed. That means just copying some files to the Raspberry. The windgust sensor needs installation of module Wunderground Weather Services. The LogicalRule module comes with the standard Z-Way distribution.
Somfy box specification
Opto coupler CNY 744 used in the add-on electronics (dutch site)
Mounting board for opto coupler and resistors (dutch site)
Discussion on the usage of this module please in this forum space