Starting to do some HA things after being away for awhile. A little confused on when/how to use templates.
I’ve successfully subscribed to a webhook that notifies when my Zoom status changes. The goal is to set up some ‘on air/off air’ lights so my wife and I know when we’re in meetings so we don’t interrupt.
I can use the trigger to turn lights on and off, but I want to use data in the payload - email and presence_status - so I know which light to change, and whether to change it to red (do not disturb) or green (available).
here’s the pseudocode I need to translate into an action. I don’t know how to translate this into real HA script.
if trigger.json.requestbody.object.email = “adam@xyx” then
if trigger.json.requestbody.payload.object.presence_status = “Do not disturb” then
light.turn_on.adamstatus color_name=red
if trigger.jason.payload.object.presence_status = “Available” then
light.turn_on.adamstatus color_name=green
endif
if trigger.json.requestbody.object.email = “alisa@xyx” then
if trigger.json.requestbody.payload.object.presence_status = “Do not disturb” then
light.turn_on.alisastatus color_name=red
if trigger.jason.payload.object.presence_status = “Available” then
light.turn_on.alisastatus color_name=green
endif
here’s a sanitized example of what gets posted when the webhook triggers:
{
“applicationId”: “MHRy-FXpSauKAupwSfTNFQ”,
“monitorTime”: 1598762450465,
“traceId”: “Webhook_b50e7b05becc4392af5a68c2080e4d6d”,
“accountId”: “scrubbed”,
“event”: “user.presence_status_updated”,
“status”: “200”,
“userId”: “I97aq0o3T-u5cxvZ2TQVkg”,
“url”: “https://hooks.nabu.casa/scrubbed”,
“subscriptionId”: “scrubbed”,
“requestHeaders”: “N/A”,
“requestBody”: {
“event”: “user.presence_status_updated”,
“payload”: {
“account_id”: “scrubbed”,
“object”: {
“date_time”: “2020-08-30T04:40:50Z”,
“email”: “adam@xyz”,
“id”: “scrubbed”,
“presence_status”: “Available”
}
}
},
“responseHeaders”: {
“Server”: “Python/3.7 aiohttp/3.6.1”,
“Content-Length”: “4”,
“Date”: “Sun, 30 Aug 2020 04:40:50 GMT”,
“Content-Type”: “text/plain; charset=utf-8”
},
“runTime”: “162”,
“ttl”: 1599972050,
“requestParameters”: undefined,
“responseData”: undefined
}