Https://docs.openmqttgateway.com/integrate/openhab3.html#install-the-mqtt-binding

I installed the new version OpenMQTTGateway 1.8 on my ESP -WROOM-32
this new version allows me to recover the data from my SwitchBot Blind Tilt in OpenHab 4.2.2 however I do not know how to order them (open, close, send a tilt value)
Can anyone help me?

Raspberry 4
Openhabian
OpenHab 4.2.2

Hi @Dom76

We’re just ironing out the last kinks with OpenMQTTGateway/Theengs Gateway MQTT auto-discovery, and with the upcoming releases of openHAB 4.3 and an 18 dot of OpenMQTTGateway things will be vastly improved on the auto-discovery front.

I do not quite understand however what you mean by

how to order them (open, close, send a tilt value)

so someone else will be better suited to address this side of your query.

Hi

In fact all my equipments is well discovered but when I create things, they are online but do not report any datas and cannot be controlled!
I created my things directly in OpenHab in a xxx.things file (see below) and there I retrieve all the information from my “Blind Tilt” but I don’t know how to order them.


| Hans_Lree DigiH
December 3 |

  • | - |

Hi @Dom76

We’re just ironing out the last kinks with OpenMQTTGateway/Theengs Gateway MQTT auto-discovery, and with the upcoming releases of openHAB 4.3 and an 18 dot of OpenMQTTGateway things will be vastly improved on the auto-discovery front.

I do not quite understand however what you mean by

how to order them (open, close, send a tilt value)

so someone else will be better suited to address this side of your query.

Well, these are just the things definitions sexually defined in your .things file, where the order is totally irrelevant.

Have you created items with links to these things yet, in an .items file? E. g. for the battery level something like

Number Blind_Tilt_Battery "Blind Tilt Battery [%d %%]" <battery_icon> {channel="mqtt:topic:OMG_ESP32_XXXXXXX:battery"}

with then placing these items in your sitemap, dashboard or wherever you want them any way and order you like?

Keep in mind I’m still stuck on openHAB2 here, so the channel syntax above might have changed in the meantime, and is only entered here from the top of my head :wink:

Also, is the REGEX required for the tranformationPatterns, or would it not still suffice to only define?!?

transformationPattern="JSONPATH:$.batt"

Yes I obviously have an .item file and a .sitmap and it all works perfectly.
but it's controlling the blinds that I don't know how to do.
<img apple-inline="yes" id="0E58ADEE-0463-4DC2-AD12-07958E6D5110" src="upload://rpNgPpwOjdG7smV84dqm8aNqqn3.jpeg" class="">

| Hans_Lree DigiH
December 3 |

  • | - |

Dom76:

I created my things directly in OpenHab in a xxx.things file (see below) and there I retrieve all the information from my “Blind Tilt” but I don’t know how to order them.

Well, these are just the things definitions sexually defined in your .things file, where the order is totally irrelevant.

Have you created items with links to these things yet, in an .items file? E. g. for the battery level something like

Number Blind_Tilt_Battery "Blind Tilt Battery [%d %%]" <battery_icon> {channel="mqtt:topic:OMG_ESP32_XXXXXXX:battery"}

with then placing these items in your sitemap, dashboard or wherever you want them any way and order you like?

Keep in mind I’m still stuck on openHAB2 here, so the channel syntax above might have changed in the meantime, and is only entered here from the top of head :wink:

Also, is the REGEX required for the tranformationPatterns, or would it still not suffice to only define?!?

transformationPattern="JSONPATH:$.batt"

And just to be clear - sexually was meant to be textually - only saw it in your replied quite of mine just now :wink:

but it’s controlling the blinds that I don’t know how to do.

You haven’t defined any commandTopic in your things.

While I do not have any of the controllable SwitchBot devices myself, the command Topic path for OpenMQTTGateway is home/OpenMQTTGateway/commands/MQTTtoBT and the JSONd to send described at

E. g.

Type string : mqtt_command            "MQTT Command"        [ commandTopic="home/OpenMQTTGateway/commands/MQTTtoBT" ]

Type string : sys_command           "SYS Command"        [ commandTopic="home/OpenMQTTGateway/commands/MQTTtoSYS/config" ]

Then create the kind of itme(s) (slider,switch) you prefer, which trigger a rule or rules to send the relevant JSON to the commandTopic or also control the system parameter settings of your gateway with the above added sys_command thing.

All this should hopefully also be made a lot easier with auto-discovery in the future.

Thanks I will look at that tomorrow.

Envoyé de mon iPhone

SO 
I managed to order the blinds thanks to the information you sent me but the commands sent work randomly, sometimes they execute almost immediately and other times they do not execute.
And this whether via OpenHab or directly via terminal commands.
Any idea?

Thanks I will look at that tomorrow.

Envoyé de mon iPhone

Is your Blind Tilt still paired with the SwitchBot app, and this might possibly cause some issues?

But this is really just a wild guess from my side, as I was only involved in the state decoding and hex commands structure, and with no controllable SwitchBot devices myself, I cannot really say what might be the issue here.

The best option would be to post your issue on the OpenMQTTGateway/Theengs forum, so that the involved unregular openHAB forum team members can look into it.

I struggled to get my blinds working too. With the Switchbot app on my iPhone, controlling my blinds is intermittent. From my iPhone I send a command to open three blinds. Sometimes they all open like they should, sometimes one or two and then sometimes none.
That said, I don’t expect them to work perfectly from openHab, but they do as well as from my phone.
This is an example of what I send from the command line for one blind.

mosquitto_pub -h 192.168.92.254 -t home/OMG_ESP32C3_BLE/commands/MQTTtoBT -m '{"model_id":"W270160X","tilt":"close_down","id":"C0:D1:3B:7F:8A:CD"}'
mosquitto_pub -h 192.168.92.254 -t home/OMG_ESP32C3_BLE/commands/MQTTtoBT -m '{"model_id":"W270160X","tilt":"open","id":"C0:D1:3B:7F:8A:CD"}'

From openHab I pass the command to a python script to send to the MQTT broker. It’s a work in progess but it is working. I hope that helps.
Chris

Ok thanks

Envoyé de mon iPhone

With my above suggested controlTopic things, and then the linked items, you can circumvent any Python script requirement and directly then send the command to the commantTopic item, e. g.

BLE_MQTT_Command.sendCommand('{\"model_id\":\"W270160X\",\"tilt\":\"open\",\"id\":\"C0:D1:3B:7F:8A:CD\"}')

just as for any other generi BLE device which doesn’t require a PIN or constant paired connection, with the generic READ and WRITE commands.

Sounds like the intermittent problem with the Blint Tilt might not be OpenMQTTgateway specific then, if the SwitchBot app has similar issues. Hopefully being addressed soon, as other users with the SwitchBot Curtain stated for them it was even snappier than with the SwitchBot app and hub itself.

I am sure sending the command strictly using openHab is possible, but for me python is easier, and I reused code I wrote years ago for a MQTT IR controller I designed to control my Yamaha reciever.
One of the challenges I saw was including a variable in the command string when I want to set the blinds to something other than open or close. The next challenge I am working on is testing whether or not the blinds performed the sent command correctly so I can do a retry.
And yes, even being in the same room and line of site, the blinds are pretty iffy controlling it with my phone. Personally, I don’t think these blinds are ready for “prime time” yet but I still like them. They solve a problem for me and that is good.

No worries, fi you’re happy with your script stick with it :slight_smile:

For anyone else possibly interested in the direct way.

Just by concatenating the command sting as in the opernMQTTGateway documentation for the SwitchBot devices with the fetched/entered value from a slider for example, then sending the individually concatenated string to the command item.

If you look at the bottom of the SwitchBot command sections, there is always a response (assuming success) if the command has been sent through OpenMQTTGateway. So you can test within a specified time if such a response came back indicating a successful command, if not, send the command again.

I have never seen this response come back even when the command is executed correctly. How do we view this response?

The responses come in on the same MQTT channel as the regular state messages. Best to view with MQTT Explorer in the History of the Blind Tilt’s messages.

Reading or Writing commands to generic BLE devices also comes back with a generic response containing a boolean success key, while the SwitchBot device have a simpler masked response, as they also have simpler actual command formatting.

You should still see the differences of received MQTT messages in the History of MQTT Explorer, between the regular longer state messages containing keys for

open, direction, motion, calibrated, lightlevel, batt

while a successful response message contains

tilt, open, direction

So any messages containing the unique tilt key are responses, but I think I might suggest to additionally also include the success key in the SwitchBots’ responses for an even easier recognition.

As this seems to have been confirmed by teams members with the Blind Tilt, as well as the other implemented SwitchBots, I really cannot stress it enough to recommend deleting and removing the devices from any proprietary app and/or hub, as it definitely wouldn’t be the first BLE device which only plays nicely if completely removed from any app/hub link, while other only do broadcast regular BLE advertising if they are actually paired with the proprietary app, like my Qingping Air Monitor Lites for example :wink:

I would also suggest to make sure to implement a delay to any command things when using a setpoint for value input, or with a slider if using real-time sliders, as not to overload with lots of command messages in succession.

I understand the principle but I don’t have enough experience to integrate this into my openHAB thing. Can you help me on this point?

Do you see the response messages in the MWTT message history in MQTT Explorer now though?

And have you tried removing your Blind Tilt from any proprietary SwitchBot app and/or SwitchBot hub? As I’m still hoping and expecting the direct Bluetooth commands to work reliably once the Blind Tilt is not linked to these any longer.

So response checking should actually not really be necessary on your behalf, as OpenMQTTGateway already impelemnts trying to connect and issue the command several times by itself. So any command failures you are seeing are the result of severlal connection/command failures already. I myself do not do any response success checking for the Bluetooth Lights I have and control thought OMG.

BUT, if I wanted to implement something like this right now, without thinking too much about most efficient way, I’d likely create a proxy switch item needsResending initialised as OFF, and whenever you send a particular command in a rule you also set this proxy item to ON and create a timer to keep checking the state of that proxy item on a regular basis while its state is still ON.

Then creating a thing for the unique tilt key in the response message, or my actual preferred way for certain multi-message type received devices of only having one thing for the whole received MQTT messages, and then using a rule to conditionally assign various item values and testing for the existence of keys, like



if(msg.toString.contains("batt")) {
    batteryItem = Float::parseFloat(transform("JSONPATH", "$. batt", msg).toString) as Number
}




if(msg.toString.contains("tilt")) {
    needsResending.postUpdate(OFF)
}



Then again, this might be my completely round about way, and remember that I do not know any of the more modern possibilities and syntax openHAB 4 might have for things like this, but this really being more of a general OH syntax issue I’m sure some of the pros here might have more efficient solutions for such cases.

@Dom76 How far away is your OpenMQTTGateway ESP32 from your Blind Tilt?
@badhairday How far away are you with your phone when you are having similar issues with the native app?

Could it just be a bad reception issue with the Blind Tilts which could be resolved by placing the ESP32 closer to the device and/or using an external antenna?!?

I did my tests with ‘ESP32 in the same room. I haven’t had time to do a test by disconnecting the blinds from the SwitchBot application yet but I will do it today. Personally I use the SwitchBot HuB and I have no problem with commands with the application when I control a blind directly, only the scenes that control several blinds sometimes do not control them all and you have to restart the scene.