Home / Portfolio / MQTT Payload Processor

MQTT Payload Processor

MQTT Payload Processor Diagram
%author% via %publisher%

There are many ways smart devices can communicate. From Wifi to Zigbee, Zwave to Bluetooth, all protocols serve a specific purpose. My smart home, runs on radio devices that use the same protocol as your garage opener. Radio frequency (RF) signals are emitted on at 433MHz and captured by a receiver. From there it can be further processed by a payload processor and acted upon by the home automation hub.

Use cases:

  • Gateway: Acts as a gateway to convert RF codes (or other implementation specific identifier) to native Home Assistant events
  • Schedules: reuse the same RF device (wall panel or remote control) to perform multiple actions depending on some pre-defined schedule
  • Clean & Maintainable: Store all RF specific integer codes in one location and use events as triggers in automations.
  • Post processing: for payloads delivered by Open MQTT Gateway

How does the payload processor work?

MQTT Payload Processor Diagram
MQTT Payload Processor Diagram showing how messages flow through the different systems and the role the processor component plays.

You need have some kind of device that emits specific payloads on an MQTT topic that you want to convert to Home Assistant events. My use case is integration with OpenMQTTGateway where RF payloads are sent on a specific MQTT topic.

For example, an RF motion sensor, door sensor and wall button panel may send the following messages on /rf/all:

/rf/all 121330
/rf/all 163562
/rf/all 136566

Payload processor allows you to name and define these devices (including their respective RF codes) in one central location. The rest of your Home Assistant configuration then refers to events and callback scripts instead. (This way your RF codes are not duplicated and used throughout the configuration.) It acts as a gateway between different domains (e.g. RF and Home Assistant).

Since each device emits a different code such as 1576482, it can be overwhelming to use these numbers throughout the Home Assistant configuration.

I wrote this custom integration for Home Assistant to help map RF payloads to events in Home Assistant. It allows you to define all RF devices such as a wall panel and specify the different button codes it is able to emit. When a device is triggered, the component will create a native Home Assistant event that is easy to use in automation triggers.

Before:

 trigger:
    platform: mqtt
    topic: rf/1576482

After (using Event trigger):

  trigger:
    platform: event
    event_type: wall-panel-button-1

My examples are specific to RF devices, but you can use this component in any situation where implementation specific data is sent on an MQTT topic and you want to add a layer of abstraction on top of it.

Each payload is unique to a device. Some devices have multiple payloads.

Defining Schedules

You can the define schedules (e.g. morning, afternoon, evening, night) that can be used to give the buttons on the device different functions depending on the active schedule. Learn more on the Github Documentation.

One feature that all devices have in common is that buttons can be pressed in any combination. This is because the device emits different numbered payloads for each button combination. This means a 3 button panel will give you 7 possible button combinations. (Pressing buttons in any of the following combinations:

1
2
3
1-2
1-3
2-3
1-2-3

With a bit of practice (and good memory) this can be used to trigger 7 different automations. Add to this the ability to configure schedules and time-based button functions will be sure to cater for any home automation scenario you have in mind.

What can it be used for?

Integrating cheap RF devices into your smart home is one of the best ways to add sensors to your system because of how affordable they are compared to Wifi counterparts. I have used this component for motion sensors, wall panels and dash button.

Repositoryhttps://github.com/danobot/mqtt_payload_processor
PlatformPython / Home Assistant

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More