Overkiz API and Somfy API

pi@raspberry:~ $ wget https://github.com/tetienne/somfy-open-api/archive/master.zip
--2018-11-18 13:02:19--  https://github.com/tetienne/somfy-open-api/archive/master.zip
Herleiden van github.com (github.com)... 140.82.118.4, 140.82.118.3
Verbinding maken met github.com (github.com)|140.82.118.4|:443... verbonden.
HTTP-verzoek is verzonden; wachten op antwoord... 302 Found
Locatie: https://codeload.github.com/tetienne/somfy-open-api/zip/master [volgen...]
--2018-11-18 13:02:19--  https://codeload.github.com/tetienne/somfy-open-api/zip/master
Herleiden van codeload.github.com (codeload.github.com)... 192.30.253.120, 192.30.253.121
Verbinding maken met codeload.github.com (codeload.github.com)|192.30.253.120|:443... verbonden.
HTTP-verzoek is verzonden; wachten op antwoord... 200 OK
Lengte: niet-opgegeven [application/zip]
Wordt opgeslagen als: ā€˜master.zipā€™

master.zip                                     [ <=>                                                                                    ]  26,07K  --.-KB/s    in 0,1s

2018-11-18 13:02:20 (227 KB/s) - 'ā€˜master.zipā€™' opgeslagen [26696]
pi@raspberry:~ $ unzip master.zip
Archive:  master.zip
d6bf3e9a01a7a7281914b0f9415a81375c8d74b5
   creating: somfy-open-api-master/
  inflating: somfy-open-api-master/.gitignore
  inflating: somfy-open-api-master/.travis.yml
 extracting: somfy-open-api-master/CHANGELOG.md
  inflating: somfy-open-api-master/LICENSE
 extracting: somfy-open-api-master/MANIFEST.in
  inflating: somfy-open-api-master/README.md
   creating: somfy-open-api-master/pymfy/
 extracting: somfy-open-api-master/pymfy/__init__.py
  inflating: somfy-open-api-master/pymfy/__version__.py
   creating: somfy-open-api-master/pymfy/api/
 extracting: somfy-open-api-master/pymfy/api/__init__.py
   creating: somfy-open-api-master/pymfy/api/devices/
 extracting: somfy-open-api-master/pymfy/api/devices/__init__.py
  inflating: somfy-open-api-master/pymfy/api/devices/base.py
  inflating: somfy-open-api-master/pymfy/api/devices/blind.py
  inflating: somfy-open-api-master/pymfy/api/devices/category.py
  inflating: somfy-open-api-master/pymfy/api/devices/roller_shutter.py
  inflating: somfy-open-api-master/pymfy/api/model.py
  inflating: somfy-open-api-master/pymfy/api/somfy_api.py
  inflating: somfy-open-api-master/requirements.txt
  inflating: somfy-open-api-master/setup.py
   creating: somfy-open-api-master/tests/
 extracting: somfy-open-api-master/tests/__init__.py
  inflating: somfy-open-api-master/tests/get_device.json
  inflating: somfy-open-api-master/tests/get_devices_1.json
  inflating: somfy-open-api-master/tests/get_devices_2.json
  inflating: somfy-open-api-master/tests/get_site.json
  inflating: somfy-open-api-master/tests/get_sites.json
  inflating: somfy-open-api-master/tests/test_command.py
  inflating: somfy-open-api-master/tests/test_somfy_api.py
  inflating: somfy-open-api-master/tests/test_somfy_device.py
  inflating: somfy-open-api-master/tox.ini
pi@raspberry:~ $ cd somfy-open-api-master
pi@raspberry:~/somfy-open-api-master $ sudo python setup.py install
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
  warnings.warn(msg)
running install
running bdist_egg
running egg_info
creating pymfy.egg-info
writing requirements to pymfy.egg-info/requires.txt
writing pymfy.egg-info/PKG-INFO
writing top-level names to pymfy.egg-info/top_level.txt
writing dependency_links to pymfy.egg-info/dependency_links.txt
writing manifest file 'pymfy.egg-info/SOURCES.txt'
file src/api.py (for module src/api) not found
reading manifest file 'pymfy.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pymfy.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
file src/api.py (for module src/api) not found
file src/api.py (for module src/api) not found
warning: install_lib: 'build/lib.linux-x86_64-2.7' does not exist -- no Python modules to install

creating build
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/pymfy-0.1.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pymfy-0.1.0-py2.7.egg
Copying pymfy-0.1.0-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adding pymfy 0.1.0 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/pymfy-0.1.0-py2.7.egg
Processing dependencies for pymfy==0.1.0
Searching for typing
Reading https://pypi.python.org/simple/typing/
^Cinterrupted
pi@raspberry:~/somfy-open-api-master $ sudo python3 setup.py install
/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
  warnings.warn(msg)
running install
running bdist_egg
running egg_info
writing requirements to pymfy.egg-info/requires.txt
writing dependency_links to pymfy.egg-info/dependency_links.txt
writing pymfy.egg-info/PKG-INFO
writing top-level names to pymfy.egg-info/top_level.txt
file src/api.py (for module src/api) not found
reading manifest file 'pymfy.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'pymfy.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
file src/api.py (for module src/api) not found
file src/api.py (for module src/api) not found
warning: install_lib: 'build/lib' does not exist -- no Python modules to install

creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pymfy.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/pymfy-0.1.0-py3.5.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pymfy-0.1.0-py3.5.egg
Copying pymfy-0.1.0-py3.5.egg to /usr/local/lib/python3.5/dist-packages
Adding pymfy 0.1.0 to easy-install.pth file

Installed /usr/local/lib/python3.5/dist-packages/pymfy-0.1.0-py3.5.egg
Processing dependencies for pymfy==0.1.0
Searching for typing
Reading https://pypi.python.org/simple/typing/
Downloading https://files.pythonhosted.org/packages/bf/9b/2bf84e841575b633d8d91ad923e198a415e3901f228715524689495b4317/typing-3.6.6.tar.gz#sha256=4027c5f6127a6267a435201981ba156de91ad0d1d98e9ddc2aa173453453492d
Best match: typing 3.6.6
Processing typing-3.6.6.tar.gz
Writing /tmp/easy_install-9ixm8e3a/typing-3.6.6/setup.cfg
Running typing-3.6.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-9ixm8e3a/typing-3.6.6/egg-dist-tmp-pc_9csg9
zip_safe flag not set; analyzing archive contents...
Moving typing-3.6.6-py3.5.egg to /usr/local/lib/python3.5/dist-packages
Adding typing 3.6.6 to easy-install.pth file

Installed /usr/local/lib/python3.5/dist-packages/typing-3.6.6-py3.5.egg
Searching for requests-oauthlib==0.7.0
Best match: requests-oauthlib 0.7.0
Adding requests-oauthlib 0.7.0 to easy-install.pth file

Using /usr/lib/python3/dist-packages
Finished processing dependencies for pymfy==0.1.0
pi@raspberry:~/somfy-open-api-master $ cd ..
pi@raspberry:~ $ cd Downloads
pi@raspberry:~/Downloads $ python3 contribution.py
Traceback (most recent call last):
  File "contribution.py", line 1, in <module>
    from pymfy.api.somfy_api import SomfyApi
ImportError: No module named 'pymfy'

@johndoe I was able to reproduce your issue. The package uploaded on pypi wasā€¦ empty. Now if you upgrade pymfy to 0.2.1, it should be OK.

@gieljnssns Your first issue is linked to the python version you use. Minimum version has to be 3.4. For the second error, upload the package as explain just above.

Thx you guys for your feedback.

[SOLVED]
Can I get some explanation about the full callback URL?
I can not get this workingā€¦

I used https://hassio.com like above.
When u use the contribute code, you get an URL, paste this in a browser.
Then you have to authorise and your browser will go to another URL, paste this one in the contribute scriptā€¦

Somfy made a nice schema to explain the flow: https://developer.somfy.com/apis-docs
Later, this callback URL will be replace by the HomeAssistant public url.

Somfy support has been really nice. After some exchange with them, they sent me all the currently supported type. Iā€™ve created an issue for each category: https://github.com/tetienne/somfy-open-api/issues
Their documentation will be soon updated.

1 Like

With the latest project version, all the devices supported by the Somfy API can be manipulated: blind, roller shutter, camera protect and thermostat.

1 Like

Hello, aby progress? I realy need orientation of slats (0-100%) my blinds. Openhab can do that, but i dont want OH. :-\ Please, do this function fĆ³r as.

Currently Iā€™ve started the development of the new somfy component. But itā€™s no so easy to understand. The dev documentation is really great but no complete. So I have to look at components such abode or wink to progress. I really want to understand what I do and not simply perform a copy paste. It will ease maintenance later.
About the orientation, I think I will add it as a service. Cover platform does not support it.

Thank you for your answer. Great to hear it. Think you, if tilt will be avalible in this year? Little Jesus or Santa have Google home for me and I want play with it. :wink:
You create tahoma component for hassio?

I cannot give you any deadline. Iā€™m doing this on my freetime, and I have no idea of the amount of code I have to do yet.
Iā€™m not the related to the Tahoma component.

FYI, with the latest version of my client API, I greatly improved the token management. It will help a lot for the Home Assistant component developpment.

Iā€™ve create a first version of the Somfy component and of the Somfy cover platform. You can see my commits here. Itā€™s still a work in progress. I think there is still a lot of improvement to do.

2 Likes

Hello, how can i add component to Hassio RPi? https://www.home-assistant.io/components/cover.somfy/ Doesnt work. :frowning:

@tetienne
I made a folder /config/custom_components/somfy and I placed the init.py file there, I made a folder /config/custom_components/cover and placed the Somfy.py file there.
When I restart HA the pymfy library doesnā€™t get installed because it was imported before its get installed

# from pymfy.api.devices.base import SomfyDevice

import homeassistant.helpers.config_validation as cv
from homeassistant.components.http import HomeAssistantView
from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
from homeassistant.helpers import discovery

REQUIREMENTS = ['pymfy==0.4.1']

So I commented the line and placed here

    def update(self):
        """Update state of the device."""
        from requests import HTTPError
        from pymfy.api.devices.base import SomfyDevice
        try:
            SomfyDevice(self.somfy, self.api).refresh_state()
        except HTTPError as error:
            _LOGGER.error("Cannot update device %s. %s.", self.name, error)

When I restart HA

But when I authorise

{"error":"redirect_uri_mismatch","error_description":"The redirect URI provided does not match registered URI(s)."}

and these errors

Unable to prepare setup for platform cover.somfy: Platform not found.
Unable to find component cover.somfy
Error loading custom_components.cover.somfy. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 92, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/cover/somfy.py", line 10, in <module>
    from homeassistant.components.somfy import DOMAIN, SomfyEntity
ModuleNotFoundError: No module named 'homeassistant.components.somfy'

@Bojkas You have to create a custom component. But if you donā€™t know what you do, I suggest to not install this component yet. Itā€™s still an early alpha version.

@gieljnssns Oh itā€™s nice to see you test the component. For the requirements not installed, I have perhaps missed a step. I havenā€™t yet added pymfy the requirements file. About redirect_uri_mismatch error, you have to set the redirect URL in Somfy Dev Portal to https://<your_hass_base_url>/auth/somfy/callback. Https is required. If your instance is only available in local, you have to setup a self-signed certificate.

As improvement, I have to limit the number of requests sent to Somfy. Currently, I send one request to know the state of a device. I have also to remove the usage of the configurator popin. According to @balloob, this is deprecated. I donā€™t know yet how it can be done.

About redirect_uri_mismatch error, you have to set the redirect URL in Somfy Dev Portal to https://<your_hass_base_url>/auth/somfy/callback

It was still on https://hassio.com, I have changed the url but now I get

500 Internal Server Error

Server got itself in trouble

And for

ModuleNotFoundError: No module named 'homeassistant.components.somfy'

Iā€™ve changed

# from homeassistant.components.somfy import DOMAIN, SomfyEntity
from custom_components.somfy import DOMAIN, SomfyEntity

and another error

Wed Dec 19 2018 16:10:11 GMT+0100 (CET)

Error while setting up platform somfy
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/cover/somfy.py", line 21, in setup_platform
    devices = api.get_devices(category=Category.ROLLER_SHUTTER)
  File "/config/deps/lib/python3.6/site-packages/pymfy/api/somfy_api.py", line 87, in get_devices
    site_ids = [s.id for s in self.get_sites()] if site_id is None else [
  File "/config/deps/lib/python3.6/site-packages/pymfy/api/somfy_api.py", line 71, in get_sites
    return [Site(s) for s in r.json()]
  File "/config/deps/lib/python3.6/site-packages/pymfy/api/somfy_api.py", line 71, in <listcomp>
    return [Site(s) for s in r.json()]
  File "/config/deps/lib/python3.6/site-packages/pymfy/api/model.py", line 8, in __init__
    self.id = json.get('id')
AttributeError: 'str' object has no attribute 'get'

When can you release an official component? Can your component the tilting of the outside covers?

@Bojkas It will depend of my free times. I hope end of january. Now, as said above is just a question of improvement. For the tilting, you mean the orientation of the blind? (sorry Iā€™m not an English native speaker). If yes, itā€™s supported by the API. So I will be able to add it in HASS.

@gieljnssns About this 500, it came from the Somfy server or from HASS? In the first case, it can be due to a temporary issue on their size (it wonā€™t be the first time). In the second case, have you a stack trace?

Yes, i mean orientation, not position. Im not an English native speaker too, im from Czech. :slight_smile:

@tetienne

When I click on JA (yes) my browser goā€™s to https://xxxxxxxxxxxxx.duckdns.org/auth/somfy/callback?state=BVWgzlExxxxxxxxxxxxxxxxxxxx1VhD5g&code=MWRxxxxxxxxxxxxxxxxxxxxxjVmMmQzYTE5MxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxmI2ZDBhMjE5OQ
and Iā€™ve got the internal server error