#Coding4Fun – #RaspberryPi LED Christmas Tree 🎄 sync with #MicrosoftTeams (1/N) Why? Why not !

Buy Me A Coffee

Hi !

So I was preparing boxes with gadgets I have for our next house move, and I realized that I had a super cool Led based Christmas Tree, that can be used with a Raspberry Pi. The device can be programmed with Python, so I decided to go in my notes and I found something different to test the tree:

Sync the Tree Lights with my Microsoft Teams Status

Something like this !

After Build 2020, I have some notes from Scott Hanselman and Isaac Levin, which explains a way to start with this, please see references.

Note: Isaac Presence Light app does 90% of the work, kudos to him here!

So, I decided to start easy and create a simple Python Flask WebApp with the following end points

  • setcolor (color as parameter)
  • off
  • on
  • away
  • online
  • busy

Microsoft Teams supports much more states, but this ones are good enough for me to test the app.

The app is super simple, here goes the code

# Bruno Capuano
# simple webserver with flask
# change raspberry pi tree colours

from flask import Flask, request                                                
from tree import RGBXmasTree
from time import sleep
from colorzero import Color

def set_tree_color(new_color):
    global tree
    print(f'set color: {new_color}')
    tree.color = Color(new_color)
    return new_color

app = Flask(__name__)
tree = RGBXmasTree()

def set_color():
    # http://rpi8gb:8090/setcolor?color=red
    color = request.args.get("color")
    return set_tree_color(color)    

# Microsoft Team Status

def set_off():
    global tree
    return 'OK'

def set_on():
    global tree
    return 'OK'    

def teams_away():
    return set_tree_color('yellow')

def teams_online():
    return set_tree_color('green')

def teams_busy():
    return set_tree_color('red')

if __name__ == '__main__':
    # Run the server
    app.run(host='', port=8090)

And, time for settings and config in the Presence Light App (next post more details about this). My device name is RPI8GB, so you can understand the Custom API Uris.

Presence Light config for Raspberry Pi Christmas Tree

And it was running !

More details and a better experience in future posts.

Happy coding!


El Bruno


Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.