Last active
May 18, 2022 14:40
-
-
Save instance-id/52fd28a20d76aca467cb5ad01c81dfed to your computer and use it in GitHub Desktop.
UserScript/TamperMonkey - Sends HTTP request to NodeRed HTTP Listener when web based Microsoft Teams status/presence changes to enable automated actions in NodeRed/HomeAssistant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Web Based Microsoft Teams Presence To NodeRed/HomeAssistant | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Sends HTTP request to NodeRed HTTP Listener when Web based Microsoft Teams status/presence changes to enable automated actions in NodeRed/HomeAssistant | |
// @author instance.id | |
// @match https://*.teams.microsoft.us/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const INTERVAL = 5000; | |
let currentStatus = '' | |
let settingData = '' | |
setInterval(() => { | |
let status = document.querySelector("span.ts-skype-status"); | |
if (currentStatus == status.title) { return; } | |
console.log('Current Status: ' + status.title) | |
if (status != null && (status.title == 'In a call' || status.title == 'Busy' || status.title == 'In a meeting')) { | |
currentStatus = status.title; | |
console.log('Busy, turn Zigbee light on!'); | |
settingData = 'on'; | |
} else { | |
currentStatus = status.title; | |
console.log('Not busy, turn Zigbee light off!'); | |
settingData = 'off'; | |
} | |
// curl --insecure https://192.168.50.231:1880/teams_status -H "Content-Type: application/json" -d '{"status": currentStatus, "set": "on"}' | |
$.ajax({ | |
type: "POST", | |
url: "https://192.168.50.231:1880/teams_status", | |
data: { | |
status: currentStatus, | |
set: settingData | |
}, | |
success: function (data) { | |
console.log(data); | |
}, | |
dataType: "json" | |
}); | |
}, INTERVAL); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"bd906c5074427c45","type":"tab","label":"Listeners","disabled":false,"info":"","env":[]},{"id":"1720fda6a853e745","type":"http in","z":"bd906c5074427c45","name":"teams_status","url":"/teams_status","method":"post","upload":false,"swaggerDoc":"","x":550,"y":470,"wires":[["ae2c8f39e6320fb1","f8cf61fdbc27b16f"]]},{"id":"ae2c8f39e6320fb1","type":"http response","z":"bd906c5074427c45","name":"","statusCode":"","headers":{},"x":710,"y":450,"wires":[]},{"id":"047b46b908b92a87","type":"api-call-service","z":"bd906c5074427c45","name":"work_lamp","server":"ae034bd8.042578","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.upstairs_kitchen_lamp_c","data":"{\"transition\":1}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"all","x":880,"y":450,"wires":[["8544e1e0f89e19ac"]]},{"id":"f8cf61fdbc27b16f","type":"switch","z":"bd906c5074427c45","name":"","property":"payload.set","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":490,"wires":[["047b46b908b92a87"],["8ad2733313a9b7fc"]]},{"id":"8ad2733313a9b7fc","type":"api-call-service","z":"bd906c5074427c45","name":"work_lamp","server":"ae034bd8.042578","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.upstairs_kitchen_lamp_c","data":"{\"transition\":1}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"all","x":880,"y":500,"wires":[["8544e1e0f89e19ac"]]},{"id":"8544e1e0f89e19ac","type":"debug","z":"bd906c5074427c45","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1110,"y":470,"wires":[]},{"id":"ae034bd8.042578","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated condition check to include 'Busy', 'In a call', 'In a meeting' status messages.