
OpenBeken provides a scriptable set of MQTT-related commands that can be used to publish data not only directly to Home Assistant, but also to other devices in the MQTT network. This way you can for example control a Zigbee switch directly from OBK, without writing any automations in HA. In this tutorial I will show you how you can do this in few simple steps.
Basic requirements
This tutorial assumes that you already have OBK device and that your device is connected to MQTT. I am using Home Assistant for this purpose.
OBK publish command
OBK provides multiple commands for publishing data, but most important is just publish command.
publish [TopicName] [Payload] [bRawMode]
First argument is MQTT topic name, second is payload, third is optional, used to strip prepended OBK device name to the topic name.
The payload can include escaped quotation marks, I will show an example soon.
The bRawMode disabled prepending OBK prefix, let's see how it looks in both cases:


Can you spot the difference? Yes, one command has "WindowsOBK/" and "/get" added.
For more information on commands, see: https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
Controlling OBK device from OBK
Let's say that your target device is called "Uticnica2". It's OBK device, so it follows naming here:
https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/mqttTopics.md
It's important to remember that short name is used for MQTT:

So, the publish to control relay will use name Uticnica2/1/set.
1 there stands for channel index.
Then, payload can be either 0 or 1, to set it on or off.
So the full command is:
publish Uticnica2/1/set 0 1
Let's run it:

The following command should change the state of target device accordingly.

Controlling Zigbee device from OBK
Now let's try something more seemingly complicated. Let's control a Zigbee device from OBK.
First, let's look up the topics of Zigbee2mqtt device I have:
https://www.zigbee2mqtt.io/devices/TS0012.html
As you can see, there is a clear instruction how to control it, but can OBK do it?

Let's try executing:
publish zigbee2mqtt/test2/set " {\"state_left\" : \"TOGGLE\"}" 1

The state of Zigbee device was changed. It works correctly.
Summary
As you can see, it's very easy to publish data via OBK scripting command. The method I have presented above is working even for JSON commands with the quotation marks, all thanks to the possiblity of escaping the quotes. With this mechanism, you can create advanced automations without involving the HA scenes system itself. I hope you'll find it useful.
PS: In the next topic we will check if it's possible to publish a file from LittleFS, we will also look into variables expansion
Cool? Ranking DIY Helpful post? Buy me a coffee.