Control hOn devices with python
Find a file
Dan Davies 728a891e6c Fix KeyError in MQTT publish handler dropping whole status update
_on_publish_received() indexes appliance.attributes["parameters"]
directly by parName when applying an incoming appliancestatus push:

    appliance.attributes["parameters"][parameter["parName"]].update(parameter)

If the payload contains a parName that hasn't been seen/initialized
locally yet, this raises KeyError before self._hon.notify() is
reached, so the entire push message (not just that one parameter) is
silently dropped for that appliance.

In practice this reproduced reliably on a Haier washing machine
(HW90-B14959U1-UK) at end-of-cycle, where the push includes a
"programStats" parameter:

    Exception ignored in: <class 'KeyError'>
    Traceback (most recent call last):
      File ".../awscrt/mqtt5.py", line 1540, in _on_publish
        self._on_publish_cb(publish_data)
      File ".../pyhon/connection/mqtt.py", line 109, in _on_publish_received
        appliance.attributes["parameters"][parameter["parName"]].update(
    KeyError: 'programStats'

Because the exception is swallowed by the underlying MQTT client as
"Exception ignored in", it fails silently with no log entry pointing
at the cause - the visible symptom is just that dependent entities
(e.g. door-open state bundled in the same push) never update.

Fix: use setdefault() instead of a raw index so an unseen parName
initializes its entry instead of raising.
2026-08-23 13:03:13 +01:00
.github/workflows Add python3.12 support 2023-11-19 23:53:21 +01:00
pyhon Fix KeyError in MQTT publish handler dropping whole status update 2026-08-23 13:03:13 +01:00
.flake8 Add flake8 config 2023-07-18 21:31:26 +02:00
.gitignore Fix missing zone attribute 2023-04-15 22:25:34 +02:00
.pylintrc Fix checks 2024-02-11 05:11:21 +01:00
LICENSE Init commit 2023-02-13 01:41:38 +01:00
MANIFEST.in Next try to add py.typed in package 2023-07-24 01:47:45 +02:00
mypy.ini Improve type hints 2023-07-23 21:55:42 +02:00
README.md Update README.md 2024-02-02 23:49:49 +01:00
requirements.txt Support cloud push with wss mqtt 2024-03-18 19:59:38 +01:00
requirements_dev.txt Support cloud push with wss mqtt 2024-03-18 19:59:38 +01:00
setup.py Bump 0.17.5 2024-07-10 12:47:30 +01:00

This python package is unofficial and is not related in any way to Haier. It was developed by reversed engineered requests and can stop working at anytime!

pyhOn

PyPI - Status PyPI PyPI - Python Version PyPI - License PyPI - Downloads
Control your Haier, Candy and Hoover appliances with python! The idea behind this library is, to make the use of all available commands as simple as possible.

Installation

pip install pyhOn

Quick overview

To get an idea of what is possible, use the commandline-tool pyhOn. This command requests all available options of connected appliances from the hOn api of your Haier Account.

$ pyhOn --user example@mail.com --password pass123
========== WM - Waschmaschine ==========
data:
  attributes:
    parameters:
      ...
      texture: 1
      totalElectricityUsed: 28.71
      totalWashCycle: 35
      totalWaterUsed: 2494
      transMode: 0
      ...
settings:
  startProgram:
    rinseIterations:
      max: 5
      min: 3
      step: 1
    spinSpeed:
      - 0
      - 400
      - 600
      - 800
      ...

Python-API

List devices

import asyncio
from pyhon import Hon

async def devices_example():
    async with Hon(USER, PASSWORD) as hon:
        for appliance in hon.appliances:
            print(appliance.nick_name)

asyncio.run(devices_example())

Execute a command

async with Hon(USER, PASSWORD) as hon:
    washing_machine = hon.appliances[0]
    pause_command = washing_machine.commands["pauseProgram"]
    await pause_command.send()

Set command parameter

async with Hon(USER, PASSWORD) as hon:
    washing_machine = hon.appliances[0]
    start_command = washing_machine.commands["startProgram"]
    for name, setting in start_command.settings:
        print("Setting", name)
        print("Current value", setting.value)
        if setting.typology == "enum":
            print("Available values", setting.values)
            setting.value = setting.values[0]
        elif setting.typology == "range":
            print("Min value", setting.min)
            print("Max value", setting.max)
            print("Step value", setting.step)
            setting.value = setting.min + setting.step

Translation

To get the translation of some keys like programs, you can use the translation command to see all of hOn's available translations

$ pyhOn translate es
AC:
  APPLIANCE_RENAME:
    CONTENT_CHOOSE_NAME: Antes de continuar, debes elegir un nombre...
    DEFAULT_NAME: Aire acondicionado
    TITLE_CHOOSE_NAME: ¡Elije un nombre para tu aire acondicionado!
    TITLE_SAVE_NAME: Para cambiar el nombre de tu aparato:
...

This generates a huge output. It is recommended to pipe this into a file

$ pyhOn translate fr > hon_fr.yaml
$ pyhOn translate en --json > hon_en.json

Usage example

This library is used for the custom HomeAssistant Integration "Haier hOn".

Contribution

Any kind of contribution is welcome!

Please add your appliances data to our hon-test-data collection.
This helps us to develop new features and not to break compatibility in newer versions.