How do I publish a JSON payload to a HABApp MqttItem?
I have a Daikin airconditioner fitted with a “Faikin” ESP32 unit (GitHub - revk/ESP32-Faikin: ESP32 based module to control Daikin aircon units).
This unit makes unit information and settings available through mqtt.
I have written the following simple code to try out controlling the unit via HABApp.
The specific MqttItems (commented out) work.
The “generic” MqttItem does not when I (i.e.) try to publish {‘power’: ‘on’} to it.
This post suggests that publishing an entire JSON payload is possible.
import HABApp
from HABApp.mqtt.items import MqttPairItem, MqttItem
class AircoAutomation(HABApp.Rule):
def __init__(self):
super().__init__()
self.daikin_ac_info = MqttItem.get_item('state/daikinac/status')
self.daikin_ac = MqttItem.get_create_item('setting/daikinac/')
self.daikin_ac_power = MqttItem.get_create_item('command/daikinac/power')
self.daikin_ac_settemp = MqttItem.get_create_item('command/daikinac/temp')
self.daikin_ac_fanmode = MqttItem.get_create_item('command/daikinac/fan')
self.daikin_ac_mode = MqttItem.get_create_item('command/daikinac/mode')
self.run.soon(self.command_aircon)
def command_aircon(self):
self.daikin_ac.publish({'power': 'off'})
# self.daikin_ac_power.publish('on')
# self.daikin_ac_fanmode.publish('A')
print (self.daikin_ac_power.value)
print (self.daikin_ac_info.value['home'])
AircoAutomation()
I am aware that the topics names differ (‘command/daikinac/power’ vs ‘setting/daikinac’) but that is how the Faikin documentation specifies the mqtt topics for this device.
setting is used to publish settings in JSON format. The command topic to send commands to individual command topics (such as ‘power’, ‘mode’ etc).
Changing these topics does not alter the behavior (i.e. the settings do not come through to the device).