- Integrates Twitch chat with Tuya smart bulbs so viewers can change light colors and power state.
- Uses the Tuya Cloud API for device control and OAuth token management.
demo.mp4
src/main.rs: bootstraps the application, creates theTwitchClientandTuyaClient, and enters the main receive loop.
mod bulb;
mod clients;
mod settings;
mod token;
mod twitch;
#[tokio::main]
async fn main() {
let settings = default_settings();
let mut twitch = TwitchClient::new(&settings);
let tuya = TuyaClient::new(/* client id, secret, base url, ... */);
// ... request token, check online devices, and loop receiving events
}src/clients/twitch_client.rs: connects to Twitch EventSub, translates chat events into responses, and delegates bulb actions to the Tuya client.
pub struct TwitchClient {
api: TwitchEventSubApi,
last_color_change: Option<Instant>,
}
impl TwitchClient {
pub fn new(settings: &Settings) -> Self {
let keys = get_twitch_keys(settings);
let builder = create_twitch_builder(keys);
let api = build_twitch_connection(builder);
twitch_tokens_to_settings();
Self { api, last_color_change: None }
}
}src/bulb/color.rs: converts CSS color names to HSV and sends signedcolour_data_v2commands to Tuya devices (HMAC-SHA256 signing per request).
pub async fn bulb_color(
base_url: &String,
client: &reqwest::Client,
client_id: &Option<String>,
secret: &Option<String>,
devices_ids: &[String],
sign_method: &String,
access_token: &Option<String>,
color_name: &str,
) {
// lookup color, convert to HSV, build command body, sign, and POST to Tuya
}These snippets are small excerpts; see the real implementations in src/main.rs, src/clients/twitch_client.rs, and src/bulb/color.rs.
- Head over to Tuya Developer Platform
- Go to the
Cloudtab and click onCreate Cloud Project
- Fill in with the following information:
- Select this options:
- In the
Overviewcopy yourAccess ID/Client IDandAccess Secret/Client Secret. - Head over to the
Devicestab, and click onAdd Device - Copy the
idof each device (light bulb)
- Head on over to Twitch Dev Platform
- Click on the
+ Register your applicationbutton:
- Fill out the form with something similar to this:

- Then click click on the
Managebutton - Here you will need to copy your
Client IDand request a newClient Secret:


