Need a simple tuto to execute a little python program
Closed this issue · 8 comments
Hello,
Thank you very much for your program.
I would like to make a little Python script to simply open or close my Roller Shutter, for exemple, and I don't know how to use this API.
Could you, please, provide us a little tuto to explain how the API works ?
I've executed the script from the Readme file and I have this information :
Volet Cuisine (rts://1231-xxxx-2819/xxxxxxxx) - rts:RollerShutterRTSComponent UpDownRollerShutter - RollerShutter
But for the rest I don't know what to do...
Thanks !
We should indeed improve the documentation a bit; #190. You can see a very advanced implementation in Home Assistant (see https://github.com/home-assistant/core/tree/dev/homeassistant/components/overkiz).
from pyoverkiz import OverkizClient
from pyoverkiz.enums import OverkizCommand
from pyoverkiz.models import Command, Device, StateDefinition
client = OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"])
device_url = "rts://1231-xxxx-2819/xxxxxxxx"
exec_id = await client.execute_command(
device_url,
Command(OverkizCommand.OPEN, [0])
)
THANK YOU SO MUCH !!!!!!!!!!!!!!!!!!!! It's working perfectly !!!
HERE IS A WORKING CONFIGURATION FOR ME :
#INSTALL or UPDATE python-overkiz-api : https://github.com/iMicknl/python-overkiz-api :
sudo python3 -m pip install pyoverkiz --upgrade
It works with the last today's version : pyoverkiz==1.7.4
#GIVE LOGIN INFORMATIONS :
import asyncio
import time
import pyoverkiz
from pyoverkiz.const import SUPPORTED_SERVERS
from pyoverkiz.client import OverkizClient
from pyoverkiz.enums import OverkizCommand
from pyoverkiz.models import Command, Device, StateDefinition
USERNAME = "mail@mail.com"
PASSWORD = "somfyconnectpassword"
#THEN GET INFORMATIONS ABOUT SOMFY DEVICES :
async def getting_info() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
for device in devices:
print(f"{device.label} ({device.id}) - {device.controllable_name}")
print(f"{device.widget} - {device.ui_class}")
while True:
events = await client.fetch_events()
print(events)
time.sleep(2)
asyncio.run(getting_info())
#FIND THE ROLLER SHUTTER URL (IT SHOULD BE LIKE THIS : rts://1234-1234-1234/12345678
#PASTE THE ROLLER SHUTTER URL :
roller_shutter_url='rts://1234-1234-1234/12345678'
async def open_roller_shutter() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = roller_shutter_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.OPEN, [0]) )
#AND VOILA ! :
asyncio.run(open_roller_shutter())
HERE IS MY COMPLETE CONFIG FOR RTS SOMFY ROLLER SHUTTER AND IO SOMFY Atlantic Electrical Heater HEATING SYSTEM ( Interface de chauffage io. Référence 1822452 )
#!/usr/bin/python3
#sudo python3 -m pip install pyoverkiz
#https://github.com/iMicknl/python-overkiz-api/issues/759
import asyncio
import time
import pyoverkiz
from pyoverkiz.const import SUPPORTED_SERVERS
from pyoverkiz.client import OverkizClient
from pyoverkiz.enums import OverkizCommand
from pyoverkiz.models import Command, Device, StateDefinition
USERNAME = "mail@mail.com"
PASSWORD = "somfyconnectpassword"
volets_cuisine_url='rts://1234-1234-1234/12345678'
chauffage_salon_url='io://1234-1234-1234/12345678'
#Scanner les appareils :
#############################################
async def scan() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
for device in devices:
print(f"{device.label} ({device.id}) - {device.controllable_name}")
print(f"{device.widget} - {device.ui_class}")
while True:
events = await client.fetch_events()
print(events)
time.sleep(2)
asyncio.run(scan())
#Obtenir la liste des équipements :
##############################################
async def getting_info() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
for device in devices:
print(f"{device.label} ({device.id}) - {device.controllable_name}")
print(f"{device.widget} - {device.ui_class}")
asyncio.run(getting_info())
#Ouvrir les volets de la cuisine : string value (OPEN, CLOSE, MY, STOP)
##############################################
volets_cuisine_url='rts://1234-1234-1234/12345678'
async def ouvrir_volets_cuisine() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = volets_cuisine_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.OPEN, [0]) )
asyncio.run(ouvrir_volets_cuisine())
#Fermer les volets de la cuisine :
##############################################
volets_cuisine_url='rts://1234-1234-1234/12345678'
async def fermer_volets_cuisine() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = volets_cuisine_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.CLOSE, [0]) )
asyncio.run(fermer_volets_cuisine())
#Position "My" volets de la cuisine :
##############################################
volets_cuisine_url='rts://1234-1234-1234/12345678'
async def my_volets_cuisine() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = volets_cuisine_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.MY, [0]) )
asyncio.run(my_volets_cuisine())
#Stop les volets de la cuisine :
##############################################
volets_cuisine_url='rts://1234-1234-1234/12345678'
async def stop_volets_cuisine() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = volets_cuisine_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.STOP, [0]) )
asyncio.run(stop_volets_cuisine())
#Mode éco chauffage salon : string value (boost, comfort, comfort-1, comfort-2, eco, frostprotection, off, secured)
##############################################
chauffage_salon_url='io://1234-1234-1234/12345678'
async def mode_eco_chauffage_salon() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = chauffage_salon_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.SET_HEATING_LEVEL,['eco']) )
asyncio.run(mode_eco_chauffage_salon())
#Mode confort (19°) chauffage salon :
##############################################
chauffage_salon_url='io://1234-1234-1234/12345678'
async def mode_confort_chauffage_salon() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = chauffage_salon_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.SET_HEATING_LEVEL,['comfort']) )
asyncio.run(mode_confort_chauffage_salon())
#Mode confort-1 (18°) chauffage salon :
##############################################
chauffage_salon_url='io://1234-1234-1234/12345678'
async def mode_confort1_chauffage_salon() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = chauffage_salon_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.SET_HEATING_LEVEL,['comfort-1']) )
asyncio.run(mode_confort1_chauffage_salon())
#Mode confort-2 (17°) chauffage salon :
##############################################
chauffage_salon_url='io://1234-1234-1234/12345678'
async def mode_confort2_chauffage_salon() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = chauffage_salon_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.SET_HEATING_LEVEL,['comfort-2']) )
asyncio.run(mode_confort2_chauffage_salon())
#Eteindre chauffage salon :
##############################################
chauffage_salon_url='io://1234-1234-1234/12345678'
async def off_chauffage_salon() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = chauffage_salon_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.SET_HEATING_LEVEL,['off']) )
asyncio.run(off_chauffage_salon())
#Hors-gel (7,5°) chauffage salon :
##############################################
chauffage_salon_url='io://1234-1234-1234/12345678'
async def hors_gel_chauffage_salon() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = chauffage_salon_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.SET_HEATING_LEVEL,['frostprotection']) )
asyncio.run(hors_gel_chauffage_salon())
HERE IS MY CONFIG FOR MyFoxAlarm TSKAlarmController Somfy Outdoor Camera Référence 2401560 AND THE SPOTLIGHT
#Activer alarme: string value (ARM, PARTIAL, DISARM, ARM_NIGHT, ARM_AWAY)
##############################################
alarme_url='myfox://SOMFY_PROTECT-45YGghggy567TTyGigigj768T8/site_alarm'
async def activer_alarme() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = alarme_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.ARM) )
asyncio.run(activer_alarme())
#Désactiver alarme:
##############################################
alarme_url='myfox://SOMFY_PROTECT-45YGghggy567TTyGigigj768T8/site_alarm'
async def desactiver_alarme() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = alarme_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.DISARM) )
asyncio.run(desactiver_alarme())
#Allumer spot alarme: string value (ON, OFF)
##############################################
spot_alarme_url='myfox://SOMFY_PROTECT-45YGghggy567TTyGigigj768T8#2'
async def allumer_spot_alarme() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = spot_alarme_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.ON) )
asyncio.run(allumer_spot_alarme())
#Eteindre spot alarme:
##############################################
spot_alarme_url='myfox://SOMFY_PROTECT-45YGghggy567TTyGigigj768T8#2'
async def eteindre_spot_alarme() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
device_url = spot_alarme_url
exec_id = await client.execute_command( device_url, Command(OverkizCommand.OFF) )
asyncio.run(eteindre_spot_alarme())
Thank you for your precious help. Almost everything works now.
However, I have a last problem for importing my scenarios. I don't know how to do :
I think I need a "scenario.oid" but I don't know how to obtain it.
I don't find any information about my scenarios when I scan the Tahoma and when I start the scenario.
Here is my code. I try to adapt this : https://github.com/home-assistant/core/blob/dev/homeassistant/components/overkiz/scene.py
If you could give me a quick help, it would be nice. However I'm already more than satisfied by all the help you provided to me, it was very helpful. Thanks ;-)
#Scénario "Je me couche" :
##############################################
from pyoverkiz.models import Scenario
async def scenario_je_me_couche() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
devices = await client.get_devices()
exec_id = await client.execute_scenario(scenario.oid)
@pzim-devdata sorry for the late reply, you need to call get_setup
or get_scenarios
to receive the scenario oid.
@pzim-devdata sorry for the late reply, you need to call
get_setup
orget_scenarios
to receive the scenario oid.
Thank you ! 😉
HERE IS MY CONFIG FOR SCENARIOS
from pyoverkiz.models import Scenario
#Obtenir les noms et l'oid des scénarios :
##############################################
async def getting_oid_scenarios() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
scenarios = await client.get_scenarios()
for scenario in scenarios:
print(f"{scenario.label} - {scenario.oid}")
asyncio.run(getting_oid_scenarios())
#Scénario "Je me couche" :
##############################################
scenario_je_me_couche_oid='8g45646y567-1234-1234-b234-1234a1a1ab12'
async def scenario_je_me_couche() -> None:
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS["somfy_europe"]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
print(exception)
return
scenario_oid=scenario_je_me_couche_oid
exec_id = await client.execute_scenario(scenario_oid)
asyncio.run(scenario_je_me_couche())