[ { "id": "d8ebccc8.ddb8c", "type": "tab", "label": "Sonos Doorbell", "disabled": false, "info": "" }, { "id": "a0cc0f9.6f370f", "type": "function", "z": "d8ebccc8.ddb8c", "name": "Filter and Store Current Sonos States", "func": "var sonosSpeakers = []\n\nfor (i = 0; i < msg.payload.length; i++) {\n var entity = msg.payload[i];\n if (entity.entity_id.includes(\"sonos\")) {\n sonosSpeakers.push({\n \"entity_id\": entity.entity_id,\n \"media_content_id\": entity.attributes.media_content_id,\n \"media_content_type\": entity.attributes.media_content_type,\n \"media_position\": entity.attributes.media_position,\n \"state\": entity.state,\n \"volume_level\": entity.attributes.volume_level\n })\n }\n}\n\nflow.set(\"speaker_ids\", sonosSpeakers.map(x => x.entity_id).join(\", \"))\nflow.set(\"speaker_states\", sonosSpeakers)\nreturn {};", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 790, "y": 240, "wires": [ [ "6281911b.68e04" ] ] }, { "id": "4d544b1b.7d10f4", "type": "ha-api", "z": "d8ebccc8.ddb8c", "name": "Get All States", "server": "edcc1a69.99d288", "debugenabled": false, "protocol": "websocket", "method": "get", "path": "", "data": "{\"type\":\"get_states\"}", "dataType": "json", "location": "payload", "locationType": "msg", "responseType": "json", "x": 470, "y": 240, "wires": [ [ "a0cc0f9.6f370f" ] ] }, { "id": "ca95a51b.cf84d8", "type": "api-call-service", "z": "d8ebccc8.ddb8c", "name": "Ding Dong!", "server": "edcc1a69.99d288", "version": 1, "debugenabled": false, "service_domain": "media_player", "service": "play_media", "entityId": "", "data": "", "dataType": "json", "mergecontext": "", "output_location": "payload", "output_location_type": "msg", "mustacheAltTags": false, "x": 890, "y": 480, "wires": [ [ "761c0d9b.3c4714" ] ] }, { "id": "aa1fd25c.12df4", "type": "api-call-service", "z": "d8ebccc8.ddb8c", "name": "Set Volume", "server": "edcc1a69.99d288", "version": 1, "debugenabled": false, "service_domain": "media_player", "service": "volume_set", "entityId": "", "data": "", "dataType": "json", "mergecontext": "", "output_location": "", "output_location_type": "none", "mustacheAltTags": false, "x": 890, "y": 400, "wires": [ [ "80e49bb4.08d378" ] ] }, { "id": "45fb844b.9d8b3c", "type": "api-call-service", "z": "d8ebccc8.ddb8c", "name": "Media Pause", "server": "edcc1a69.99d288", "version": 1, "debugenabled": false, "service_domain": "media_player", "service": "media_pause", "entityId": "", "data": "", "dataType": "json", "mergecontext": "", "output_location": "", "output_location_type": "none", "mustacheAltTags": false, "x": 1010, "y": 320, "wires": [ [ "3ba1fa3a.7c5796" ] ] }, { "id": "6281911b.68e04", "type": "function", "z": "d8ebccc8.ddb8c", "name": "Get Entity IDs", "func": "return {\n \"payload\": {\n \"data\": {\n \"entity_id\": flow.get(\"speaker_ids\")\n }\n }\n}", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 560, "y": 320, "wires": [ [ "3a94e9f.37a6c16" ] ] }, { "id": "3ba1fa3a.7c5796", "type": "function", "z": "d8ebccc8.ddb8c", "name": "Format Volume", "func": "return {\n \"payload\": {\n \"data\": {\n \"entity_id\": flow.get(\"speaker_ids\"),\n \"volume_level\": 0.5\n }\n }\n};", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 700, "y": 400, "wires": [ [ "aa1fd25c.12df4" ] ] }, { "id": "80e49bb4.08d378", "type": "function", "z": "d8ebccc8.ddb8c", "name": "Format Play", "func": "return {\n \"payload\": {\n \"data\": {\n \"entity_id\": flow.get(\"speaker_ids\"),\n \"media_content_id\": \"\",\n \"media_content_type\": \"music\"\n }\n }\n};", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 690, "y": 480, "wires": [ [ "ca95a51b.cf84d8" ] ] }, { "id": "761c0d9b.3c4714", "type": "delay", "z": "d8ebccc8.ddb8c", "name": "", "pauseType": "delay", "timeout": "10", "timeoutUnits": "seconds", "rate": "1", "nbRateUnits": "1", "rateUnits": "second", "randomFirst": "1", "randomLast": "5", "randomUnits": "seconds", "drop": false, "x": 780, "y": 560, "wires": [ [ "7a4d8300.a5524c" ] ] }, { "id": "3a94e9f.37a6c16", "type": "api-call-service", "z": "d8ebccc8.ddb8c", "name": "Snapshot Sonos", "server": "edcc1a69.99d288", "version": 1, "debugenabled": false, "service_domain": "sonos", "service": "snapshot", "entityId": "", "data": "", "dataType": "json", "mergecontext": "", "output_location": "", "output_location_type": "none", "mustacheAltTags": false, "x": 790, "y": 320, "wires": [ [ "45fb844b.9d8b3c" ] ] }, { "id": "92dabf49.9a73e", "type": "api-call-service", "z": "d8ebccc8.ddb8c", "name": "Restore Sonos", "server": "edcc1a69.99d288", "version": 1, "debugenabled": false, "service_domain": "sonos", "service": "restore", "entityId": "", "data": "", "dataType": "json", "mergecontext": "", "output_location": "", "output_location_type": "none", "mustacheAltTags": false, "x": 940, "y": 620, "wires": [ [] ] }, { "id": "7a4d8300.a5524c", "type": "function", "z": "d8ebccc8.ddb8c", "name": "Get Speakers from Flow State", "func": "return {\n \"payload\": {\n \"data\": {\n \"entity_id\": flow.get(\"speaker_ids\")\n }\n }\n}", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 630, "y": 620, "wires": [ [ "92dabf49.9a73e" ] ] }, { "id": "7839c619.ffb938", "type": "mqtt in", "z": "d8ebccc8.ddb8c", "name": "Doorbell Rings", "topic": "sensor/doorbell", "qos": "2", "datatype": "auto", "broker": "73256168.b59a3", "x": 140, "y": 160, "wires": [ [ "4d544b1b.7d10f4" ] ] }, { "id": "edcc1a69.99d288", "type": "server", "z": "", "name": "Home Assistant", "legacy": false, "addon": false, "rejectUnauthorizedCerts": true, "ha_boolean": "y|yes|true|on|home|open", "connectionDelay": true, "cacheJson": false }, { "id": "73256168.b59a3", "type": "mqtt-broker", "z": "", "name": "Mosquitto", "broker": "mosquitto", "port": "1883", "clientid": "", "usetls": false, "compatmode": false, "keepalive": "60", "cleansession": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "closeTopic": "", "closeQos": "0", "closePayload": "", "willTopic": "", "willQos": "0", "willPayload": "" } ]