The Smart Room Control System is a Python-based application that manages various devices in a room, including lights, led strips, sensors, and more. The application is based on a "room manger", which routes all traffic and provides a database for all app to seamlessly sync variables, even if they are not directly connected, this means that every module in this app could run a on a different machine without any issues. This app is build around MQTT and ArduBridge.
The smart-room is a project I have been working on for the past few years and this is the public release of it. Due to my project having many private files committed and pushed over time, I am unable publish it and instead, I had to clean it up and publish it under a different repo.
-
Light Control: Adjust brightness and toggle lights using buttons, remote control, or MQTT commands.
-
Camera security system.
-
Double clap for turing lights on/off
-
Automatic shutoff of lights once you leave the room.
-
Led strip for more efficient lighting.
-
Remote gui that works on windows, linux, and even android.
-
MQTT Communication: Receive and process commands from specified MQTT topics. Log events and send updates via MQTT.
-
Arduino Integration: Connects to Arduino for hardware-level interactions such as GPIO control and PWM output.
- MG90S Servo
- Single pole light dimmer
- Metal rod (straightened paper clip)
- Linkage Stopper
- Light switch cover (3D printer file supplied in the CAD folder, if no 3D printer is available, you will just have to glue the servo to the light switch cover)
- Light Switch-to-Servo connector (3D printer file supplied in the CAD folder, if no 3D printer is available, you will have to again, use glue)
- WS2812B Led Strip (I am using and tested BTF-LIGHTING LED Strip)
- Strong power supply
Any windows, linux, mac, or android device. My GUI attachment has been designed for the YQSAVIOR Q2 Tablet
git clone https://github.com/TzurSoffer/smart_room_pub.git
cd smart_room_pub
sudo docker build -t smart-room .
Run the command sudo docker-compose up -d
to start the room.
- For windows, you can follow this guide.
- For linux, you can follow this guide.
- NOTE: not every linux machine uses the same network manager, and if the guide does not work for you, please search up how to setup a static ip on your specific flavor of linux.
- NOTE: This it not the best method for setting up a static ip, it will always be better to set it up through your router.
git clone https://github.com/TzurSoffer/smart_room_pub.git
cd smart_room_pub
pip install -r requirements.txt
- if on linux, then also run the commands
sudo apt install -y portaudio19-dev
for clap-detector deps.
- For windows, download and install an mqtt broker from https://mosquitto.org/download
- For Linux, run
sudo apt install -y mosquitto
to install mosquitto.
- For windows, you can follow this guide.
- For linux, you can follow this guide.
- NOTE: not every linux machine uses the same network manager, and if the guide does not work for you, please search up how to setup a static ip on your specific flavor of linux.
- NOTE: This it not the best method for setting up a static ip, it will always be better to set it up through your router.
- Take an official arduino uno (Revision 3 has been tested), and connect it via usb to the rpi. If you have already flashed it with the correct firmware, it should automatically be detected by the software and start flashing an LED after the smart-room has been started. If you did not flash it with the firmware, please look below at the flashing section.
- for linux, run this command:
python -c "import serial.tools.list_ports; [print(f'Port: {port.device}, Description: {port.description}, HWID: {port.hwid}') for port in serial.tools.list_ports.comports()]"
- for windows, go to device manager and find your arduino under the COM ports section.
- Once you found your arduino's port, put its port into the settings file under the
arduComport
variable. ex.COM7
for windows or/dev/ttyACM0
for linux.
- In the
settings.json
file, change thearduFirmwareNoPromptUpdate
variable totrue
. This will flash the arduino with the correct firmware on start of app. Then simply start the app usingsudo docker-compose up -d
, and after a bit, the arduino LEDs should turn on for a few seconds, then stop, then begin flashing. This is how you know the arduino has been flashed and the room is running.
- Connect your Arduino device to a system.
- Follow instructions from GSOF_ArduBridge to flash the arduino with the correct firmware.
- Print the lights cover file and the light cap file.
- Replace you existing light cover with the printed one.
- use a bit of hot glue to connect the light cap to the light switch.
- Insert the servo into its slot.
- Screw the linkage stopper to the cap.
- connect your metal rod between the arduino and the cap.
- connect the servo to the correct arduino pin (defaults to pin 11 in the core's config).
- Connect your LED strip's power cable to an external power supply, the ground to the arduino's ground and the data pin to the correct data pin on the arduino (defaults to pin 13 in the room manager's config)
- Change the
ledCount
variable in the room manager's config to the correct LED count.
- For running on a windows, linux, or mac simply install the requirements using
pip install -r requirements.txt
, then run themain.py
python file. - For running on an android device such as a tablet or phone, I have provided the compiled apk file in the bin directory, simply copy the file to your android device, and install it via your file manager or adb.
This GUI has multiple pages each designed for its own section of the room. To switch between pages, click on the page you want from the left hand side of your device and the app will switch your page. To get into the admin panel, click it and input the password.
-
Once you have developed your module and want to use incorporate into your room, you need set it up in the settings file of the roomManager. Note, make sure you are using the
mqttCommunication.py
file and not the regularpaho-mqtt
for sending messages to the server.- in the features key of the setting, add a new entry following this pattern:
"inputTopic": { "commands": { "msgContent": "commandCallback", "msgContent": "commandCallback" } }
replace
inputTopic
with the topic that your module will send messages to,msgContent
with the content of the message that gets sent, andcommandCallback
with the command you want to call (commands are also specified in the settings file).- If needed, add a command to the settings file. To add a command, add a new entry in the commands section of the settings following this pattern:
"commandName": { "command": "commandType", "cmdKey": "cmdValue", "cmdKey": "cmdValue" }
replace
commandName
with the name of the command (commandCallback
if following instruction from previous step),commandType
with the type of command, your options are betweensendMessage
, andrunCommands
, lastly replace cmd cmdKey with the expected keys for said command and command value with a value.If adding a
sendMessage
command, follow this syntax:"commandName": { "command": "sendMessage", "topic": "yourTopic", "message": "yourValue" }
If adding a
runCommands
command, follow this syntax:"commandName": { "command": "runCommands", "commands": ["cmd1", "cmd2", ...], }
- Follow the previous step for setting up a command, except you want to set the commands topic to be the topic you are listening on.
- Set up a feature that redirect the traffic that you want to receive to the command you made.
Use the database.py
module from the modules folder and create a new instance, then simply pretend your wanted variable exists, and once you try and access it, it will fetch it in the background.
db = DatabaseClient("brokerIp")
db.a = "anything"
print(db.a)
you can now close the program or just run in on a different machine, once you try and fetch the variable a, it will still be the value of what you last set it.
This project is licensed under the MIT License. See the LICENSE file for more details.
Developed by Tzur Soffer (2021-now).