API/Development

Getting Started with the Adax API

The Adax API provides a standard http-based interface for control of Adax thermostats. Software developers will be able to query status and send commands to their thermostat(s). Adax aims to follow the general rules of API compatibility and will protect implementations from breaking when bug fixes and new features are implemented. The API also strives to be self-documenting, easy to understand and use.

4.1. Remote Client API User Guide

Overview

Adax API is provided as a REST service and that allows you to:

  • Get your rooms target and current temperatures,
  • Change your rooms heating target temperatures.

Getting Started

For using Adax API you will need an authentication token for secure access and some REST services usage knowledge. The API is provided at the https://
api-1.adax.no/client-api/ address. The services description can be accessed at the https://api-1.adax.no/client-api/openapi in an OpenAPI format. You
could also use the provided Python and Java samples as a starting point.

Obtaining Authentication Credentials Required for Adax API

Using the Adax WiFi application you can create and get the authentication token used for accessing the Adax API. You should use at least the Adax WiFi
app version 3.7. The authentication token can be accessed following those steps:

  1. Navigate to Account Tab,
  2. Select “Remote user client API”
  3. Select “Add Credential”
  4. Give some name to the created credential and copy the generated password.

Using Adax API

The API provides 3 end points:

  1. /auth/ for authentication to the REST service.
  2. /rest/v1/control/ for controlling your rooms
  3. /rest/v1/content/ for getting rooms statuses. (add ?withEnergy=1 to get heaters power consumption for past hour)
  4. /rest/v1/energy_log/{roomId} – returns hourly energy log from current time back to 1 week for the specified room in 1h intervals.

Control and status endpoins accepts and returns json documents.

Code Samples

Python Sample

# install dependencies with: pip install requests sanction
import requests
import sanction


CLIENT_ID = "112395"

# replace with your client ID (see Adax WiFi app,Account Section)
CLIENT_SECRET = "6imtpX63D5WoRyKh"

# replace with your client ID (see Adax WiFi app,Account Section)
API_URL = "https://api-1.adax.no/client-api"

def get_token():

# Authenticate and obtain JWT token
oauthClinet = sanction.Client(token_endpoint = API_URL + '/auth/token')
oauthClinet.request_token(grant_type = 'password', username = CLIENT_ID, password = CLIENT_SECRET)
return oauthClinet.access_token

def set_room_target_temperature(roomId, temperature, token):

# Sets target temperature of the room
headers = { "Authorization": "Bearer " + token }
json = { 'rooms': [{ 'id': roomId, 'targetTemperature': str(temperature) }] }
requests.post(API_URL + '/rest/v1/control/', json = json, headers = headers)

def get_homes_info(token):

headers = { "Authorization": "Bearer " + token }
response = requests.get(API_URL + "/rest/v1/content/", headers = headers)

json = response.json()

for room in json['rooms']:

roomName = room['name']
targetTemperature = room['targetTemperature'] / 100.0
currentTemperature = 0

if ('temperature' in room):
currentTemperature = room['temperature'] / 100.0

print("Room: %15s, Target: %5.2fC, Temperature: %5.2fC, id: %5d" % (roomName, targetTemperature, currentTemperature, room['id']))

token = get_token()

# Change the temperature to 24 C in the room with an Id of 196342
set_room_target_temperature(196342, 2400, token)

# Replace the 196342 with the room id from the
get_homes_info output
get_homes_info(token)