Info

Year

2019

Languages

Python, Flask

Platform

IoT, Client Library

Back to Projects

Overview

There are a plethora of smart home thermostats on the market all of which provide a wide variety of features. While I looked at Nest and Hive and many of the other popular ones, I settled on the Drayton Wiser system because it provides a hub controller that actually hosts a local API. While you can use their mobile app and access the system via their cloud infrastructure, you can also directly talk to your controller via a local RESTful API. This means you have a bit of insurance against the company going bust or any internet outages breaking your schedules.

The idea of the library is to make it as easy as possible to use in Python. You can get a list of your devices in just a few lines.

import draytonwiser
manager = draytonwiser.Manager(wiser_hub_ip=HUB_IP_ADDRESS, api_secret=API_SECRET)
devices = manager.get_all_devices()

In my home setup (See Home Automation), I have all IoT devices on their own VLAN with a firewall setup that prevents them from talking to the public internet. The Drayton Wiser still works locally as the mobile phone app will talk to your local controller if it can’t connect to the public internet. I then control all interactions with the thermostat either through the inbuilt schedules or via Home Assisstant through the VPN.

This combo of access methods provides a reasonable amount of security while also still helping the non-techie person in the house. Handy.

To enable this to work with Home Assistant I’ve been collaborating online to develop the python client library required to interact with the Home Assistant component.

Examples

This example shows how in the backend the client library will make interconnections between related objects. Devices, Rooms, RoomStats and iTRVs are all related and connected but come as separate endpoints in the API. These are separated to make sending data back to them easier but when retrieving data the client library will make the interconnections between objects for you.

import draytonwiser
manager = draytonwiser.Manager(wiser_hub_ip=HUB_IP_ADDRESS, api_secret=API_SECRET)

devices = manager.get_all_devices()
for device in devices:

    print("Type: " + str(type(device)))
    print("Room ID: " + str(device.get_room_id()))
    print(device.product_type + " ID:[" + str(device.id) + "]")
    print("Battery: " + str(device.get_battery_percentage()))

    # A measurement object is a related RoomStat or SmartValve. To make it
    # easier to iterate the Device class abstracts some of this away for you
    # so you don't have to always care if it's a RoomStat or an iTRV or a SmartPlug
    
    if device.has_measurement():
        print("  Temperature: " + str(device.measurement.temperature()))

        if device.product_type == "RoomStat":
            print("  Humidity: " + str(device.measurement.measured_humidity))

This example shows boosting the temperature in a room for a short period of time. This is triggered from Home Assistant when we want a little bit more heat.

import draytonwiser
manager = draytonwiser.Manager(wiser_hub_ip=HUB_IP_ADDRESS, api_secret=API_SECRET)

room = manager.get_room(3)
room.set_boost(30, 18) # Parameters are: duration in minutes, temperature in celcius

Source Code & Projects

To get the system working with Home Assistant a number of projects on Github are used.

Project Description Link
Drayton Wiser Python API The backend python library that connects to the API GitHub
Mock API Server A mock Drayton Wiser hub that can be used for testing. Based on Flask. GitHub
Drayton Wiser Home Assistant Component Home Assistant component developed by https://github.com/asantaga/ GitHub
Drayton Wiser Home Asisstant Component A fork of the project to integrate the new library GitHub