Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mark-veenstra/01aeccf357ced3c5be048f6b2c704e97 to your computer and use it in GitHub Desktop.
Save mark-veenstra/01aeccf357ced3c5be048f6b2c704e97 to your computer and use it in GitHub Desktop.
Pause/Resume Sonos player based on Teams Activity
[
{
"id": "ebd5249f.25e888",
"type": "server-state-changed",
"z": "ab79f90a.53a598",
"name": "Teams Activity",
"server": "c81f47a6.9b2ef8",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "sensor.teams_activity",
"entityidfiltertype": "exact",
"outputinitially": true,
"state_type": "str",
"haltifstate": "MATCHING_THIS_AT_ALL",
"halt_if_type": "str",
"halt_if_compare": "is_not",
"outputs": 2,
"output_only_on_state_change": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": true,
"ignorePrevStateUnknown": true,
"ignorePrevStateUnavailable": true,
"ignoreCurrentStateUnknown": true,
"ignoreCurrentStateUnavailable": true,
"x": 90,
"y": 860,
"wires": [
[
"c0fcba25.57e6e8",
"2d7679df.9e1466"
],
[
"c0fcba25.57e6e8",
"2d7679df.9e1466"
]
]
},
{
"id": "c0fcba25.57e6e8",
"type": "debug",
"z": "ab79f90a.53a598",
"name": "TEAMS ACTIVITY",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 310,
"y": 760,
"wires": []
},
{
"id": "d43806bb.833568",
"type": "switch",
"z": "ab79f90a.53a598",
"name": "Are we calling?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "In a call",
"vt": "str"
},
{
"t": "eq",
"v": "In a meeting",
"vt": "str"
},
{
"t": "eq",
"v": "Presenting",
"vt": "str"
},
{
"t": "eq",
"v": "On the phone",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 5,
"x": 500,
"y": 860,
"wires": [
[
"cf03ec69.f8639"
],
[
"cf03ec69.f8639"
],
[
"cf03ec69.f8639"
],
[
"cf03ec69.f8639"
],
[
"ceb54a46.aae548"
]
]
},
{
"id": "cf03ec69.f8639",
"type": "sonos-universal",
"z": "ab79f90a.53a598",
"confignode": "7b5c8fc6.e244d",
"command": "group.get.playbackstate",
"state": "",
"stateType": "str",
"name": "",
"x": 730,
"y": 820,
"wires": [
[
"30ab9add.7eed76",
"31592613.be2bfa"
]
]
},
{
"id": "30ab9add.7eed76",
"type": "switch",
"z": "ab79f90a.53a598",
"name": "Are we playing?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "playing",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 960,
"y": 820,
"wires": [
[
"4881dada.598794"
]
]
},
{
"id": "4881dada.598794",
"type": "sonos-universal",
"z": "ab79f90a.53a598",
"confignode": "7b5c8fc6.e244d",
"command": "group.pause",
"state": "",
"stateType": "str",
"name": "",
"x": 1150,
"y": 820,
"wires": [
[
"e0e1131b.6aeb4"
]
]
},
{
"id": "2d7679df.9e1466",
"type": "change",
"z": "ab79f90a.53a598",
"name": "Set playerName",
"rules": [
{
"t": "set",
"p": "playerName",
"pt": "msg",
"to": "OfficeSpeaker",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 300,
"y": 860,
"wires": [
[
"d43806bb.833568"
]
]
},
{
"id": "ceb54a46.aae548",
"type": "switch",
"z": "ab79f90a.53a598",
"name": "Did we pause the player?",
"property": "didWePause",
"propertyType": "flow",
"rules": [
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 730,
"y": 900,
"wires": [
[
"16df3192.9e181e"
]
]
},
{
"id": "16df3192.9e181e",
"type": "sonos-universal",
"z": "ab79f90a.53a598",
"confignode": "7b5c8fc6.e244d",
"command": "group.play",
"state": "",
"stateType": "str",
"name": "",
"x": 950,
"y": 900,
"wires": [
[
"947a1c3a.858b1"
]
]
},
{
"id": "31592613.be2bfa",
"type": "debug",
"z": "ab79f90a.53a598",
"name": "PLAYBACK STATE",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 970,
"y": 760,
"wires": []
},
{
"id": "e0e1131b.6aeb4",
"type": "change",
"z": "ab79f90a.53a598",
"name": "",
"rules": [
{
"t": "set",
"p": "didWePause",
"pt": "flow",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1360,
"y": 820,
"wires": [
[]
]
},
{
"id": "947a1c3a.858b1",
"type": "change",
"z": "ab79f90a.53a598",
"name": "",
"rules": [
{
"t": "delete",
"p": "didWePause",
"pt": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1170,
"y": 900,
"wires": [
[]
]
},
{
"id": "c81f47a6.9b2ef8",
"type": "server",
"name": "Home Assistant",
"addon": true
},
{
"id": "7b5c8fc6.e244d",
"type": "sonos-config",
"name": "Config_Node_Playbar",
"serialnum": "",
"ipaddress": "172.22.22.10"
}
]
@mark-veenstra
Copy link
Author

mark-veenstra commented Mar 17, 2021

image

Above is an example flow for Node-RED within Home Assistant, so these tools should be setup already!

Prerequisites:

Some help:

  • Make sure to change the Config_Node_Playbar to your config node. I am using the Playbar as a control node for all commands. But change it as you like, as described in the docs
  • Change the Set playerName node, which has value OfficeSpeaker to the name of your desired speaker in Sonos App. Also see the docs for definitions and values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment