MQTT-Controlled Astronomical Smart Bulb (Smitch -> Tasmota + Python)

by ArijitKumar in Design > Software

50 Views, 0 Favorites, 0 Comments

MQTT-Controlled Astronomical Smart Bulb (Smitch -> Tasmota + Python)

91ec5fcb-bcc1-49a0-b09e-1c39d0fdbfbf.png

The Indian Smart bulb - Smitch which was created by IoT-Monks primarily operated via the Smitch app, which required the user to be logged in to the Smitch server. With the company suddenly closing down and the servers not accessible anymore, all owners of the Smitch smart bulb had no choice but to abandon the bulbs, since it could not be even switched on or off anymore.


To prevent adding it to the increasing pile of e-waste, in this tutorial, we will be first flashing a firmware - Tasmota, which makes it independent of any cloud or server. Secondly, we will utilize the newly flashed bulb for some automation action which will turn the bulb on/off and follow the cicardian rythm of the human body based on the local sunrise/sunset. Also, for the enthusiasts, we have implemented a way to track the passes of International Space Station, all of which are based on MQTT commands to the bulb from a Raspberry Pi Zero 2W.


Turn an abandoned cloud smart bulb into a locally controlled, astronomy-driven light that follows the Sun daily and briefly comes alive when the International Space Station passes overhead — all without accounts, apps, or external servers.


This project uses:

  1. A reflashed ESP-based smart bulb (Tasmota)
  2. A local MQTT broker
  3. Two small Python scripts

Everything runs locally. If the internet disappears, the light still knows where the Sun is.


What This Bulb Does

Channel 2 (White / CT)

  1. Simulates sunrise and sunset using real solar times
  2. Slowly ramps brightness and color temperature over hours
  3. Settles into a low, warm moonlight mode at night

Channel 1 (RGB)

  1. Activates only when the ISS is above your horizon
  2. Color represents the ISS direction (azimuth)
  3. Brightness represents how high it is in the sky (elevation)
  4. Temporarily overrides the normal lighting

A simple file-based override lets you pause automation instantly.

Supplies

img.jpg
RPiZ2W.jpg

Hardware Requirements

  1. Any ESP8266 / ESP32 based RGB or RGB+CCT smart bulb
  2. Wi-Fi network with local access
  3. A Linux system (Raspberry Pi, mini PC, NAS, etc.) running 24/7
Many discontinued or cloud-dependent bulbs work perfectly once reflashed.

Flash Tasmota on the Bulb

There are many ways to flash ESP-based bulbs. In this case, the bulb exposed a built-in web updater, making the process much simpler.

Updating the Bulb Firmware

If you want to flash custom firmware (for example, Tasmota) to the bulb, follow these steps.

Step 1: Access the Firmware Update Page

  1. Open a browser and navigate to:
http://<bulb-ip>:1336/update
  1. Enter the following credentials:
  2. Username: admin
  3. Password: c21pdGNo

Step 2: Flash Tasmota Minimal Firmware

  1. Download the Tasmota minimal firmware from the official repository:
http://ota.tasmota.com/tasmota/release/tasmota-minimal.bin.gz
  1. (If the download does not start, long-press the link, copy it, and paste it directly into the browser address bar.)
  2. Upload the firmware file using the update page.

Step 3: Update to Full Tasmota Firmware

  1. After the minimal firmware finishes flashing, navigate to:
http://<bulb-ip>/up
  1. Download the full Tasmota firmware:
http://ota.tasmota.com/tasmota/release/tasmota.bin.gz
  1. Upload the full firmware file.

After reboot, the bulb will be running full Tasmota and ready for MQTT configuration.

Configure Bulb

Before your Raspberry Pi scripts can control the solar light, the bulb itself needs to be set up correctly. Follow these steps carefully:

1. Apply the Template

  1. Open Blakadder Templates.
  2. Copy the template for the Smitch SB161001-B22:

{
"NAME":"Smitch SB161001 - B22",
"GPIO":[0,0,0,0,416,419,0,0,417,420,418,0,0,0],
"FLAG":0,
"BASE":18
}
  1. Paste this template into your bulb’s configuration (Tasmota Web UI → Configuration → Configure Template).
  2. Click Save and let the bulb restart.

2. Enable MQTT

  1. Go to Configuration → Configure MQTT in the bulb interface.
  2. Set the following values:
  3. Host: IP address of your Raspberry Pi (for example, 192.168.1.50)
  4. Port: 1883
  5. Topic: sunbulb (or any consistent name — make sure your scripts use the same topic)
  6. Client ID: leave default or set something unique
  7. Click Save and allow the bulb to restart again.

3. Allow External Connections

  1. By default, the Raspberry Pi (and Tasmota) listens only on localhost (127.0.0.1).
  2. Change the MQTT/Web settings so the Pi listens on all interfaces (0.0.0.0). This allows your scripts to communicate with the bulb from the network.

4. Verify the Connection

  1. On your Raspberry Pi, you can test MQTT connectivity with:

mosquitto_sub -h 192.168.1.50 -t sunbulb/# -v
  1. If configured correctly, you should see messages when the bulb state changes.

Tips:

  1. The MQTT topic you set here must match exactly with the topic in your scripts (sunbulb in my case).
  2. Once these settings are saved, your Raspberry Pi scripts will be able to smoothly control the light during ISS passes.

Set Up MQTT on Raspberry Pi

Install a local broker (example using Mosquitto):

sudo apt install mosquitto mosquitto-clients

Test MQTT manually:

mosquitto_pub -t cmnd/sunbulb/Power -m ON

The bulb should respond immediately.

State Tracking (Important)

Create a small MQTT subscriber that listens to Tasmota stat/ topics and writes the latest state to:

/tmp/sunbulb_state.json

This prevents unnecessary MQTT spam and keeps scripts state-aware.

Solar Lighting Script (Channel 2)

Color.png

solar_light.py

This script:

  1. Calculates sunrise and sunset using Astral
  2. Ramps brightness and CT smoothly
  3. Avoids Dimmer=0 to prevent accidental shutdown

Key parameters:

PRE_LIGHT_MINS = 90
POST_SUN_MINS = 30
EVENING_MINS = 210
DIM_MAX = 100
DIM_WORKING = 15
DIM_MOON = 2

Run this script periodically (cron every 1–5 minutes).

ISS Tracking Script (Channel 1)

iss_bulb.py

This script:

  1. Downloads and caches ISS TLE data
  2. Computes real-time azimuth and elevation
  3. Maps direction → hue, height → brightness
  4. Temporarily disables channel 2 via a lock file

When the ISS sets, normal lighting resumes automatically.

Manual Override

Create a file to override automation:

echo ON > /tmp/sunbulb_override # manual mode
echo OFF > /tmp/sunbulb_override # force lights off
rm /tmp/sunbulb_override # resume automation

This works instantly and does not rely on MQTT or apps.

Automation Scheduling

Use cron to run both scripts:

*/2 * * * * python3 solar_light.py
*/1 * * * * python3 iss_bulb.py

Adjust frequency based on preference.

Why This Works Long-Term

  1. No cloud services
  2. No accounts or logins
  3. No vendor lock-in
  4. Fully inspectable and modifiable

The bulb will continue to work as long as the Sun rises and the ISS orbits — both are expected to be stable for some time.

Possible Extensions

  1. Add Moon phase brightness
  2. Log ISS passes via MQTT
  3. Integrate with Home Assistant
  4. Use weather data for cloud-adjusted lighting

Conclusion

This project turns a discarded smart bulb into a local, astronomy-aware lighting system. It demonstrates that the hardware was never the limitation — firmware and control philosophy were.

If a device can be reflashed, it can be rescued.