Integrating a Shelly1 GEN3 with a Shelly BLU door/window via Bluetooth and publish BLU status in MQTT

I have integrated an BLU door/window in a Shelly1 GEN3 to get the status of a gate open/closed. After being integrated when the BLU status changes Shelly one should be able to sent that event information published in MQTT where OPENHAB should subscribe the topic and be updated with the door status. Nevertheless, up to now, I am unable to publish that information with a script written in the shelly. In spite the MQTT endpoint being well configured and MQTT shelly configuration as well.

Has anyone stepped into this issue?

Thanks for any feedback

João

I have two Shelly Blu units connected to Shelly relays and publishing to MQTT. besides that I have four Aranet CO2 sensors throughout the house connected to the same Shelly relays via Bluetooth. So I’ve merged the Shelly Blu and Aranet examples from thr Shelly script base, as the amount of scripts is limited to three (especially the older relays I believe). There is no problem in receiving these mqtt messages with Openhab.

For your situation I think we lack quite some information as to where the problem might be. Although you state that the messages don’t get published. So lets start by that.

First start off with your MQTT server. Can you read and publish messages directly on there? Which MQTT server do you use? I believe Mosquitto is restricting their code more and more to force authentication to have a more secure message relay. So do you have authentication turned on? Did you create a user for your Shellies? Do you have more items connected to your MQTT server that can succesfully be received (subscribed) by openHab? Do you have logging on your Shelly relay enabled so you are sure that your script functions.

Simply put: show us your configuration (code, screenshots, no need to reveal user names or passwords of course). For now it is just guessing what your setup is and what is and what isn’t working as expected. All we know you have a Shelly Blu item at one end and openHab at the other.

I just answered a similar question in a german board.

I assume that you have an MQTT broker running.
You enter the broker adress under Settings / MQTT in the Shelly app for the device that acts as the interface to the BLU device (red box)

(screenshots in German only, sorry for that)
Then, also in the Shelly app, you look up the MAC address of the BLU device:

Whether Shelly is sending MQTT messages properly can, for example, be checked using the MQTT Explorer: https://mqtt-explorer.com/.

In openHAB, you then integrate the BLU device like this:

mqtt.things

Thing mqtt:topic:mosquitto:mqtt_Shelly "MQTT Shelly" (mqtt:broker:mosquitto) {
    Channels:
          Type contact : cTerrasse       "Terrassentür"        [ stateTopic="shelly/events/rpc", transformationPattern="REGEX:(.*d8:7a:XX:XX:72:c0.*)∩JSONPATH:$.params.events[0].data.Window",  off="0" , on="1" ] 
}

where d8:…:c0 is the MAC address of the BLU.

shelly.items

Contact Fkontakt_Erker_links      "Erker Tür links"  {channel="mqtt:topic:mosquitto:mqtt_Shelly:cTerrasse"}

Thank you very much for your swift response.

In attachment I send you a file with the architecture of the components involved, with the configuration of the Shelly1 GEN3 regarding the MQTT. By the way, the Shelly is communicating with MQTT publishing internal events.

The publish issue I have is regarding the publishing of a topic using the script which I show below:

// Publica manualmente no MQTT
let msg = “open”; // payload
let topic = “shellies/shelly1g3-e4b063eb84b8/gate”; // generic topic to show the gate status

print(“Testing publishing:”, msg, “em”, topic);

Shelly.call(“MQTT.Publish”, {
topic: topic,
message: msg,
qos: 1,
retain: true
}, function(res, err) {
if (err) print(“—Error MQTT—”, JSON.stringify(err));
else print(“—MQTT OK—”);
});

the result is: —Error MQTT— 404 (meaning “No handler for MQTT.Publish”)

I send you in attachment the deviceinfo from shelly1 GEN3, the logs from the device and the logs from the MQTT extracted from the mosquitto_sub which evidences that the shelly is publishing in MQTT.

Thank you very much,

João

MobaXterm_192.168.1.51joao_20260407_163246.txt (32.1 KB)

debug-log-shelly1g3-e4b063eb84b8 (14).txt (25.3 KB)

data-shelly1g3-e4b063eb84b8 (1).txt (9.8 KB)

Try MQTT.publish

1 Like

Thanks a Lot . It worked

1 Like

You should mark the post with the solution as “the solution”, so that others can see that the topic was solved and quickly find the solution.

You absolutely right. This is my first thread. Sorry! Thank you for the advice!

Here is the solution I have applied and works fine:

THINGS

Thing mqtt:topic:shellyDoor “Shelly Door Sensor” {
Channels:
Type string : door “Door State” [
stateTopic=“shelly1g3-e4bxxxxxxxxxxx/status/bthomesensor:202”,
transformationPattern=“JSONPATH:$.value”
]

ITEMS

String DoorRaw “Door Raw [%s]” { channel=“mqtt:topic:shellyDoor:door” }

// finalstate (OpenHAB Contact)
Contact Door_Main “Main Door [%s]”

SITEMAPS

Text item=Door_Main label=“Estado do Portão [%s]” icon=“door”

RULE

rule “Convert Shelly Door State”
when
Item DoorRaw changed
then
if (DoorRaw.state.toString == “true”) {
Door_Main.postUpdate(OPEN)
} else if (DoorRaw.state.toString == “false”) {
Door_Main.postUpdate(CLOSED)
}
end

1 Like

By using contact instead of string (like shown in my proposal) you can omit the rule and use a direct linked Contact Item.