My teenage son streams on Twitch, and he used to get annoyed at me interupting him while he was live on stream. So I decided to see if I could use an ESP-01 to solve this problem, it has a couple of GPIO pins so turning a relay on and off shouldn't be an issue. I'd seen some laser engraved perspex "On Air" signs on eBay and thought it would be cool if I could make it switch on automatically when ever he started streaming, and off again once he fnished. I could then place it above his bedroom door and I'd know to either come back later, or enter quietly if it was important.

Twitch has a streaming API which you can request various status updates and information from. Once you have signed up for the Developer program and registered an app on their developer portal, you can start using it to make requests.<Twitch_User>

This returns details of the selected users current stream, if there is no stream then the data it returns is blank:


We can use this as a Streaming Status, if there is data then the light should be on, if the data is blank then the light should be off. A simply python script can do this and can control the GPIO Ports. Twitch have recently switched to OAuth and as a result you need to request an access token before making any requests, and also keep that Access Token up to date, OAuth is reasonably straight forward so I added this to the previous script once they introduced it. The main part of the script is here, this does all the status checking, and GPIO switching:


Once I had the script working I designed a small circuit on breadboard to control the relay:



This worked well and I then transposed it on to a piece of vero board to make it much neater, there is a 3v3 voltage regulator for the ESP-01, a small capacitor and then the relay: