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 (6)

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
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

photo
photo
1

Every time I visit this blog, I always find something new and unique. The articles cover a variety of topics, and the editorial team turns them into interesting and insightful articles. slope

photo
1

Metamask wallet extension - a digital haven for all your cryptocurrency needs. With its sleek interface and robust security features, this extension is a game-changer in the world of online transactions. Seamlessly integrating with your browser, the Metamask wallet extension allows you to store, send, and receive Ethereum and other ERC-20 tokens with ease. Its intuitive design makes managing multiple wallets a breeze, giving you full control over your assets at all times. Whether you're trading on decentralized exchanges or participating in blockchain-based games, the Metamask wallet extension ensures that your funds are always safe and secure. Say goodbye to clunky hardware wallets and hello to the future of digital finance with the Metamask wallet extension by your side.


Metamask wallet extension | Metamask wallet extension

photo
1

Keep your cryptocurrency secure with Bitkeep wallet. Designed for maximum security and convenience, it's the perfect way to store and manage all your digital assets. Bitkeep wallet


Discover the power and efficiency of Saitapro - the innovative software solution for businesses looking to streamline their processes and increase productivity. Try it today! Saitapro

Leave a Comment
 
Attach a file