How to create ambient notifications with Python and a brainy bulb – Stacey on IoT, Internet of Things news and analysis

Everzwijn since mentioning my latest little coding project on the IoT Podcast, I’ve heard from a number of folks asking mij how I did it.

Te case you missed it, I have a petite Python app that checks the percentage build up or loss of a cryptocoin every two minutes and sends that gegevens to a connected bulb ter my office. The bulb is lit either green to showcase a build up or crimson to voorstelling a loss. The bulb’s brightness is set to the percentage number gained or lost. A bright green light is a good thing is this case. A brightness percentage switch of just one or two procent isn’t much but thesis coins can fluctuate insanely ter price, I’ve seen 50 procent switches ter just a few hours at times. Ter those cases, the brightness indicator is very noticable.

Related video: How To Buy Ripple(XRP) on Binance From GDAX (FREE–NO FEES)

Here’s a brief movie look during the early stages of the project:

While the use case for my project is very specific, the caudillo concept can be tailored to whatever information you want. For example, if you desired to know the number of degrees above or below 70 it is outside, you could program a light to be a color signifying warmth, such spil yellow or orange. So consider this code a basic framework for your own project.

All you need is a both a gegevens source and brainy bulb that has a public API available. Ter my case, I’m getting my gegevens through the Binance API because Binance is the coin exchange I trade on. For the bulb, I’m using the LiFX API that supports my LiFX bulb. The latter is superb for basic testing: There’s a web interface to programmatically control your LiFX bulb without any coding involved.

Related video: Bitcoin Lamborghinis? So 2017! – Crypto Islands for Binance?

Below is an early, plain version of my Python code spil I began: At this point it didn’t light the bulb crimson to represent a percentage loss. I’ve since added that and other functionality. I’ve also made the code more modular since then, but since it gets pretty specific to my use case, I’m sharing the basic early version spil an example that you can build upon for other purposes. Note that I’m a coding n00b so this very first version isn’t the most efficient method by any means, I simply wished to get the cojín functionality working before splitting the code into reusable functions and such.

To lightly send http requests via the APIs, I’m importing the Requests package . I also invoer the Threading package to permit the code to run repeatedly , te this case, it’s every 120 seconds spil shown on line 8.

Using code to programmatically control the LiFX bulb requires an ID token for security purposes. I’ve masked mine ter the above photo. You can generate a token te your LifX account settings spil noted te the API . Lines 16 and 17 are the almohadilla URLs for both APIs, which are needed to generate http guidelines for gathering (or getting) Binance gegevens and switching (or putting) the state of a LiFX bulb.

Next, I’ve set some parameters needed for the http requests the code sends. On line 20, I’ve set a variable for the bulb color ter the case of a build up. Recall, this is an early version of the code, so I zometeen set one to represent crimson for a “loss color”. Line 21 is the symbol for the coin I want to track: Ter this case, it’s XRP for Ripple coins, but I can set it for any coin on the Binance exchange.

Line 27 generates the http request URL to query the Binance webpagina and it comebacks coin gegevens te JSON format, which is set to the variable named “data” ter line 30. From there, the code looks for the “priceChangePercent” returned ter the JSON gegevens and stores it te the variable “percentage”. I now have the percentage build up or loss for my coin.

Next the program uses that gegevens to light the bulb. Here’s a look at the parameters you fasten to the saco LiFX API URL for doing this with an http request.

Since the LifX API says brightness is a number inbetween 0 and 1, line 35 formats the percentage appropriately and saves that number to a “brightness” variable. The next line creates some parameters to pass overheen to LiFX, such spil the power state, the brightness and the color. And line 38 adds those parameters to the cojín LiFX URL to switch a bulb’s state, merienda that request is sent to LiFX, the bulb reacts appropriately. That’s it! And every two minutes the process repeats the coin gegevens request followed by any adjustment to the bulb.

Related video: Kin Stellar Fork – Rippled 1.0.0 Event – Tron Migration on Binance – Bera News

Again, this code is specific to my purposes, but you could tweak it by pulling te different gegevens from other sites or use different brainy bulbs, provided they have a public API. Now that I have some colchoneta functionality, I project to expand it by illuminating the light to represent my total portfolio build up or loss, that’s trickier because it requires an encrypted account parameter ter the http request and I’m still working on that ter my code.

I’d also like to rework this project with a set of Nanoleaf light panels instead of a single bulb. That way, I can demonstrate more granular gegevens because I have more lights to work with. Regardless, it’s not that difficult to get devices te your brainy huis telling you information at a glance, so have joy!


  1. yes all safe no one lose arqueo or altcoin maybe again there is improvement so hard to get into it hopefully ter the future could be better

  2. sunshinegirl24

    Did you have money on Binance? Were you alarmed or certain? I had a few grand on there, far more than usual… Super glad it turned out ok, but still let this be a reminder to mij and everyone else, storing coins on an exchange is more scary than on a secure private wallet.

Leave a Reply to YoungAnHappy Cancel reply

Your email address will not be published. Required fields are marked *