Run a Python script from the RB4

Hello everyone,

I’m new to the Gladys project, which I’ve been watching from afar for a few years.
This is an assistant I would like to use, but under certain conditions.
I have a nice wooden desk with semi-transparent white epoxy resin that contains a strip of addressable LEDs.

I’m about to order an RB4 to install the assistant on it, but I need to know if it’s possible to create a scene that would run a Python script directly from the RB?

Indeed, since these are addressable LEDs, the command is a bit different (after reading the component’s datasheet, I estimated that using the board’s PWM would be very practical), which is why I would need Python to manage all this.

Additionally, I have a small electronic model that manages power, and I don’t want to put it on the network as this would require the purchase of additional compatible communication equipment… The goal is to control the pins (always via a Python script)

Is this feasible?
Thanks in advance,
Matt

Hello @MattDudu and welcome to Gladys :slight_smile:

You can definitely do this with the MQTT integration.

You can create an « MQTT » device of type « light » in Gladys, and give it the characteristics it has (on/off + brightness + color for example), and Gladys will provide you with MQTT topics to listen to in your Python script.

Then on the Python side, you need to use an MQTT library to connect to the MQTT broker and listen on the topics provided by Gladys.

Every time the state changes on Gladys, a message will be published on the MQTT topic and you will receive the message in your script :slight_smile:

Don’t hesitate if you have any questions

Hi @pierre-gilles :slight_smile:

Thanks for your quick reply, I’ll have to look into the MQTT API then, noted!
This reminds me of an OS called ROS (for Robot Operating System that I used on a robot at school to make the different peripherals communicate with the same subscription system to topics, so in the idea I see how it works)

But it’s still quite vague in my mind, the « famous » .py will be well stored on the raspberry?
Because I imagine that when the RB starts, it directly launches the Gladys interface (if we imagine that we are on the HDMI output)? Or is it always an interface like the Rasbian desktop?

Thanks in advance =)
Matt

It’s accessible in your browser, Gladys is just a Docker container running on Raspbian Lite (no desktop environment).

You can do whatever you want on the OS (Python) independent of Gladys (since Gladys is isolated in a container).

Got it, I understand now, it’s perfect then :smiley:

In this hypothesis, we are therefore in agreement that the RB can itself be considered as an MQTT device? And if we push the theory a bit, several « devices » (which could control different PINs) can be described in different Python scripts? (With 1 script = 1 device)

Thanks for your help and explanations!

Matt

That’s the principle of everything on the same machine, you can start with that.

If you want to push the system further and have multiple Raspberry Pi, you need to:

  • check that the MQTT broker has its ports open (this is the case with Gladys)
  • check that the other Raspberry Pi can contact the MQTT broker
  • properly manage the different MQTT Topics in each Python script (installed on each RPI)

I recommend some documentation:

https://www.framboise314.fr/utiliser-le-protocole-mqtt-pour-communiquer-des-donnees-entre-2-raspberry-pi/

@cicoub13 Wow, thank you so much for all these explanations, it’s much clearer now!

This is super interesting, I’m going to go ahead and make a purchase and then experiment with all of this :wink:

Thank you all again :heart_eyes: