LEGO DUPLO train control with esphome

@JWL98, @anthonyangel, @vrutkovs, @arehsan, @Lumpusz

Very cool that you guys figured this out, amazing.
I am trying to wrap my head around this, but still a bit puzzled:
How do you guys know what values to enter for:

  • ble_clients mac_address and id
  • service_uuid
  • characteristic_uuid
  • the value of the bytes to write

thanks up front for the help,

Br,

Raymond

service_uuid and characteristic_uuid are hardcoded values LEGO uses in the train to identify data. These will not change. Same for bytes to write - this is the protocol we should follow.
MAC address and ID can be detected using ESP32 Bluetooth Low Energy Scanner — ESPHome

Thank you very much for your response.
Makes things a lot clearer.
Do you know any esphome yaml files to use to get that data?
Do I need to push any buttons on the Lego hub to activate communication?
Can the values to send be found in the official Lego api docks?
Sorry for all the questions :grin:
Trying to fully understand.
I have never used BLE with HA or esphome.
Best regards,
Thanks upfront,
Raymond

Do you know any esphome yaml files to use to get that data?

You may want to start with ESPHome Tutorial at Getting Started with ESPHome and Home Assistant — ESPHome first

Do I need to push any buttons on the Lego hub to activate communication?

I don’t think Lego hub is needed, at least I don’t have one

Can the values to send be found in the official Lego api docks?

I don’t know tbf, quite possibly these are extracted from the docs indeed

I am a bit puzzled :slight_smile:
How are you connecting this all to Lego if you don’t have a hub?
With a hub I mean: Lego part 88009
thanks again
br
Raymond

ESPHome runs on a microcontroller which has BT, so it can connect to the train directly

Thanks I got that part :smiley:
I was talking about the ā€˜Lego-side’
You still need a hub as linked above in the Lego train, or am i misunderstanding things?
Br

Hi, I am trying to figure out a way to use this to turn an esp32 in a remote controller for that lego train… how do you generate the payload bits? is there a tutorial, because I simply don’t get it… how do you determine which value to use? I read the Lego Wireless Protocol docs on git but I think I am missing something… e.g to get that motor running… i figured out I need the section 3.27 Output Command 0x81 - Motor Sub Commands. I also figured out that I have to convert the PWM duty cycle to hex… but what is with the rest of the command values, where do I get them from?

thanks upfront

Hi, @JWL98,
Congrats, the project is awesome!!
How do you learn the bluetooth codes of the buttons that you replicate later to send to the train?
Thanks,
Miguel