HABApp MqttPairItem throws errors: rule does not load

In this post I struggled with topic names to get Mqtt to work in HABApp. After getting things working I continued to try to consolidate the status and command topics in one MqttPairItem (based on Sebastians suggestion in that post).
HABApp throws the following error however:

[2025-07-02 23:35:29,448] [             HABApp.Rules]    ERROR |   File "/etc/openhab/habapp/rules/AircoAutomation.py", line 90, in AircoAutomation.py
[2025-07-02 23:35:29,449] [             HABApp.Rules]    ERROR |     AircoAutomation()
[2025-07-02 23:35:29,449] [             HABApp.Rules]    ERROR |   File "/etc/openhab/habapp/rules/AircoAutomation.py", line 55, in __init__
[2025-07-02 23:35:29,449] [             HABApp.Rules]    ERROR |     self.daikin_ac = MqttPairItem.get_create_item('state/daikinac',write_topic='command/daikinac/control')
[2025-07-02 23:35:29,449] [             HABApp.Rules]    ERROR |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2025-07-02 23:35:29,449] [             HABApp.Rules]    ERROR |   File "/opt/habapp/lib/python3.11/site-packages/HABApp/mqtt/items/mqtt_pair_item.py", line 48, in get_create_item
[2025-07-02 23:35:29,449] [             HABApp.Rules]    ERROR |     assert isinstance(item, cls), f'{cls} != {type(item)}'
[2025-07-02 23:35:29,449] [             HABApp.Rules]    ERROR | AssertionError: <class 'HABApp.mqtt.items.mqtt_pair_item.MqttPairItem'> != <class 'HABApp.mqtt.items.mqtt_item.MqttItem'>
[2025-07-02 23:35:29,449] [              HABApp.Rule]  WARNING | /opt/habapp/lib/python3.11/site-packages/HABApp/rule_manager/rule_file.py:86: RuntimeWarning:coroutine 'HABAppRuleContext.unload_rule' was never awaited
[2025-07-02 23:35:29,449] [             HABApp.Rules]  WARNING | Failed to load /etc/openhab/habapp/rules/AircoAutomation.py!

Sebastian suggested the following:

This I did. The error remains.
Following steps were:

  1. remove the AircoAutomation() instantiation at the end of the file (attempt to prevent loading).
  2. stop habapp (sudo systemctl stop habapp).
  3. remove AircoAutomation.py from rules.
  4. start habapp.
  5. copy AircoAutomation.py into rules folder.

Observed behaviour: same error.

This is my code (no double MqttItems to my knowledge).

import HABApp
from HABApp.core.items import Item
from HABApp.core.events import ValueChangeEvent, ValueChangeEventFilter
from HABApp.openhab.items import NumberItem, SwitchItem, GroupItem
from HABApp.mqtt.items import MqttPairItem, MqttItem
import datetime
import logging
log = logging.getLogger("RuleLog")

class AircoAutomation(HABApp.Rule):
    def __init__(self):
        super().__init__()


        self.daikin_ac = MqttPairItem.get_create_item('state/daikinac',write_topic='command/daikinac/control')
        
        self.ac_handbediening = SwitchItem.get_item('Daikin_handbediening')
        self.roomtemp = NumberItem.get_item('A_Bg_Gang_Multisensor_Sensor_temperature')
        self.teruglevering = NumberItem.get_item('P1_Meter_Current_Total_Net_Power')

        self.SET_TEMP = 19
        self.nu = datetime.datetime.now().time()
        self.starttijd = datetime.time(10, 30, 0)
        self.stoptijd = datetime.time(16, 30, 0)

        self.roomtemp.listen_event(self.change_ac, ValueChangeEventFilter())
        self.teruglevering.listen_event(self.change_ac, ValueChangeEventFilter())

    def change_ac(self,event: ValueChangeEvent):

        if self.roomtemp.value > self.SET_TEMP and self.nu > self.starttijd and self.teruglevering < -100: 
            if self.ac_handbediening.is_off():
                if self.daikin_ac['power'] == False:
                    self.daikin_ac.publish({"power":True,"temp":self.SET_TEMP,"mode":"C","fan":"A"})
                    log.info('DAIKIN -- Airconditioner aan.')

        if self.nu > self.stoptijd and self.teruglevering > -50:
            if self.ac_handbediening.is_off():
                if self.daikin_ac['power'] == True:
                    self.daikin_ac.publish({"power":False})
                    log.info('DAIKIN -- Airconditioner uit.')

AircoAutomation()

What am I doing wrong?

Does your device publish on ‘state/daikinac’ with the retain Flag set to true?
This will result in HABApp automatically creating the MqttItem.
Is it possible to configure the device so that it’s retain: false?
Also try deleting all retained topics for ‘state/daikinac’ in MqttExplorer.

Yes, I think it does: in MQTT-explorer there is a RETAINED label in the “value” box to the right.


In the Faikin settings here is no option to disable or enable the retain flag on topics.

For now I have coded two separate MqttItems, one (‘state/daikinac/status’) for reading status, and one (‘command/daikinac/control’) for command publishing. I find two items where I can read from and publish in JSON format is a huge improvement over ten (or so) items for reading and publishing to different airco settings :grinning_face:.

I’ll ask the Faikin developer about the retain flag.

The developer of the Faikin device has confirmed that the retain flag is set for setting/[hostname] topics. It is a set feature in his support library for ESP32 devices.
That would mean deleting the retained topics on the broker and loading the rule as you suggested. But that means after every reload of HABapp (upgrades of HABapp, updates of OpenHAB, system reboots etc). That would mean manual intervention every time such an event happens: too much trouble imo.
I will keep my read and write MQTT Items and wait if I come across appropriate mqtt topics for a MqttPairItem in the future.
Thank you.