This object is in archive! 

API

yves shared this question 3 years ago
Answered

bonjour . quelqu'un pourrait m expliquer comment fonctionne l API ? par exemple , comment allumer une lampe ( quelle uuid et quelle commande ) .Merci.

Replies (3)

photo
1

Bonjour. Personne utilise l API ?

photo
1

Bonjour,

Si tu veux utiliser des commandes par requête HTTP, tu dois créer un accessoire virtuel (j'utilise les switch et les meter). Ensuite avec des règles interne à la Zipato tu fais correspondre les commandes.

Dans les virtuels, tu dois répéter le plus bas niveau dans l'arborescence de l'accessoires et ouvrir sa configuration. Tu trouves alors le lien dans "URL:". Il faut y ajouter la valeur qui suit (souvent 0 ou 1). Testable direct dans ton navigateur.

J'utilise l'API dans un module Homebridge, mais c'est assez lourd à mettre en place et à tester.

Pour les choses simples passer par des accessoires virtuels est simple et efficace.

Bonne journée,

photo
1

ok merci . Je croyais que l api était plus simple . Je passerai par des virtuels . merci et bon réveillon .

photo
1

Hi

to use API it is required to make login session which will keep your credentials. After that it is possible to control any device by changing either its attribute or ability value.

Below you may find one python example where you can check Login and ability/ attribute setting:

import requests
import json
import hashlib
#from py_session import py_session
import z_settings

USERNAME = z_settings.USERNAME
PASSWORD = z_settings.PASSWORD

# Set session - one for the all requests
session_login = requests.session()

# Step 1 - init
URL_init = z_settings.URL_MAIN + '/user/init'

res = session_login.get(URL_init).json()

if not res['success']:
    exit()

# Step 2 - login
URL_login = z_settings.URL_MAIN + "/user/login"

pas2sign = hashlib.sha1(PASSWORD.encode("utf-8")).hexdigest()
token = hashlib.sha1((res['nonce'] + pas2sign).encode("utf-8")).hexdigest()
head = {'Authorization': 'token {}'.format(token)}
data = {'username': USERNAME}

res_login = session_login.get(URL_login, params={'username': USERNAME, 'token': token})

# Step 3 - set Zipato server
URL_serial = z_settings.URL_MAIN + '/box/select?serial=' + z_settings.ZIPATO_SERIAL
res_serial = session_login.get(URL_serial).json()

server_name = res_serial['name']
server_localIP = res_serial['localIp']
server_remoteIP = res_serial['remoteIp']

# Step 4 - get user devices
URL_devices = z_settings.URL_MAIN + "/devices"
res_devices = session_login.get(URL_devices).json()

user_device = ""
for z_device in res_devices:
    if (z_device['name'] == z_settings.DEVICE_NAME):
        user_device = z_device['name']
        user_device_uuid = z_device['uuid']
        break

# Step 4 - get device ability
URL_abilities = z_settings.URL_MAIN + "/devices/" + user_device_uuid + "/abilities"
res_abilities = session_login.get(URL_abilities).json()

for z_ability in res_abilities:
    if (z_ability['name'] == z_settings.ABILITY_NAME):
        user_ability = z_ability['name']
        user_ability_uuid = z_ability['uuid']
        if z_ability['fields'][z_settings.STATE_ATTRIBUTE]:
            user_attribute_uuid = z_ability['fields'][z_settings.STATE_ATTRIBUTE]
        break

if not user_attribute_uuid:
    exit()

# Step 5 - get attribute value
URL_attribute = z_settings.URL_MAIN + "/attributes/" + user_attribute_uuid + "/value"
res_attribute = session_login.get(URL_attribute).json()

attribute_value = res_attribute['value']
attribute_timestamp = res_attribute['timestamp']

# Switch state
attribute_value_new = "false"
if attribute_value == "false":
    attribute_value_new = "true"

# Step 6 - set attribute value
p_value = {'value': attribute_value_new}

res_attribute_put = session_login.put(URL_attribute, data=json.dumps(p_value), headers=z_settings.HEADERS)

photo
1

It's getting too complicated for me. I would just like to know how to find the URL of the different devices to be able to control them with another system. Thank you.

photo
1

Hi

you can control just virtual devices not real devices.

URLs of virtual devices you can foind easily under ability settings.

photo
1

ok merci

Replies have been locked on this page!