Project: Smart Bulb Cop Car

Hello! Welcome 🙂

Today I would like to show you how to build a straightforward project which will imitate a police car with light and sound.

I want the projects here to be fully aligned with KISS policy – so I’ll Keep It Simple…

But then, I’ll extend the project into another one:

Fake TV Simulator – Turning police car into an anti-theft toy to discourage intruders/burglars

So let’s start with this one!

My Gear

My gear for this project includes:

2 Smart Bulbs
I’m using Yeelight LED BULB II (Color), and I can strongly recommend them. The control is convenient, deployment is effortless, and I believe they are trustworthy.

1 Bluetooth speaker
can be any, but I got for one
of my many journeys, JBL GO. The quality of the sound
is good, and the battery
is durable.

Raspberry PI 4B
Last but not least – I need some platform to run this project. It’s unnecessary for this one, but it will be mandatory for this one presented in the introduction, so setting it up on this level will save some time in the future.

So, my whole set looks like this:

All devices used for this project 😉

RPi – prerequisites

As promised, I will use RPi as a platform to run the whole code in this project. So I assume that your RPi is appropriately configured, it’s up-to-date, etc.
I don’t want here to waste time describing how to do it; it can be easily found on the Internet 😊

I will use RPi 4B to connect to my Wi-Fi, which I can control via VNC protocol, so the whole configuration and screenshots show this perspective.

However, if you don’t want to use RPi to emulate my project, it can still be done on a regular PC.

Bulbs Preparation

I don’t want to get through the installation in detail – this is elaborated in the instruction, and the wizard is intuitive. But, just a quick overview:

  1. Before you start, place the bulb into the proper lamp (with E27 socket)
  2. Download the Yeelight app on your Android/iOS device from the appropriate store.
  3. Turn Wi-Fi and Bluetooth on
  4.  Go to Devices, then click Add Device and select the proper device.
  5. Then follow the instruction (for the time being) to turn on a light for 2 seconds, then turn off for 2 seconds and repeat it four times. After that, your light bulb should be restarted and switched on with white light.)
  6. Press Next, Find your Lightbulb on the list, and finish with the wizard.
  7. Check if the firmware is up-to-date. If not, update it.

So after these easy steps, my setup for two bulbs looks like this:

My device card

The final step for using Bulbs in this project is to turn ‘developer mode’ on, called ‘LAN Control.’ To do this:

  1. Go to your devices page
  2. Open context menu from the left and press ‘LAN control’:
Swipe from left to right
  1. Switch it on like this:
Make sure LAN Control is switched on

Now your Bulbs are correctly installed and if you are curious about them, spend some time to discover their options 😉

Connecting the speaker

To connect the speaker to my RPi, I will use the default Bluetooth manager. To do that for the first time, I need to:

1. Click the Bluetooth symbol and Turn On the Bluetooth

2. Then click ‘Add Device….

Adding device
  1. The adding device window will prompt.
  2. I’ve found my device on the list (mine is JBL GO), so I select it and click ‘Pair.’
Pairing prompt
  1. After a while, I got the confirmation that the Pairing was done correctly:
  1. Now my devices are paired. Next time when I want to use the speaker, I will start with this step.
  2. To connect to the speaker (or any other Bluetooth device), we need to click on the Bluetooth button, then select the name on the device and click ‘Connect’
That doesn’t mean it’s working…
  1. Sometimes I got ‘connection failed’ message:
  1. To work around, I will use the audio menu to connect the speaker:
But here is a workaround
  1. I’ve heard the ‘beep’ meaning that the speaker is connected, and the icon in the Bluetooth manager changed icon:
Now working 😉

I always check with any YouTube clip to double-check if everything works perfectly. If it works, we are ready to go further.😊

If you are not using RPi to recreate this code, please connect your Bluetooth speaker to your environment and make sure it works properly. 😉

Connecting the Bulbs

To control our bulb, using Python yeelight library is required.

So with a pip, we need to use:

pip3 install yeelight

Now we need to discover the IPs of our bulb. We can do it by:

  • checking manually in bulb’s settings
Device info in Yeelight App
  • or we can use yeelight library
from yeelight import discover_bulbs

Which is not always working correctly…

Once found, we can check if we can steer our Bulbs with python code.

Here is a simple example:

from yeelight import Bulb
from time import sleep
bulbR = Bulb("") #make to provide correct IP address
bulbL = Bulb("")

If you managed to turn off the lamps for 5 seconds and then they turned off, everything works like a charm 😉

Note: Interacting with Bulbs is done via a cloud provider. They can only accept 60 quotes per minute. It’s going to be important in the final part.

Playing the sound

I decided to use the python-vlc library to play the sound from many others because the vlc player is already preinstalled in my Raspbian distribution. After reviewing some manuals, it was one of the top up-to-date solutions.

I was also considering using pygame, a lovely library designed for games development, but installing and importing whole sets of modules designed for writing video games would be taking a sledgehammer to crack a nut.

So let’s use python-vlc. Sticking to the instruction, we need to start with installing the module:

pip3 install python-vlc

Then I’ve found a brief article about: How to Play Audio With VLC In Python

While I would like to ’emulate’ Police Car, I need a good sound. I’ve found a few of them on, and the police2.wav created by guitarguy1985 appeared the most for me. You can find it: Here, and yes, login to download is required, but if you don’t like it, you can use a different sound instead. Simple code to play the .wav looks like this:

import vlc 
file= 'police2.wav'
player = vlc.MediaPlayer(file)

Sometimes we can get strange error code to look ugly, but then the code is still working (vlc plays the file):

error while running wav

I’ve found a small workaround by changing the vlc verbosity to -1. Now the code looks like this:

import vlc 
import os
os.environ['VLC_VERBOSE'] = str('-1')
file= 'police2.wav'
player = vlc.MediaPlayer(file)

Getting it all together

My goal was to ‘act’ a police car using two lightbulbs and a speaker. Now we have the speaker in place, we can play sounds and communicate with Smart Lightbulbs.

So we have to build a code that will:

  1. play a sound of ‘police sirene’
  2. change their brightness of ‘police lights’
  3. simultaneously change lightbulb colors to make them blink

Let’s import everything that we need: yeelight for bulbs, vlc & os for playing music without errors, and time for sleeping the code.

We have to keep in mind that bulbs accept only 60 requests (total, not each) per minute, so I’ll define some interval to keep things in order and add some prints to make it more ‘gangsta’:

from yeelight import Bulb
from time import sleep
import vlc
import os
os.environ["VLC_VERBOSE"] = str("-1")
interval = 0.5
file = 'police2.wav'
player = vlc.MediaPlayer(file)
bulbR = Bulb("")
bulbL = Bulb("")
print("Put your hand's in the air!")

The main loop is used to change the brightness and color of the bulb in a state-machine way (obviously, self-describing):

for i in range(0,4): sirene and changing state
    bulbL.set_rgb(0, 0, 255)
    bulbR.set_rgb(255, 0, 0)
    bulbR.set_rgb(0, 0, 255)
    bulbL.set_rgb(255, 0, 0)
    print(f"***Siren {i+1}***")#we are counting sirenes

Unfortunately, after four sirens, we got busted ☹, so we had to clean and turn off the lights:


Final show:

Here is a final show

And the ‘gangsta’ output:

And the result is presented on the screen.

And that’s it for today 😊

Source code for this project on my Github: HeadFullOfCiphers/SmartBulbCopcar

I hope you liked this little project, and if you want to check what the project evolved to or what was also developed in the process of creating this material, you can read:

  1. Fake TV Simulator – Turning police car into anti-theft toy to discourage intruders/burglars
  2. Simple Python Ex-If remover
  3. Handy Android EXIF Cleaner

Reference list:

  2. Python yeelight library readthedocs
  3. Python-vlc library docs
  4. How to Play Audio With VLC In Python
  5. Police2.wav sound from

Check out related posts:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: