I added the SonosPollyTTS palette, and created a flow you can import & modify for your needs. It only plays the message a single time.
There is no need for a function node. You can use your existing switch node (which turns on the light) and two additional change nodes (one for door open, the other for door closed). Set msg.payload in the change nodes to be the text you want spoken via Sonos.
Import this sequence
[
{
"id": "7180dbe8.227cec",
"type": "hubitat command",
"z": "3009af18.2611a8",
"name": "Attic Light off",
"server": "662851c4.3ccad",
"deviceId": "4198",
"command": "off",
"commandArgs": "",
"x": 740,
"y": 760,
"wires": [
[]
]
},
{
"id": "e6866d9a.183a7",
"type": "switch",
"z": "3009af18.2611a8",
"name": "open/closed",
"property": "payload.value",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "open",
"vt": "str"
},
{
"t": "eq",
"v": "closed",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 530,
"y": 740,
"wires": [
[
"a49584b2.1eff",
"26dc73e6.8f6a24"
],
[
"7180dbe8.227cec",
"9b31952c.59c798"
]
]
},
{
"id": "a9e7950.53fd3e8",
"type": "hubitat device",
"z": "3009af18.2611a8",
"name": "Contact - Attic Door",
"server": "a22e0ea9.276dc8",
"deviceId": "388",
"attribute": "",
"sendEvent": true,
"x": 320,
"y": 740,
"wires": [
[
"e6866d9a.183a7"
]
]
},
{
"id": "a49584b2.1eff",
"type": "hubitat command",
"z": "3009af18.2611a8",
"name": "Attic Light on",
"server": "662851c4.3ccad",
"deviceId": "4198",
"command": "on",
"commandArgs": "",
"x": 740,
"y": 720,
"wires": [
[]
]
},
{
"id": "9b31952c.59c798",
"type": "change",
"z": "3009af18.2611a8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "The door is closed",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 750,
"y": 800,
"wires": [
[
"5d034f76.575b2"
]
]
},
{
"id": "26dc73e6.8f6a24",
"type": "change",
"z": "3009af18.2611a8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "The door is open",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 750,
"y": 680,
"wires": [
[
"5d034f76.575b2"
]
]
},
{
"id": "5d034f76.575b2",
"type": "sonospollytts",
"z": "3009af18.2611a8",
"name": "",
"voice": "0",
"ssml": false,
"sonosipaddress": "192.168.1.218",
"sonosvolume": "40",
"sonoshailing": "Hailing_Hailing.mp3",
"config": "a57893d5.3a977",
"property": "payload",
"propertyType": {},
"rules": [],
"x": 980,
"y": 740,
"wires": [
[]
]
},
{
"id": "662851c4.3ccad",
"type": "hubitat config",
"z": "",
"name": "HubitatS",
"usetls": false,
"host": "192.168.1.36",
"port": "80",
"token": "5dee560c-c42c-4e4b-bdf7-6bed1bb77371",
"appId": "4489",
"nodeRedServer": "http://192.168.1.4:1880",
"webhookPath": "/hubitat/webhook2"
},
{
"id": "a22e0ea9.276dc8",
"type": "hubitat config",
"z": "",
"name": "HubitatM",
"usetls": false,
"host": "192.168.1.46",
"port": "80",
"token": "496f7f11-256d-44c9-99c6-4ed460d3efb0",
"appId": "1522",
"nodeRedServer": "http://192.168.1.4:1880",
"webhookPath": "/hubitat/webhook"
},
{
"id": "a57893d5.3a977",
"type": "sonospollytts-config",
"z": "",
"name": "Config",
"noderedipaddress": "192.168.1.4",
"noderedport": "1980",
"purgediratrestart": "leave"
}
]