Skip to main content

Asynchronous Python client controlling an OJ Microline Thermostat.

Project description

GitHub Release Python Versions Project Stage Project Maintenance License

GitHub Activity PyPi Downloads GitHub Last Commit Stargazers Issues

Maintainability Code Coverage

Build Status Typing Status

Asynchronous Python client for communicating with a OJ Microline Thermostat.

About

A Python package to control OJ Microline thermostats. It currently supports the WD5 series (OWD5, MWD5), WG4 series (UWG4, AWG4), and WG5 series.

Installation

pip install ojmicroline-thermostat

Datasets

Thermostat

This object represents the current state of a thermostat.

Variable Type Description
model string The model name for this thermostat.
serial_number string The serial number for this thermostat.
software_version string The currently installed software version.
zone_name string The name of the zone this thermostat belongs to.
zone_id integer The ID of the zone this thermostat belongs to.
name string The name of the thermostat.
online boolean Indicates if the thermostat is connected to the network.
heating boolean Indicates if the thermostat is currently heating/is on.
regulation_mode integer The currently set regulation mode of the thermostat, see below.
supported_regulation_modes list The regulation modes this thermostat supports.
min_temperature integer The lowest temperature the thermostat can be set to.
max_temperature integer The highest temperature the thermostat can be set to.
manual_temperature integer If the regulation mode is set to manual mode, the thermostat will target this temperature.
comfort_temperature integer If the regulation mode is set to comfort mode, the thermostat will target this temperature.
comfort_end_time datetime If the regulation mode is set to comfort mode, it will end at this time.
vacation_mode boolean If true then the thermostat is set to vacation_temperature from vacation_begin_time to vacation_end_time. If false, then no vacation is in progress or scheduled.
vacation_temperature integer If the regulation mode is VACATION, the thermostat will target this temperature.
vacation_begin_time datetime The vacation regulation mode will begin at this time. Note that vacations may be scheduled to begin in the future.
vacation_end_time datetime If in vacation mode, the thermostat will return to schedule mode at this time.
last_primary_mode_is_auto boolean Unknown

These fields are only available on WD5-series thermostats; for others, they may be None:

Variable Type Description
thermostat_id int The unique identifier for this thermostat.
adaptive_mode boolean If on then then the thermostat automatically changes heating start times to ensure that the required temperature has been reached at the beginning of any specific event.
open_window_detection boolean If on then the thermostat shuts off the heating for 30 minutes if an open window is detected. Also available on WG5-series thermostats.
daylight_saving_active boolean If on, the "Daylight Saving Time" function of the thermostat will automatically adjust the clock to the daylight saving time for the "Region" chosen.
sensor_mode integer The currently set sensor mode of the thermostat, see below. Also available on WG5-series thermostats.
temperature_floor integer The temperature measured by the floor sensor. Also available on WG5-series thermostats.
temperature_room integer The temperature measured by the room sensor. Also available on WG5-series thermostats.
boost_temperature integer If the regulation mode is set to boost mode, the thermostat will target this temperature.
boost_end_time datetime If the regulation mode is set to boost mode, it will end at this time.
frost_protection_temperature integer If the regulation mode is set to frost protection mode, the thermostat will target this temperature. Also available on WG5-series thermostats.
schedule Schedule/dict The schedule the thermostat currently uses. On WD5 this is a Schedule object; on WG5 it is a raw dict from the API.
energy list The energy usage in kWh for the current day and the six previous days. (Note that the integrated tariff calculation needs to be disabled.)

These fields are available on WG4 and WG5-series thermostats; for others, they may be None:

Variable Type Description
temperature integer The current temperature; the thermostat uses the room sensor or floor sensor based on its configuration. Avoid using this directly; instead, call the get_current_temperature() method which also works for WD5-series thermostats.
set_point_temperature integer The temperature the thermostat is targeting. Avoid using this directly; instead, call the get_target_temperature() method which also works for WD5-series thermostats.

These fields are only available on WG5-series thermostats; for others, they may be None:

Variable Type Description
building_id string The building UUID this thermostat belongs to.
zone_uuid string The zone UUID this thermostat belongs to (WG5 uses UUIDs rather than integer zone IDs).
is_in_standby boolean Whether the thermostat is in standby (frost protection) mode.
schedule_id string The UUID of the schedule assigned to this thermostat.
schedule_name string The name of the schedule assigned to this thermostat.

Regulation modes

Integer Constant Description
1 REGULATION_SCHEDULE The thermostat follows the configured schedule.
2 REGULATION_COMFORT The thermostat is in comfort mode until comfort_end_time.
3 REGULATION_MANUAL The thermostat is in manual mode, will not resume schedule unless changed.
4 REGULATION_VACATION The thermostat is in vacation mode, it started at vacation_begin_time and ends at vacation_end_time.
6 REGULATION_FROST_PROTECTION The thermostat is set to frost protection, preventing the floor from freezing.
8 REGULATION_BOOST The thermostat is in boost mode for 1 hour, using the max_temperature as target temperature.
9 REGULATION_ECO The thermostat is in eco mode, using the lowest temperature of the schedule.

Keep in mind that certain thermostats only support a subset of these modes; be sure to check the Thermostat.supported_regulation_modes field.

Sensor modes

Integer Constant Description
1 SENSOR_ROOM_FLOOR The thermostat takes the average of the room and floor temperature
3 SENSOR_FLOOR The thermostat is using the floor sensor for target temperature.
4 SENSOR_ROOM The thermostat is using the room sensor for target temperature.

Methods

OJMicroline

Method Params Description
login None Create a new session at the OJ Microline API.
get_thermostats None Get all thermostats from the OJ Microline API.
set_regulation_mode resource: Thermostat, regulation_mode: int, temperature: int | None = None, duration: int = COMFORT_DURATION Set the regulation mode based on the input.
- resource: An instance of a Thermostat model returned by get_thermostats()
- regulation_mode: An integer representing the regulation mode, see "Regulation modes"
- temperature: An integer representing the temperature, eg: 2500. Only useful when setting the regulation mode to manual or comfort.
- duration: The duration in minutes to set the temperature for; only applies to comfort mode.
get_current_energy None Return the current energy usage in kWh. This is the first value in the energy property list.

Usage

WD5 Example

import asyncio
from time import sleep

from ojmicroline_thermostat import OJMicroline, Thermostat, WD5API
from ojmicroline_thermostat.const import (
    REGULATION_BOOST,
    REGULATION_COMFORT,
    REGULATION_ECO,
    REGULATION_FROST_PROTECTION,
    REGULATION_MANUAL,
    REGULATION_SCHEDULE,
    REGULATION_VACATION,
)

REGULATION_MODES = {
    REGULATION_SCHEDULE: "Schedule",
    REGULATION_ECO: "Eco",
    REGULATION_MANUAL: "None (Manual)",
    REGULATION_FROST_PROTECTION: "Frost Protection",
    REGULATION_BOOST: "Boost",
    REGULATION_COMFORT: "Comfort",
    REGULATION_VACATION: "Vacation",
}


async def main():
    """Show example on using the OJMicroline client."""
    async with OJMicroline(
        api=WD5API(
            customer_id=1234,
            api_key="<app-api-key>",
            username="<your-username>",
            password="<your-password>",
        ),
    ) as client:
        # Thermostats
        thermostats: list[Thermostat] = await client.get_thermostats()

        for resource in thermostats:
            print("####################")
            print(f"# {resource.name}")
            print("####################")
            print("- Details:")
            print(f"   Serial Number: {resource.serial_number}")
            print(f"   Mode: {REGULATION_MODES[resource.regulation_mode]}")
            print(f"   Temperature: {resource.get_current_temperature()}")
            print(f"   Target temperature: {resource.get_target_temperature()}")
            print("")

            print(f"- Setting to boost mode")
            await client.set_regulation_mode(resource, REGULATION_BOOST)
            print("Sleeping for 5 seconds..")
            sleep(5)
            print(f"- Setting to schedule")  # noqa: E501
            await client.set_regulation_mode(resource, REGULATION_SCHEDULE)


if __name__ == "__main__":
    asyncio.run(main())

WG5 Example

import asyncio

from ojmicroline_thermostat import OJMicroline, Thermostat
from ojmicroline_thermostat.wg5 import WG5API
from ojmicroline_thermostat.const import (
    REGULATION_MANUAL,
    REGULATION_SCHEDULE,
)


async def main():
    """Show example on using the OJMicroline client with a WG5 thermostat."""
    async with OJMicroline(
        api=WG5API(
            username="<your-username>",
            password="<your-password>",
        ),
    ) as client:
        thermostats: list[Thermostat] = await client.get_thermostats()

        for resource in thermostats:
            print(f"{resource.name}: {resource.get_current_temperature() / 100}°C")
            print(f"  Target: {resource.get_target_temperature() / 100}°C")

            # Set to manual mode at 25°C
            await client.set_regulation_mode(resource, REGULATION_MANUAL, 2500)

            # Set back to schedule
            await client.set_regulation_mode(resource, REGULATION_SCHEDULE)


if __name__ == "__main__":
    asyncio.run(main())

Contributing

This is an active open-source project. We are always open to people who want to use the code or contribute to it.

We've set up a separate document for our contribution guidelines.

Thank you for being involved! :heart_eyes:

Setting up development environment

This Python project is fully managed using the Poetry dependency manager.

You need at least:

Install all packages, including all development requirements:

poetry install

Poetry creates by default an virtual environment where it installs all necessary pip packages, to enter or exit the venv run the following commands:

poetry shell
exit

Setup the pre-commit check, you must run this inside the virtual environment:

pre-commit install

Now you're all set to get started!

As this repository uses the pre-commit framework, all changes are linted and tested with each commit. You can run all checks and tests manually, using the following command:

poetry run pre-commit run --all-files

To run just the Python tests:

poetry run pytest

License

MIT License

Copyright (c) 2020-2024 Robbin Janssen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ojmicroline_thermostat-3.4.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ojmicroline_thermostat-3.4.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file ojmicroline_thermostat-3.4.0.tar.gz.

File metadata

  • Download URL: ojmicroline_thermostat-3.4.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.3 Linux/6.17.0-1010-azure

File hashes

Hashes for ojmicroline_thermostat-3.4.0.tar.gz
Algorithm Hash digest
SHA256 3b637c41e51433a15c5095815388fbe7394ba1ade6d3b26f035ad99b42019a01
MD5 d6cc63342da64780cc4db26804b9da37
BLAKE2b-256 5dcc16f409845a67760a21f27c3561c41811235b22b4e3aa0412a640d27b8673

See more details on using hashes here.

File details

Details for the file ojmicroline_thermostat-3.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ojmicroline_thermostat-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e530de7be14baf03f98c752b43fb2c476d10d5fcc86670fd94bbdc588f54c51
MD5 846ff4c6465087205738f050ceb5c93c
BLAKE2b-256 4f18ad7676420641f10b634372a48f77057c52f0b58ec1dd1f430b2e8a865cfb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page