Coder Social home page Coder Social logo

nickduino / pi-somfy Goto Github PK

View Code? Open in Web Editor NEW
426.0 38.0 105.0 1.64 MB

A script to open and close your Somfy (and SIMU) blinds with a Raspberry Pi and an RF emitter.

License: Other

Python 42.15% CSS 9.15% HTML 15.84% JavaScript 32.72% Shell 0.14%

pi-somfy's Introduction

Pi-Somfy

1 Overview

This project allows to operate multiple Somfy shutters using the RTS protocol from a Raspberry Pi with cheap hardware costing less than $2. It comes with a command line interface, a web interface and an Amazon Alexa interface.

2 Hardware

This project has been developed and tested with a Raspberry Pi B+ and a Raspberry Pi 3 as the base platforms. Since the serial port and network are the only external ports used, the program could be used on other platforms with minor modifications and testing.

Wi-Fi connectivity and Ethernet cable should both work. Note that the hardware has to be reasonably close (i.e. in the same house or in the same aisle of your mansion: just like a physical remote) to the shutters you operate, as the signal strength will otherwise not be sufficient.

As of now, you have to build your own hardware. Here are the steps to do so.

  1. You need the RF Transmitter. If you wish to order it from eBay, this link maybe helpful:
    Order.
    Note that desoldering a 3 pin component isn't trivial, so ordering more than one may be a good idea in case of a screw up.
  2. You need an oscillator for a 433.42 MHz frequency. The above RF transmitter comes with a common 433.93 MHz one, which will not work with your Somfy shutter. If you wish to order it from eBay, this link maybe helpful:
    Order
  3. You will need cables to connect the transmitter to the Raspberry Pi. Any cable will do obviously, but I found these quite helpful.
    Order
  4. OPTIONAL: If you intend to place your Raspberry Pi further than about 10 ft from your receiver (aka your shutter or awning), you may need an antenna. Literally any 17 cm solid core copper wire will do the job. But if you prefer to order a fancy full one, this one will come handy
    Order

Once you have all the hardware handy, it's now time to swap the oscillator, which requires a bit of soldering. Reason for this is that the emitter you bought uses a common 433.93 MHz frequency, Somfy however requires a 433.42 MHz frequency. Take the following steps to exchange the oscillator

  1. Identify the oscillator. It looks like this (marked with a red circle):
    Front view.
    Turn the RF Transmitter around. You will see that the oscillator is soldered in on 3 points
    Back View
  2. While pulling the oscillator from the front, heat up the 3 soldering point on the back with the soldering iron until the oscillator is detached from the board
  3. Clean up the remaining solder mess on both desoldering braid or a desoldering pump
  4. Now put in the new oscillator (make sure all 3 pins connect through the print) and solder it in again
  5. Solder an antenna to the ANT pad. The ideal is a 17 cm solid core wire but almost anything will do the job. I used this antenna from ebay (Order) as I like the outlook. If your Pi is less than 10 ft from the receiver, it may work without antenna.

And you are done on the mods!

Now the last step is to connect your adjusted RF transmitter to your Raspberry Pi. Use the following diagram to help you connect it

Diagram

Note that I used GPIO 4 but you can change the value of TXGPIO to whatever you want if you choose a different way to connect your RF emitter. This is a configuration parameter in operateShutters.conf.

OK. now this all should look like this. Note that some of the pictures are a bit confusing with regards to which GPIO a cable connects to. It's easier to see on the above diagram. But if you struggle, maybe the Wiring Diagram helps.

Full Picture
Pi Connection
RF Transmitter Connection

3 Software

If you are new to using a Raspberry Pi and Linux please refer to other sources for coming up to speed with the environment. Having a base knowledge will go a long way. This site is a great place to start if you are new to these topics.

If you are not familiar with remote login commands for Linux/Unix, two useful commands if you are not using a GUI on your raspberry pi are "ssh" and "scp". These commands allow you to run your Pi without a monitor or user interface. These programs allow you to remotely login to your Pi and remotely transfer files to your Pi. This page describes both programs. You can also do a web search on these programs to find other resources on their use. In short you need to have at minimum a basic understanding of using a command line, preferably some experience with Linux and the ability to transfer files to a Raspberry Pi and execute them.

The Raspberry Pi organization has documentation on installing an operating system on your Raspberry Pi. It is located here.

One the Pi has its basic setup (an operating system and an internet connection) working, ssh into your Raspberry Pi and you should find that you are in the directory /home/pi. Note: if you prefer not to use a headless system, you can also open a terminal windows directly on the Pi.

The next step is to download the Pi-Somfy project files to your Raspberry Pi. The easiest way to do this is to use the "git" program. Most Raspberry Pi distributions include the git program (except Debian Lite).

Whether or not it is already installed, it's good practice to type the following:

sudo apt-get update
sudo apt-get install git

(If git isn't installed, it will install it; if it was previously, it will update it)

Once git is installed on your system, make sure you are in the /home/pi directory, then type:

git clone https://github.com/Nickduino/Pi-Somfy.git

The above command will make a directory in /home/pi named Pi-Somfy and put the project files in this directory.

Next, we need to install Python Libraries. Before doing so, you have to decide whether you want to run Pi-Somfy in Python 2 or Python 3. The library supports both, but Python 3 is suggested. So, to proceed in Python 3, you need to ensure pip3 is installed:

If the program 'pip3' is not installed on your system, type:

sudo apt-get update
sudo apt-get install python3-pip

If you decided to use Python 2, the last command will read instead:

sudo apt-get install python-pip

Next, we need to install the PIGPIO libraries, to do so, type:

sudo apt-get install pigpio

Next install the required Python Libraries:

sudo pip3 install -r requirements.txt

If you decided to use Python 2, the last command will read instead:

sudo pip install -r requirements.txt

Next, let's test if it all works. Start <operateShutters.py> by typing:

sudo python3 /home/pi/Pi-Somfy/operateShutters.py

You should see the help text explaining the Command Line Interface

4 Usage

Note that the config file won't exists the first time you run the application. In that case, a new config file will be created based on the name you specified (e.g. /home/pi/Pi-Somfy/operateShutters.conf). Once it has been created, you can modify it to change your need (SSL or not, which port is used, etc.), it will not be erased with an update. If you messed up something, just delete it and relaunch operateShutters.py, a new vanilla copy will be generated.

You have 6 ways to operate. The recommended operation mode is mode 5. But the other 5 modes are explained here for completeness:

  1. Command line Interface
    You can use either of the following commands to operate a shutter called

Arguments:

shutterName                             Name of the shutter
-h, --help                              Show this help message and exit
-c CONFIGFILE, --config CONFIGFILE      Name of the config File (incl full Path)
-up, -u                                 Raise the shutter
-down, -d                               lower the shutter
-stop, -s                               Stop the shutter
-program, -p                            Send a program signal
-press BTN [BTN...]                     Simulate a chord press of a the specified remote buttons
                                        ('up', 'down', 'stop'/'my', and 'program')
-long                                   When used with the -press option, simulates a long press
-demo                                   lower the shutter, stop after 7 second then raise the shutter
-duskdawn DUSKDAWN DUSKDAWN, -dd DUSKDAWN DUSKDAWN
                                        Automatically lower the shutter at sunset and rise the
                                        shutter at sunrise, provide the evening delay and
                                        morning delay in minutes each
-auto, -a                               Run schedule based on config. Also will start up the web-server 
                                        which can be used to setup the schedule.
-echo, -e                               Enable Amazon Alexa (Echo) integration
-mqtt, -m                               Enable MQTT integration

Examples: All three command the shutter named corridor. The first one will raise it. The second one will lower it. The third one will lower the shutter at sunset and raise it again 60 minutes after sunrise.

sudo /home/pi/Pi-Somfy/operateShutters.py corridor -c /home/pi/Pi-Somfy/operateShutters.conf -u
sudo /home/pi/Pi-Somfy/operateShutters.py corridor -c /home/pi/Pi-Somfy/operateShutters.conf -d
sudo /home/pi/Pi-Somfy/operateShutters.py corridor -c /home/pi/Pi-Somfy/operateShutters.conf -dd 0 60
  1. Manually start Web interface only
    You can start the web-interface by typing:
    Once started, you can access the web interface at http://IPaddressOfYouPi:80. From there you can further modify your settings.
sudo python3 /home/pi/Pi-Somfy/operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a 
  1. Manually start Web interface and Alexa interface
    You can start the web-interface by typing:
sudo python3 /home/pi/Pi-Somfy/operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a -e
  1. Manually start Web interface and MQTT integration (for Home Assistant)
    You can start the web-interface by typing:
sudo python3 /home/pi/Pi-Somfy/operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a -m
  1. Finally, the recommended way to operate it is using a systemd service on boot time. You can do so by typing:
sudo bash /home/pi/Pi-Somfy/installService.sh

The service will be installed as a system service right after establishing network connectivity. If you want to stop the service simply type:

sudo systemctl stop shutters.service

If you want to start the service simply type:

sudo systemctl start shutters.service

If you want to restart the service simply type:

sudo systemctl restart shutters.service

Note, currently the service expects python3 for starting up. If you went the python 2.7 path change the following line in shutters.service file before your installation

ExecStart=sudo /usr/bin/python3 /home/pi/Pi-Somfy/operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a -e -m

to

ExecStart=sudo /usr/bin/python2.7 /home/pi/Pi-Somfy/operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a -e -m
  1. Finally, the recommended way to operate it is using a systemd service on boot time. You can do so by typing:
sudo crontab –e 

Note, that "crontab -e" will just open a console-based text editor that you can edit the crontab script. The first time you run "crontab -e" you will be prompted to choose the editor. I recommend nano. From the crontab window, add the following to the bottom of the crontab script

@reboot sleep 60;python3 /home/pi/Pi-Somfy/operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a -e -m
0 * * * * python3 /home/pi/Pi-Somfy/operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a -e -m

And save the crontab schedule. (if using nano type press ctrl-o to save the file, ctrl-x to exit nano). Now, every time your system is booted operateShutters will start.

The program is not known to crash. Hence restarting it every hour is not really required. But it does not hurt either. So up to you if you wish to use both of the above lines or just the first one. In any case, you will need to restart your Raspberry Pi once you have completed step 4. To do so, type "sudo reboot".

To stop the program from running in the background, type:

sudo pkill –f operateShutters.py

5 Web GUI

Using your web-browser, navigate to: http://IPaddressOfYouPi:80

First time you use the Web GUI, it's important that you follow these 3 steps:

  1. Set up your location. This is required to correctly determine the time of sunrise and sunset. To do so, navigate to the top menu item "Settings". Use the map to pinpoint your location. You can also use the search functionality on the left-hand side (magnifier icon) and type your address. Press "Save"

  2. You will need to set up your shutters and program your remote control. To do so, select the second menu item "Add/Remove Shutters".
    Screenshot
    Click the "Add" button, select the name for your shutter (this is also the name that the Amazon Alexa app will use later) and click on the "save" icon. Then follow the on-screen instructions for programming your shutter. For installing shutters from the factory default configuration, use the Configure button.

  3. Next, make sure your shutters work. The easiest way to verify is to use the "Manual Operations" menu.
    Screenshot
    You can rise and lower your shutters by clicking on the relevant icons.

  4. Finally, it's time to program your shutters schedule. To do so, use the "Scheduled Operations" menu.
    Screenshot

6 Alexa Integration

Before you can use the Amazon Alexa integration, you need to make sure you set up all shutters, by using "Add/Remove Shutters" in the Web GUI. Amazon Alexa does not automatically discover new or amended shutters you have added.

So once all your shutters are set up and testing on the Web GUI, go to your Echo speaker and ask Alexa to discover your device. Say, "Discover my devices," or select Add Device in the Devices section of the Alexa app.

Once Alexa has discovered your shutters, you can use the Alexa app to complete the setup.

To lower your shutter via the Echo speaker, say "Alexa, turn on {SHUTTERNAME}". And to rise the shutter again, say “Alexa, turn off {SHUTTERNAME}".

If you prefer to state the likes of "Alexa, OPEN the shutter" or "Alexa, CLOSE the shutter" (rather than using the words ON or OFF), you can set up a Routine with Alexa.

7 MQTT Integration (e.g. for Home Assistant)

While the MQTT integration was written specifically for Home Assistant, nothing is stopping the use of this integration for other purpose. But more on this later

First, to use this integration, make sure you configure your operateShutters.conf with the right parameters. Look out for the following lines:

MQTT_Server = 192.168.1.x
MQTT_Port = 1883
MQTT_User = xxxxxxx
MQTT_Password = xxxxxxx

and make sure they match the setup of you MQTT Broker. If you are using Home Assistant, you can conveniently use the "Mosquitto broker" add-on inside Home Assistant. For more information refer to the relevant Documentation

If you choose not to use the Home Assistant add-in, you can download the Mosquitto Broker and refer to the Broker configuration

Second start operateShutter.py with the "-m" option. This should look similar to this:

operateShutters.py -c /home/pi/Pi-Somfy/operateShutters.conf -a -m

And that's it, you are all set.

So if you use Home Assistant, you have 2 options:

a.) you use Home Assistant's MQTT Discovery functionality.

To do so, add the following line to operateShutters.conf

EnableDiscovery = true

and also add the following line to your configuration.yaml in Home Assistant:

mqtt:
  discovery: true

Note that both Pi-Somfy & Home Assistant need to be restarted before this will work. Home Assistant will henceforth auto discover any new shutters you add

b.) Don't use Home Assistants MQTT Discovery functionality.

If so, no further changes are required to operateShutters.conf. However you will have to add the following lines to configuration.yaml in Home Assistant for ever shutter you have (replace 0x2670xx with the shutters actual RTS_Address, which you can get from your operateShutters.conf file):

cover:
   - platform: mqtt
     name: '{SHUTTERNAME}'
     payload_open: 100
     payload_close: 0
     command_topic: 'somfy/0x2670xx/level/cmd'
     position_topic: 'somfy/0x2670xx/level/set_state'
     set_position_topic: 'somfy/0x2670xx/level/cmd'
     state_open: 100
     state_closed: 0

And that's it!

Finally, in case of any difficulties with this integration, 2 more useful commands:

a.) See messages on the MQTT Broker

If you want to see what messages are passed on the MQTT Broker, you can use the following to listen to all messages (assuming you set up mosquitto with a username and password):

mosquitto_sub -h 192.168.x.x -p 1883 -u [username]-P [password] -t '#' -v

b.) Send messages to the MQTT Broker, for Pi-Somfy to pick up

If you want to post a message to the MQTT Broker for your Pi-Somfy to pick up, you can use following to send messages (assuming you set up mosquitto with a username and password):

mosquitto_pub -h 192.168.x.x -p 1883 -u [username]-P [password] -t 'somfy/0x2670xx/level/cmd' -m '0'
mosquitto_pub -h 192.168.x.x -p 1883 -u [username]-P [password] -t 'somfy/0x2670xx/level/cmd' -m '100'

Those 2 command will lower and rise your shutters.

8 Credits

This Library was ported from Arduino sketch onto the Pi by @Nickduino to open and close his blinds automatically.

If you want to learn more about the Somfy RTS protocol, check out Pushtack.

9 License

Image of the license

Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)

pi-somfy's People

Contributors

ajmawer avatar dennis-q avatar firewiremb avatar fraboch avatar gkfr avatar huanvu avatar incub77 avatar koddsson avatar lepirlouit avatar mahallon avatar markgodwin avatar metbosch avatar michaelb2018 avatar nickduino avatar nungesser avatar rbswift avatar rosenpin avatar the-lazy-fox avatar timhannemann avatar tomschalld avatar vapouryh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pi-somfy's Issues

Running Pi-Somfy from another Python script linked to heating control

With help from others on this project I have my blinds controlled by Pi-Somfy and Alexa. I would now like to link this to information from my central heating program (tado) so that when everyone is out of the house the blinds will close (perhaps also subject to other conditions, but that's for another time). I have been able to access data from tado and download and save it in a text file on my Raspberry Pi, and create a Python script that will identify if the string that indicates whether the occupants are in (HOME or AWAY). I now want to use this IF statement to trigger Pi-Somfy to close my two blind, but this is where I am struggling, mainly because I am a virtual Python beginner.

The script I have below (HOME would be replaced with AWAY in the final version) checks if the word HOME is in the text file and then if so prints the text and confirms "True":

#!/usr/bin/python3
w = ("HOME") # For Python 3: use input() instead
with open('/home/pi/libtado/tadostate.txt') as f:
found = False
for line in f:
if w in line: # Key line: check if w is in the line.
print(line)
found = True
print (found)
if not found:
print('The word cannot be found!')

I have used various web resources to help me figure out the syntax I need to run the Pi-Somfy instruction to close a blind (replacing the three lines currently within the IF statement), but all attempts have not worked. I'm think that in part this is due to incorrect file structure and/or paths (relevant part of directory tree below)

  ├── myscheduler.pyc
│   ├── mywebserver.py
│   ├── mywebserver.pyc
│   ├── operateShutters.conf
│   ├── operateShutters.py
│   ├── pycache
│   │   ├── fauxmo.cpython-37.pyc
│   │   ├── myalexa.cpython-37.pyc
│   │   ├── myconfig.cpython-37.pyc
│   │   ├── mylog.cpython-37.pyc
│   │   ├── mymqtt.cpython-37.pyc
│   │   ├── myscheduler.cpython-37.pyc
│   │   └── mywebserver.cpython-37.pyc
│   └── README.md
├── Public
├── tado
├── tadoquery
│   ├── init.py
│   └── tadoquery4.py
├── tadoquery2.py
├── tadoquery3.py
├── tadoquery.py
├── Templates
└── Videos

Currently I have the above script (tadoquery4.py) in a home/pi/tadoquery directory together with a blanks init.py file and have used the line 'from .import operateShutters' really just to see if would recognise the operateShutters.py, but this returns 'cannot import name 'operateShutters' from 'main' (/home/pi/tadoquery/tadoquery4.py)'. I have previously had the tadoquery4.py file in the home/pi directory (ie the same directory as operateShutters.py) but that also did not work. Of course, import may be competely the wrong method for what I am trying to do!

So I am unclear how to run the operateShutters.py script from within my tadoquery4.py script and how to specify the parameters (blind name and open or close).

I would be very grateful for some help on this.

Stop doesn't work when blind is going up

Bit of an oddity. If I command the blind to go down, it does. If I try to stop it mid way, it stops fine. If I command the blind to go up, it does. If I try to stop it mid-way, nothing happens. If I use the remote to stop it after sending the up command via Pi-Somfy, it stops fine.

Within the log file for Pi-Somfy, the same button is showing as being pressed for stop whether the blind is going up or down and the rolling code sequence is correct.

Any suggestions?

Thanks

Chris

Using MQTT to control

Hi guys - this is awesome Great work. Im able to control, via the WebUI my Somfy shutter without changing the crystal on the 433 transmitter..although i have ordered some!

Anyway , my issue is that i cannot control my blind via MQTT.
As mentioned i can control it fine using the WebUI, - UP/DOWN/STOP all work very responsively..now i want to integrate it into OpenHAB using MQTT.

Pi-Somfy is communicating with my Mosquito. Its published:
somfy/0x279621/level/set_state
with values of 0 and 100

I couldnt see in the README any doco on how to use MQTT, but did find the issue comment here:
#50 (comment)
showing how to use it...

So i tried publishing :
somfy/0x279621/level/cmd
setting values 0 and 100
i also tried STOP, UP,up,DOWN,down

There is no action from my blind and nothing logged.

What am i doing wrong?

Help choosing supported hardware.

Hello, the technical specifications of my Somfy controller are the following:

Radio frecuency: 868.95 MHZ, io-homecontrol
Frecuency band of trasmission: 868.700 MHz - 869.200MHz
_

I been looking for a compatible crystal but I can't find anything on these frecuency.
Would the model that you are using works for me?
Where could I find something compatible?

Thank you in advance :)

Can you help with a supported transmitter ?

I really like this project, but I cant get the pi to communicate with the blinds, I am new to this kind of stuff, but i am pretty sure that my problem is the transmitter.

I have bought this one:
http://www.ebay.com/itm/5x-433MHz-RF-Transmitter-Receiver-Kit-Module-Arduino-ARM-WL-MCU-Raspberry-PI-/162102463039?hash=item25be0f4a3f:g:xikAAOSwnNBXXm2E

and replaced the Crystal with this one:
http://www.ebay.com/itm/331637441887

but they don't respond at all

