MQTT Device Template

class festivalgrid.device_templates.mqtt_device.MQTTDevice(device)[source]

The base class for MQTT based devices.

Note

Tasmota is a good reference for implementing new MQTT based device templates.

notify_setup_change(model)[source]

Pings both the worker and mqtt_broker services that they should reload the setup.

send_mqtt_message(topic, message)[source]

Use this to send a message to the mqtt broker.

Parameters
  • topic (str.) – The topic this message should be published under.

  • message (str.) – The message that should be published.

festivalgrid.device_templates.mqtt_device.init_mqtt(client_id=None, on_message=False, on_connect=False, on_disconnect=False)[source]

This will open a connection to the mqtt broker and register any callbacks you pass in as parameters.

Parameters
  • client_id (str.) – The name this connection should register as with the broker.

  • on_message (function.) – Callback function that gets called when a new message is received.

  • on_connect (function.) – Callback function that gets called when the connection to the broker is successful.

  • on_disconnect (function.) – Callback function that gets called when the broker disconnects.

Returns

paho.Client – the paho Client object instance