I was recently introduced to PresenceLight via my Microsoft Home Assistant friends.
PresenceLight is a solution to broadcast your various statuses to various kinds of smart lights. Some statuses you can broadcast are: your availability in Microsoft Teams or color of your choosing. There are other solutions that do something similar to sending Teams Availability to a light, but they require a tethered solution (plugging a light into a computer via USB). What PresenceLight does is leverage the Presence Api, which is available in Microsoft Graph, allowing to retrieve your presence without having to be tethered. This could potentially allow someone to update the light bulb from a remote machine they do not use.
When I investigated PresenceLight I noticed that it didn’t supported my IKEA Smart Lights. But it does have a Custom API which I could use.
After further investigation I found out that this Custom API feature did not have the option to provide a JSON body to the REST API calls made to configured endpoints 😒
This was a small disappointment because most of the REST API calls also require a body to be send. So I contacted the developer of PresenceLight, Isaac Levin via a Github issue and asked if he could add support for providing a body to the Custom API REST API call functionality.
Isaac responded that he was happy to review a PR for this new functionality to be added.
The only thing left to do was accept this challenge, especially because I’m not a real developer. I call myself a wannabee Developer. But with the help of Github Copilot I was able to add this functionality to PresenceLight🎉🙏
In the rest of this blog post I’m going to explain how you can use this improved Custom API feature of PresenceLight with Home Assistant and the Ulanzi Pixel Clock.
You first need to install the latest version of the PresenceLight solution, from one of the locations documented on the website of PresenceLight. The easiest installation is probably from the Microsoft Store.
After the installation you need to figure out how the REST API call from PresenceLight needs to look like to your Home Assistant, Ulanzi Pixel Clock or whatever service you want to trigger with your Microsoft Teams status from PresenceLight.
I already installed Awtrix-Light (AWL) on my Ulanzi Pixel clock to do more fun things with it.
AWL meant to be a companion for your smarthome like HomeAssistant, IOBroker, FHEM, NodeRed and so on.
AWL supports both MQTT and HTTP API. For the usage together with PresenceLight I used the HTTP API functionality.
If we want to send the Microsoft Team Status using PresenceLight to the Ulanzi Pixel clock we can use the following REST API call.
HTTP URL | Payload/Body | HTTP Method |
---|---|---|
http://[IP]/api/notify | JSON | POST |
Example JSON body:
{ "text": "Teams Status is Available", "rainbow": true, "duration": 10 }
This will display the text “Teams Status is Available” in rainbow colors for 10 seconds.
The PresenceLight Custom API also supports the usage of the following variables in the Custom API JSON body.
Variables | Value |
---|---|
{ {availability} } |
Graph API Teams Availability Status |
{ {activity} } |
Graph API Teams Activity Status |
{ “text”: “Teams Status is { {availability} }”, “rainbow”: true, “duration”: 10 } |
The next step is configure the Custom API settings of PresenceLight with the Uri and JSON Body information.
In PresenceLight Custom API setting you need to enter the following information:
Method | Uri | Body |
---|---|---|
POST | http://[IP]/api/notify | { “text”: “Teams Status is { {availability} }”, “rainbow”: true, “duration”: 10 } |
And how can use this with Home Assistant?
To use PresenceLight with Home Assistant you can use the Custom API functionality as follows:
In Home Assistant you can use Webhooks triggers to trigger an Automation Action, like turning on a light bulb.
Example Automation for turning on a light bulb based on the Teams status send using the Custom API functionality of PresenceLight.
alias: Teams presence - IKEA Light Bulb Living Room
description: >-
Show the Microsoft Teams status via a color of the Light Bulb in the Living
Room
trigger:
- platform: webhook
allowed_methods:
- POST
local_only: true
webhook_id: "<enter secret webhook id here>"
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: ""
sequence:
- service: light.turn_on
metadata: {}
data:
color_name: red
target:
entity_id: light.ikea_bulb
- conditions:
- condition: template
value_template: ""
sequence:
- service: light.turn_on
metadata: {}
data:
color_name: green
target:
entity_id: light.ikea_bulb
- conditions:
- condition: template
value_template: ""
sequence:
- service: light.turn_on
metadata: {}
data:
color_name: yellow
target:
entity_id: light.ikea_bulb
- conditions: null
sequence:
- service: light.turn_off
metadata: {}
target:
entity_id: light.ikea_bulb
data: {}
mode: single
In PresenceLight Custom API setting you need to enter the following information:
Method | Uri | Body |
---|---|---|
POST | http://homeassistant.local:8123/api/webhook/webhook_id | { “presence_status”:”Away” } |
This is how simple it now is to use the PresenceLight Custom API and a JSON Body.