I have a working Telis 6 and Telis 5 remote for the system today

Could it be possible for me to buy a working transmitter module for the raspberry pi from you ?

Alexa integration: only up/down is possible

Hi guys,

I was wondering if you plan to enhance Alexa integration by adding the possibility to stop the blinds? At the moment I can only make them either completely opened or closed which is rather limited :-(
Thank a lot for your work! Great project!

Where can I buy the emitter ?

Hi,

Do you have any recommendation about which emitter buy ?

I looked on Aliexpress but I don't know what to buy.

Thanks

Make it work

Hello,

I'm trying the code provided but nothing seems happening.
Python is pretty new to me.
I tried to close my shaders with this code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import locale
import time
import datetime as dt
import ephem
import pigpio
import traceback

TXGPIO=4 # 433.42 MHz emitter on GPIO 4

#Button values
boutonHaut = 0x2
boutonStop = 0x1
boutonBas = 0x4

frame = bytearray(7)

homeLocation = ephem.Observer()
homeLocation.lat, homeLocation.lon = '42.764457', '5.066435' #PUT YOUR OWN COORDINATES HERE (check on Google Maps for instance)
locale.setlocale(locale.LC_TIME,'')


def envoi_commande(telco, bouton): #Sending a frame
   checksum = 0
   
   with open("somfy/" + telco + ".txt", 'r') as file:# the files are un a subfolder "somfy"
      data = file.readlines()

   teleco = int(data[0], 16)
   code = int(data[1])
   data[1] = str(code + 1)

   print hex(teleco)
   print code

   with open("somfy/" + telco + ".txt", 'w') as file:
      file.writelines(data)

   pi = pigpio.pi() # connect to Pi

   if not pi.connected:
      exit()

   pi.wave_add_new()
   pi.set_mode(TXGPIO, pigpio.OUTPUT)


   print "Remote  :      " + "0x%0.2X" % teleco
   print "Button  :      " + "0x%0.2X" % bouton
   print "Rolling code : " + str(code)
   print ""

   frame[0] = 0xA7;       # Encryption key. Doesn't matter much
   frame[1] = bouton << 4 # Which button did  you press? The 4 LSB will be the checksum
   frame[2] = code >> 8               # Rolling code (big endian)
   frame[3] = (code & 0xFF)           # Rolling code
   frame[4] = teleco >> 16            # Remote address
   frame[5] = ((teleco >>  8) & 0xFF) # Remote address
   frame[6] = (teleco & 0xFF)         # Remote address

   print "Frame  :    ",
   for octet in frame:
      print "0x%0.2X" % octet,
   print ""

   for i in range(0, 7):
      checksum = checksum ^ frame[i] ^ (frame[i] >> 4)

   checksum &= 0b1111; # We keep the last 4 bits only

   frame[1] |= checksum;

   print "With cks  : ",
   for octet in frame:
      print "0x%0.2X" % octet,
   print ""

   for i in range(1, 7):
      frame[i] ^= frame[i-1];

   print "Obfuscated :",
   for octet in frame:
      print "0x%0.2X" % octet,
   print ""

#This is where all the awesomeness is happening. You're telling the daemon what you wana send
   wf=[]
   wf.append(pigpio.pulse(1<<TXGPIO, 0, 9415))
   wf.append(pigpio.pulse(0, 1<<TXGPIO, 89565))
   for i in range(2):
      wf.append(pigpio.pulse(1<<TXGPIO, 0, 2560))
      wf.append(pigpio.pulse(0, 1<<TXGPIO, 2560))
   wf.append(pigpio.pulse(1<<TXGPIO, 0, 4550))
   wf.append(pigpio.pulse(0, 1<<TXGPIO,  640))

   for i in range (0, 56):
      if ((frame[i/8] >> (7 - (i%8))) & 1):
         wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))
         wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
      else:
         wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
         wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))

   wf.append(pigpio.pulse(0, 1<<TXGPIO, 30415))

   #2
   for i in range(7):
      wf.append(pigpio.pulse(1<<TXGPIO, 0, 2560))
      wf.append(pigpio.pulse(0, 1<<TXGPIO, 2560))
   wf.append(pigpio.pulse(1<<TXGPIO, 0, 4550))
   wf.append(pigpio.pulse(0, 1<<TXGPIO,  640))

   for i in range (0, 56):
      if ((frame[i/8] >> (7 - (i%8))) & 1):
         wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))
         wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
      else:
         wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
         wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))

   wf.append(pigpio.pulse(0, 1<<TXGPIO, 30415))

   #2
   for i in range(7):
      wf.append(pigpio.pulse(1<<TXGPIO, 0, 2560))
      wf.append(pigpio.pulse(0, 1<<TXGPIO, 2560))
   wf.append(pigpio.pulse(1<<TXGPIO, 0, 4550))
   wf.append(pigpio.pulse(0, 1<<TXGPIO,  640))

   for i in range (0, 56):
      if ((frame[i/8] >> (7 - (i%8))) & 1):
         wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))
         wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
      else:
         wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
         wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))

   wf.append(pigpio.pulse(0, 1<<TXGPIO, 30415))

   pi.wave_add_generic(wf)
   wid = pi.wave_create()
   pi.wave_send_once(wid)
   while pi.wave_tx_busy():
      pass
   pi.wave_delete(wid)

   pi.stop()
   

envoi_commande("salon", boutonBas)

sudo ./som.py

0x267043
124
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio at localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

sudo pigpiod
sudo ./som.py

0x267043
125
Remote  :      0x267043
Button  :      0x04
Rolling code : 125

Frame  :     0xA7 0x40 0x00 0x7D 0x26 0x70 0x43
With cks  :  0xA7 0x47 0x00 0x7D 0x26 0x70 0x43
Obfuscated : 0xA7 0xE0 0xE0 0x9D 0xBB 0xCB 0x88

But nothing happend.
Do I have to register the remote? Can you please provide some code examples?
Thanks!

Getting started

Hi,

I just found your repo and would be interested in some more details:

  1. How to set chambre.txt values?
  2. What kind of remote you are using, I have a "Somfy Smoove RTS" with three Buttons.
  3. What emitter you use, I have a cheap 433 MHz emitter from eBay.

Merci beaucoup in advance for your help,
Georg.

additions to great project

Finally got my pi-somfy to run (issue #13 took me a while to resolve.) So I upgraded the script to Python 3, added a command line interface to it so that it can easily operate via cron, then added a flask based web-site to it that allows to program & configure multiple shutters to operate at a reasonable complex schedule (instead of hard coding the schedule) and finally built an Amazon Alexa interface, so shutters react to voice commands. Some screen shots are attached for your reference.

So the question is if you want to take my code and check it in in the main repository (preferred, I can send it over if you want). Alternatively if you prefer I could fork the project too.


p1

p2

p3

p4

weather integration for awnings

I'm starting work on a weather module - integrates with Yahoo weather, and allowing user to register for closing the awning in case of rain/strong wind (wind speed configurable).
I will add this to work together with the CLI shcedule, but would need help to integrate it into the GUI.

Problem with Ephem dependency on Aarch64

Can't install Ephem on Aarch64 through pip. Exits with:

unable to execute 'aarch64-linux-gnu-gcc': No such file or directory
error: command 'aarch64-linux-gnu-gcc' failed with exit status 1

I am on Debian Buster. I installed "python-ephem" through apt instead, but the script says "No module name 'ephem'".

IndentationError in somfy.py

Hello,

thank you for your code example to show how one can control somfy blinds.

I just tried to register my raspberry as a new remote. But when I execute the somfy.py I get an IndentationError in the sending function.

It seems to me that the problem is in that area:


.
.
.
wf.append(pigpio.pulse(0, 1<<TXGPIO, 30415)) # interframe gap

  for j in range(1,repetition): # repeating frames
        for i in range(7): # hardware synchronization
              wf.append(pigpio.pulse(1<<TXGPIO, 0, 2560))
              wf.append(pigpio.pulse(0, 1<<TXGPIO, 2560))
        wf.append(pigpio.pulse(1<<TXGPIO, 0, 4550)) # software synchronization
        wf.append(pigpio.pulse(0, 1<<TXGPIO,  640))

        for i in range (0, 56): # manchester enconding of payload data
              if ((frame[i/8] >> (7 - (i%8))) & 1):
              wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))
              wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
              else:
              wf.append(pigpio.pulse(1<<TXGPIO, 0, 640))
              wf.append(pigpio.pulse(0, 1<<TXGPIO, 640))

        wf.append(pigpio.pulse(0, 1<<TXGPIO, 30415)) # interframe gap

pi.wave_add_generic(wf)
.
.
.

The number of blanks in front of the "for j in range(1,repetition)... could be the problem.

Could you please check the code and/or give me a hint how to use it in a correct way.

Thanks a lot!
Uwe

socket.error: [Errno 104] Connection reset by peer

Trying to use this library. The code seems to work fine is I call

def envoi_commande(telco, bouton, repetition):

with a repetition of 1. But as soon as I put repetition 2, I get the following error:

Traceback (most recent call last):
  File "./somfy.py", line 141, in <module>
    envoi_commande("chambre", buttonStop, 2)
  File "./somfy.py", line 132, in sendCommand
    pi.wave_add_generic(wf)
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 2120, in wave_add_generic
    self.sl, _PI_CMD_WVAG, 0, 0, len(pulses)*12, extents))
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1007, in _pigpio_command_ext
    dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN))
**socket.error: [Errno 104] Connection reset by peer**

Any ideas?

Manual commands when WebUI is running

Hello,

Is there a way to be able to use manual commands like
sudo /home/pi/Pi-Somfy/operateShutters.py livingRoom -c /home/pi/Pi-Somfy/operateShutters.conf -d
when the WebUi is running?
I would like to call it from other systems.
Or is there anyway to send cli instructions to the webinterface?

Best

How to reverse remote buttons

First of all, thank you for sharing your awesome work on this project!!!

This is exactly what I needed and saved me the pain of trying to figure it out. I have a Sunsetter Awning that has a Somfy remote control built in. I also run Home Assistant on a Pi (Hassbian) and got this up and running in no time at all. Great Read Me.

I have one issue with my Awning. I reverses the remote button function from "normal". Even though it's possible to reverse remote button operation programmatically between the remote and receiver, the Sunsetter Awning will not function properly with them reversed, it's strictly prohibited for some reason. So my Home Assistant UI shows the Awning OPEN all the time unless it's in the full open position, then it registers as CLOSED.

I would like to reverse this behavior in this code. I think I might be able to configure some Cover Template in Home Assistant to revers it, but I'm not positive. I would rather mod this code to reverse the behavior at the source, rather than programming around the issue in Home Assistant. Maybe this could be a new option in the conf file? Could you point me to all the places I should touch to mod the code?

Thanks!

Echo spot: ok; Echo 2: not ok

I have two Amazon devices : one echo spot (controlled from an Android device) and an Amazon echo 2 (paired with an iPhone and an iPad). The devices are configured on two different Amazon accounts but are connected through the same WiFi network.

The echo spot does find the fauxmo devices and controls them alright, its bigger brother doesn't

Web Gui an Comandline together

Hi,
how can I use Web Gui an Comandline together?
If Webgui is started, comands from comandline didn´t work.
Kind regards

Improving the GUI

I've made a 3D render of a streamlined remote:
image

The objective is to replace this:
image

Any one has some knowledge of web designing and wants to help?
Possibly responsive design as well but not necessarily

Sunset-sunrise as argument

The way I see it, the day starts in the morning and end in the evening, I'd prefer it if the first argument passed was to open he blinds (accepting a negative value if you want to open them before sunrise) the the second to close them.

image

Moreover, we may want to use the astronomical data at night but not in the morning (open at 7 every day, close right after sunset) so I think we should seperate that in three arguments:

  • -t time
  • -m sunrise
  • -n sunset

HomeKit support

Hi all,

This is an amazing app just wondered is there consideration for HomeKit development?

Reading normal Somfy Remotes

Hi guys,

I haven't tested yet this project, but I was using a simple one which could open and close my Somfy blinds. So, your project seems to better, congratulations!

I know that the somfy motors won't provide a feedback to allow us to know the blinds position, like 30% down. We can only request down, up and stop, but no feedback.

Using a timer, we can predict where the blinds are as the raspberry pi will send down/up and the code will know how long it takes to roll over. Easy I guess.

However, if someone has used the traditional remote control, the raspberry will be out of sync and it is not going to work.

I am planning to develop an extension of your code to use the receiver 433Mhz to receive the original somfy remotes input. So, if someone uses the remote to put the blinds down/up, the raspberry pi will be able to receive this information and track the blinds position. Have you guys tried to use the receiver that comes together with the transmitter?

I would like to have this feature as I will put the blinds down based on the sunlight coming from the window to ensure that I won't damage the furniture and at the same time keep a bright room .

What so you guys think?

I will also put this to work with HA, so everything will be manageable and automatized.

Thanks guys

Latest master (5b80b56) is broken

pi@raspberrypi ~/Pi-Somfy $ sudo python /home/pi/Pi-Somfy/operateShutters.py -a


This program requires the modules located from the same github repository that are not present.

Error: Non-ASCII character '\xc2' in file /home/pi/Pi-Somfy/myalexa.py on line 74, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details (myalexa.py, line 74)

The offending line is:

            self.LogInfo ("Remote address in dec: " + str(int(shutterId,16)) + ", WeMo port will be n°" + str(portId))

Should be easily fixable.

How to test if the emitter works?

I setup the software properly on my PI. Can't get my Awning (Markiluxx using Somfy) to pair though, even after putting it in programming mode. I have no clue whether or not the emitter works in the first place. Would appreciate any pointers.

(NOT and issue) Not sure how to contact you.

I was wondering how/if it is possible to add IFTTT functionality to this. If possible I'm looking to get some small door sensors that will go on the blinds and will integrate with stringify.

Thanks.

Update README with Getting Started

Great project! I want to use that as a starting point for my Somfy blinds as well.

Can you add a "Getting Started" section to the README, that explains for beginners how to get this basically working? I already have a transmitter and the custom crystals, and need to figure out the following:

  • Connect transmitter with replaced crystal to Raspberry Pi
  • Register transmitter as additional Remote for each blind
  • Actually control the different blinds, to see if everything is working

What I want to add then is:

  • Alexa integration

Web GUI doesn’t work on iOS

On my iPhone running safari web browser I navigate to the web url and am unable to click the manual operation tab, so I can’t see the up/stop/down buttons. The only thing I see is +Add New for a new scheduled event. Clicking on settings or add/remove shutter doesn’t work either. Everything else works great on my laptop and with Alexa, just unable to use my iPhone browser. I also tried chrome on the iPhone with same results. Suggestions?

MQTT /Home Assistant integration

I have set up Home Assistant with hass,io and added in MQTT. I have gone through all the instructions in Pi-Somfy to set up integration with MQTT. I'm at the stage where I can send a an mosquitto command to open a blind, that shows up if I monitor the messages. In Home Assistant the MQTT log shows a connection and then a disconnection:

1580244209: New connection from 172.30.32.1 on port 1883.
1580244209: New client connected from 172.30.32.1 as mosqpub|3834-raspberryp (p2, c1, k60, u'neil').
1580244209: Client mosqpub|3834-raspberryp disconnected.

However, the blinds don't respond, and there are no Somfy devices showing in Home Assistant. What should I expect to see in HA, and why no response from the blinds. Is it normal for the client to connect to MQTT and then disconnect immediately (ie just passing a message and disconnecting) or should the connection to permanent?

Thanks

Multiple remotes

Hi ! First of all, thank you very much for your work =)
I'd like to know if it's possible to keep the original remote. I mean, is it possible to open/close the blind with a virtual remote AND the "real remote" ?

Thanks !

Stop button press sends invalid level to MQTT

If I send a Stop button command to an already stopped blind I get what looks like an invalid level state message via MQTT. For example:

# mosquitto_sub -h localhost -t 'somfy/#' -v
somfy/0x279623/level/set_state 1204
somfy/0x279623/level/set_state 1041

I believe this should be 0-100

stacktrace on stop command

hi!

when i issue a stop command like
/home/pi/Pi-Somfy/operateShutters.py b2 -c /home/pi/Pi-Somfy/operateShutters.conf -s

i get the following stacktrace:

Traceback (most recent call last):
  File "/home/pi/Pi-Somfy/operateShutters.py", line 533, in <module>
    MyShutter = operateShutters(args = args)
  File "/home/pi/Pi-Somfy/operateShutters.py", line 368, in __init__
    self.ProcessCommand(args);
  File "/home/pi/Pi-Somfy/operateShutters.py", line 427, in ProcessCommand
    self.shutter.stop(self.config.ShuttersByName[args.shutterName])
  File "/home/pi/Pi-Somfy/operateShutters.py", line 155, in stop
    secondsSinceLastCommand = int(round(time.monotonic() - state.lastCommandTime))
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

the command still gets executed, though.

great project, btw. - thanks a lot for this!
best regards

What to do if alexa doesn't discover shutters?

Hi, great project!
I tried to start the server multiple times with -a-e switches, but alexa doesn't seem to discover any shutter.
The webui works and operates well on my defined shutters. Any advice here?

Timing and Frame repetition

Hello,

I used your code and succeeded in registering and controlling my Somfy shades using an Aurel Transceiver (433.42MHz). I also checked the PushStack blog with details about the RTS protocol your code is based on. I noticed that you use a different timing (640us per half bit instead of 604us documented in the PushStack blog). The PushStack blog mentions that the timing is not critical but I wonder if there a special reason for that?
I have a few open questions, maybe you can help me:

  • Is it necessary to repeat the frame 3 times as you do in your code?
  • Do you have an idea how to implement a long press of the prog button to register/de-register a remote? Is this established by often repetition of the frame?
  • My original Somfy remote has a separate wheel (additionally to the 3+1 buttons) to adjust the angle of the blinds. My Somfy Telis 6 Chronis remote does not have this wheel but the angle can be adjusted by long pressing up or down. Do you have an idea how to implement this function? Is this a separate control code or is this established through frame repetition?

Thank you in advance!

Conflict with official remote?

Hi,
I was using the new webinterface and planification for weeks and now it just stopped working.
I touched nothing but I recently used the official remote manual.
Is there any kind of conflict possible?

Should I remove and reprogram it now to have it back working?

Thanks

Choosing a licence

Michael, now that we are several (2>>1 :-D) working on the project, I believe we should choose a licence.

I don't have much of a personal preference, although I quite like the idea of allowing only non-commercial uses of the project.

About changing the saw oscillator

Hi !

I'm pulling another issue because I don't know how to change the saw oscillator and i cant' find anything on google. Do i have to desolder the actual oscillator and solder the new one or is there something else I don't get ? :)

Anyway thanks for everything !

pigpiod constant cpu usage

Hi, is there any way to reduce the constant cpu usage by pigpiod? This process uses about 7-10% cpu on my pi constantly even when pi-somfy is not being used. Cheers

Rolling code glitch

I don't know what happened:

image

The error:

image

I deleted line 108 and added 4 to the rolling code of line 98 for good measure. All seems well (the shutter works)

persist shutter position

It might be nice to persist each shutter position perhaps in a [ShutterPositions] section of the .conf file similar to how the rolling codes are persisted. This would make the software more reliable for users who restart their raspberry Pi regularly or occasionally. The position could also then be represented in the Web UI.

This is a bit beyond my capabilities unfortunately but perhaps if I get more into python I will revisit this myself if nobody else beats me to it.

additional antenna

Hi at no. 5
Solder an antenna to the ANT pad :
the link points to a 1 wire antenna ... do i need to bend it and solder both ends as in the image or it's ok one end only?
a bit confused ..
by the way thanks for the repo & instructions.
Flavius

sendCommand repetition for Li-ion battery motor support

Hi,

Great project!

Is there a reason the SendRepeat parameter in the conf file is not used by operateShutters.py? It looks like repetition is hardcoded at 2 (or 1 for programming).

I've found the only way to get Li-ion battery powered motors to reliably wake up and process a command is to repeat the command 5 times. The genuine somfy remote also seems a bit less responsive with battery motors so I guess this is just a 'feature' :)

Even better, would it be possible to add a repetition parameter for each motor? Wired RTS motors don't seem to need repetition as much as battery powered motors.

Cheers,
Richard

Open-source license?

Hi @Nickduino, thanks so much for making this code public! Just wanted to ask if you'd be willing to throw some sort of a open-source license on the code—I'm hoping to publish a modification that integrates with Amazon Alexa, and I don't want to be stealing your work. 🍻

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.