Mqtt
HAASP MQTT client application
Example code
class Config(ConfigObject):
def config(self):
config = {}
# MQTT
config["mqtt"] = {}
config["mqtt"]["broker"] = "<BROKER IP>"
config["mqtt"]["port"] = 1883
config["mqtt"]["id"] = "haasp-01"
config["mqtt"]["user"] = ""
config["mqtt"]["password"] = ""
return config
def setup(self):
# mqtt devices for subscribing to payload
self.mqtt_device_status = EventObject("mqtt", "/shellys/shelly1-1298712126/relay/0", options={"mode": "subscribe"})
# mqtt device subscribing to payload with filter for hiding duplicate events
self.mqtt_device_status = EventObject("mqtt", "/shellys/shelly1-1298712126/relay/0", options={"mode": "subscribe", "hide_duplicate_values", "true"})
# mqtt device subscribing to json payload with filtering on specific key (adding : to the topic)
self.mqtt_device_status_ison = EventObject("mqtt", "/shellys/shelly1-1298712126/relay/0/status:ison", options={"mode": "subscribe"})
# mqtt device for publising payload
self.mqtt_device_command = EventObject("mqtt", "/shellys/shelly1-1298712126/relay/0/command", options={"mode": "publish"})
def process_event(self):
# mqtt example of processing event
if self.mqtt_device_status.event == "off"
if self.mqtt_device_command.set("on")