#Coding4Fun – #RaspberryPi LED Christmas Tree sync with #MicrosoftTeams (1/N) W...
source link: https://elbruno.com/2020/12/17/coding4fun-raspberrypi-led-christmas-tree-%f0%9f%8e%84-sync-with-microsoftteams-1-n-why-why-not/?utm_campaign=Feed%3A+elbruno+%28El+Bruno%29
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
#Coding4Fun – #RaspberryPi LED Christmas Tree sync with #MicrosoftTeams (1/N) Why? Why not !
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)
- online
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()
@app
.route(
"/setcolor"
)
def
set_color():
color
=
request.args.get(
"color"
)
return
set_tree_color(color)
# Microsoft Team Status
@app
.route(
"/off"
)
def
set_off():
global
tree
tree.off()
return
'OK'
@app
.route(
"/on"
)
def
set_on():
global
tree
tree.on()
return
'OK'
@app
.route(
"/away"
)
def
teams_away():
return
set_tree_color(
'yellow'
)
@app
.route(
"/online"
)
def
teams_online():
return
set_tree_color(
'green'
)
@app
.route(
"/busy"
)
def
teams_busy():
return
set_tree_color(
'red'
)
if
__name__
=
=
'__main__'
:
# Run the server
app.run(host
=
'0.0.0.0'
, 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.
And it was running !
More details and a better experience in future posts.
Happy coding!
Greetings
El Bruno
References
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK