BRmesh app bluetooth lights

It wasn’t showing up in the device list at all. I managed to get it to though now. So the item is listed as one of the devices in the MQTT integration. When I open it I have the control etc and they appear to work (ie on/off, dim, colours)… I am just not seeing any change on the device itself. I can still control it from the android device, just not from HA.

Also… this is what I got from the Android debug…

jyq_helper: getPayloadWithInnerRetry—> payload:220180000000000000000000, key: 37383836

I am reading that as device = 1 since I think you said it is the second byte. Is that correct?

What happens in the gateway session?
It should show when it receives MQTT commands.
If it does not - check if HA actually sends anything.

so it wasn’t sending anything bc I didn’t have the username/pw set. I got that fixed and now I am seeing the command in the gateway. Still is not commanding the light though. Here is what I see when I try to turn it on for example:

get_rf_payload

addr: c1c2c3
data: 8e3b4d721539b8363738383637383836
inverse_offset: 15
inverse_offset addr.len + 3: 21
Adv-Cmd : btmgmt add-adv -d 02011a1bfff0ff6db64368931ddd0895c88d319cfd0cc44995c36d50f9aa10 1
[ ‘brMesh’, ‘1’, ‘set’ ]
{“state”:“ON”,“brightness”:255}
{ state: ‘ON’, brightness: 255 }

get_rf_payload

addr: c1c2c3
data: 8e384d72153947363738383637383836
inverse_offset: 15
inverse_offset addr.len + 3: 21
Adv-Cmd : btmgmt add-adv -d 02011a1bfff0ff6db64368931ddd0b95c88d3163fd0cc44995c36d50f962e8 1

I see the 37383836 which is my key… maybe the ID is incorrect? The data I got from ADB was:

jyq_helper: getPayloadWithInnerRetry—> payload:220180000000000000000000, key: 37383836

so does that mean my ID is 1 (ie second byte) or is it actually 18? Also is that C1C2C3 correct as the address or does it need to be change for my setup?

ID is 1.

Tell HA to turn off the light.
Then grab the “btmgmt add-adv -d xxxxxxxx 1” string.
Disconnect the light from power. Connect again. Light would turn itself on.
Run this btmgmt … comand in the console. Try twice.
Would it turn off?

ok I got it working. I tried what you said and when I tried to run the command I got permission denied. When I ran the command with sudo it worked. So then I used sudo on the node command for the gateway and I can command it using HA.

Does that make sense that I need to elevate permissions to get it to work? Also now that I have it running in this mode, how do I get it to keep that gateway running all the time? And if it is running all the time is that going to hurt the performance on the HA box?

Thanks for all the help with this!

You can allow non-root users to run btmgmt too.
However the simplies way is just to allow passwordless sudo for a specific command for your user.

Run the gateway in the background with:

There is no extra noticable load intoduced by the gateway.
It idles listenning to MQTT queue, calculates a packet and pushes it to system’s BLE stack to send out.
99.999% of time it is just idle.

seems to be working. Hey another question… do you think there is any way to get this to work with an ESPHome Bluetooth Proxy? I have an ESP32 set up and running with HA as a BT proxy. I use it to extend the reach of the sensors I have. If I could get that to send the BT commands to the light then it would allow me to move them farther away.

Right now the way I understand this is that HA is sending a MQTT command and then your gateway receives and sends out corresponding BT command is that correct? So instead could the MQTT command go to the BT proxy?

It is possible, but someone needs to extend BT proxy on ESPHome to be able to handle and send out advertisment data. Lasrt time I’ve checked it was not implemented. A standalone code for ESP is posted in this thread, someone just needs to integrate it into ESPHome.

Thanks I saw that ESP code but wasn’t sure what it did. So is the idea basically that you would burn take an ESP32 with that code and create a dedicated node to talk to the lights? And does that then replace your gateway code that I am current running on the HA box?

If so then that is probably what I am actually looking for. Does that code just connect to one light though or could you connect to multiple?

That ESP32 code is basically the gateway, just needs networking (WiFi) and MQTT added.

I have an ESP32 EVB but don’t know enough about it to get it compiled to flash onto the device. I would love to test it out and see if I can get it going but are there any instructions I can follow on how to take his code and convert it?

So I have lights that are controlled by the BRMesh app, but I am running HA in docker and the MQTT and other are in docker as well. Would I have to install nodejs on the HA docker image in order for this to work? I have the meshID from the debugger so am looking for any guidance.

You can run the gateway in a separate docker container or on the host itself.
There are both nodejs and python version.
Python version requires more efforr (recompiling BlueZ), but talks to bluez stack directly.
Nodejs ver relies on calling system’s btmgmt app every time it wants to send smth out.

You can run any of those in a separate container (given you expose bluetooth stuff correctly) or on the host system.

I have the script running on the host and I think HA is connected properly. When I try and turn the light on from HA I get the following error:
[ ‘brMesh’, ‘2a’, ‘set’ ]
{“state”:“OFF”}
{ state: ‘OFF’ }
brightness: 0

get_rf_payload

addr: c1c2c3
data: 8e344ae11a3730313837303138373031
inverse_offset: 15
inverse_offset addr.len + 3: 21
Adv-Cmd : btmgmt add-adv -d 02011a1bfff0ff6db64368931ddd07925b823f14fa03cb4192cc6258fe0a4b 1
node:events:489
throw er; // Unhandled ‘error’ event
^

Error: spawn btmgmt ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted ‘error’ event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:291:12)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: ‘ENOENT’,
syscall: ‘spawn btmgmt’,
path: ‘btmgmt’,
spawnargs: [
‘add-adv’,
‘-d’,
‘02011a1bfff0ff6db64368931ddd07925b823f14fa03cb4192cc6258fe0a4b’,
1
]
}

Also very excited to see all the progress on this. Had the lights for over a year, and I’m just trying to figure out how o get all this working. Got my info from adb. Now just struggling with a similar question I see some folks are asking: How do I go about running a NodeJS script, and more specifically, how would I go about setting up NodeJS on the HA Host? I’m running HA on a VM using Virtual box. Any assistance is greatly appreciated.

whatever the OS is for the VM running your HA instance, install Noejs and then just run the node .js to run it. Yo can then run it in the backgorund if all is working

Check if you have btmgmt installed and available.
Check if you run the gateway under local user, who has permissions to run btmgmt and has permissions to use bluetooth.
Either set correct permissions or run as root.

Tried a few approaches but haven’t been able to figure it out. Note, I’m using HASS Operating System - control at the OS level is limited. If anyone has got NodeJS running in HASSOS, could you kindly share some steps I could follow?

I did manage to get it running fine using the gateway running on my HA machine. Where I want to put the lights though is far away so still trying to sort out a good way to get the gateway to run via a separate ESP device sitting on my network. It is too bad that no one has created an actual HA integration for this stuff yet. It seems like these Bluetooth mesh lights are getting more popular these days.

The only thing: they are not actually a BT mesh.
It is fake advertisment.
These lights do not create a mesh and are unable to re-transmit packets.