Play Emma's door alert on all Echo Dots unless told otherwise
This commit is contained in:
@ -15469,7 +15469,7 @@
|
||||
"z": "5e238cbbe6d612c9",
|
||||
"g": "ba738e13229c781b",
|
||||
"name": "Door Alert",
|
||||
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst masterBedroomSleeping = states['input_boolean.master_bedroom_sleeping'].state\nconst emmaSleep = states['input_boolean.emma_sleeping'].state\nconst tonyAwake = states['input_boolean.tony_awake'].state\nconst xiaDesktopUser = states['sensor.xia_desktop_current_username'].state\nconst xiaDesktopIdle = states['binary_sensor.tina_desktop_idle'].state\nconst tonyLocation = states['person.tony_stork'].state\nconst tinaLocation = states['person.christina_stork'].state\nconst overnight = states['binary_sensor.overnight'].state\nconst payload = msg.payload\nconst topic = msg.topic\n\n// Set some default values\n\nlet who = 'Master Bedroom'\nlet tinaAvailable = false\nlet tonyAvailable = false\nlet enable = false\nlet reason = {}\n\n// Determine who is available to respond\n\nif (tonyAwake === 'on' && tonyLocation === 'home') {\n tonyAvailable = true\n}\n\nif (xiaDesktopUser === 'irish' && xiaDesktopIdle === 'off' && tinaLocation === 'home') {\n tinaAvailable = true\n}\n\n// Determine where to send the alert to\n\nif (tinaAvailable === true || tonyAvailable === true) {\n who = 'Common Areas'\n}\n\n// Determine if the alert should be sent\n\nif (emmaSleep === 'on') {\n if (overnight === 'on' && masterBedroomSleeping === 'on') {\n enable = true\n reason = 'Overnight is on, and master bedroom is sleeping'\n } else if (overnight === 'off') {\n enable = true\n reason = 'Overnight is off'\n }\n}\n\n// Define the alert message\n\nlet alertTTS = {\n \"topic\": who,\n \"payload\": \"Emma has opened her door, please check on her. I repeat, Emma has opened her door, please check on her. This is urgent, Emma is awake. PDS toddler warning, a large and extremely dangerous toddler is on the ground in your area.\",\n \"type\": \"critical\"\n}\n\n// Add some logs for debugging\n\nnode.log(`--------------- Emma Door Alert --------------`)\nnode.log(`Emma Door Alert - topic: ${topic}`)\nnode.log(`Emma Door Alert - payload: ${payload}`)\nnode.log(`Emma Door Alert - masterBedroomSleeping: ${masterBedroomSleeping}`)\nnode.log(`Emma Door Alert - emmaSleep: ${emmaSleep}`)\nnode.log(`Emma Door Alert - tonyAwake: ${tonyAwake}`)\nnode.log(`Emma Door Alert - xiaDesktopUser: ${xiaDesktopUser}`)\nnode.log(`Emma Door Alert - xiaDesktopIdle: ${xiaDesktopIdle}`)\nnode.log(`Emma Door Alert - tonyLocation: ${tonyLocation}`)\nnode.log(`Emma Door Alert - tinaLocation: ${tinaLocation}`)\nnode.log(`Emma Door Alert - overnight: ${overnight}`)\nnode.log(`Emma Door Alert - tonyAvailable: ${tonyAvailable}`)\nnode.log(`Emma Door Alert - tinaAvailable: ${tinaAvailable}`)\nnode.log(`Emma Door Alert - who: ${who}`)\nnode.log(`Emma Door Alert - enable: ${enable}`)\nnode.log(`Emma Door Alert - reason: ${reason}`)\nnode.log(`----------------------------------------------`)\n\n// Send the alert if conditions are met\n\nif (topic === 'door' && payload === 'on') {\n if (enable === true) {\n node.status({fill:'green',shape:'dot',text:`Sending alert to ${who}`})\n node.send([alertTTS,msg,null])\n } else {\n node.status({fill:'red',shape:'ring',text:'Door Opened, but no alert sent'})\n }\n} else if (topic === 'timer') {\n node.status({fill:'green',shape:'dot',text:'Timer Finished'})\n node.send([alertTTS,msg,null])\n} else if (topic === 'cancel') {\n node.status({fill:'green',shape:'dot',text:'Cancel Button Pressed'})\n node.send([null,null,msg])\n} else if (topic === 'door' && payload === 'off') {\n node.status({fill:'green',shape:'dot',text:'Door Closed'})\n}",
|
||||
"func": "const states = global.get('homeassistant.homeAssistant.states')\nconst masterBedroomSleeping = states['input_boolean.master_bedroom_sleeping'].state\nconst emmaSleep = states['input_boolean.emma_sleeping'].state\nconst tonyAwake = states['input_boolean.tony_awake'].state\nconst xiaDesktopUser = states['sensor.xia_desktop_current_username'].state\nconst xiaDesktopIdle = states['binary_sensor.tina_desktop_idle'].state\nconst tonyLocation = states['person.tony_stork'].state\nconst tinaLocation = states['person.christina_stork'].state\nconst overnight = states['binary_sensor.overnight'].state\nconst payload = msg.payload\nconst topic = msg.topic\n\n// Set some default values\n\nlet who = 'Alexa Everywhere' // Default to playing on all Echo Dots unless told otherwise\nlet tinaAvailable = false\nlet tonyAvailable = false\nlet enable = false\nlet reason = {}\n\n// Determine who is available to respond\n\nif (tonyAwake === 'on' && tonyLocation === 'home') {\n tonyAvailable = true\n}\n\nif (xiaDesktopUser === 'irish' && xiaDesktopIdle === 'off' && tinaLocation === 'home') {\n tinaAvailable = true\n}\n\n// If both of us are still asleep, or I am asleep and she is at work, play the alert only in the master bedroom\n\nif (tinaAvailable === false && tonyAvailable === false) {\n who = 'Master Bedroom'\n}\n\n// Determine if the alert should be sent\n\nif (emmaSleep === 'on') {\n if (overnight === 'on' && masterBedroomSleeping === 'on') {\n enable = true\n reason = 'Overnight is on, and master bedroom is sleeping'\n } else if (overnight === 'off') {\n enable = true\n reason = 'Overnight is off'\n }\n}\n\n// Define the alert message\n\nlet alertTTS = {\n \"topic\": who,\n \"payload\": \"Emma has opened her door, please check on her. I repeat, Emma has opened her door, please check on her. This is urgent, Emma is awake. PDS toddler warning, a large and extremely dangerous toddler is on the ground in your area.\",\n \"type\": \"critical\"\n}\n\n// Add some logs for debugging\n\nnode.log(`--------------- Emma Door Alert --------------`)\nnode.log(`Emma Door Alert - topic: ${topic}`)\nnode.log(`Emma Door Alert - payload: ${payload}`)\nnode.log(`Emma Door Alert - masterBedroomSleeping: ${masterBedroomSleeping}`)\nnode.log(`Emma Door Alert - emmaSleep: ${emmaSleep}`)\nnode.log(`Emma Door Alert - tonyAwake: ${tonyAwake}`)\nnode.log(`Emma Door Alert - xiaDesktopUser: ${xiaDesktopUser}`)\nnode.log(`Emma Door Alert - xiaDesktopIdle: ${xiaDesktopIdle}`)\nnode.log(`Emma Door Alert - tonyLocation: ${tonyLocation}`)\nnode.log(`Emma Door Alert - tinaLocation: ${tinaLocation}`)\nnode.log(`Emma Door Alert - overnight: ${overnight}`)\nnode.log(`Emma Door Alert - tonyAvailable: ${tonyAvailable}`)\nnode.log(`Emma Door Alert - tinaAvailable: ${tinaAvailable}`)\nnode.log(`Emma Door Alert - who: ${who}`)\nnode.log(`Emma Door Alert - enable: ${enable}`)\nnode.log(`Emma Door Alert - reason: ${reason}`)\nnode.log(`----------------------------------------------`)\n\n// Send the alert if conditions are met\n\nif (topic === 'door' && payload === 'on') {\n if (enable === true) {\n node.status({fill:'green',shape:'dot',text:`Sending alert to ${who}`})\n node.send([alertTTS,msg,null])\n } else {\n node.status({fill:'red',shape:'ring',text:'Door Opened, but no alert sent'})\n }\n} else if (topic === 'timer') {\n node.status({fill:'green',shape:'dot',text:'Timer Finished'})\n node.send([alertTTS,msg,null])\n} else if (topic === 'cancel') {\n node.status({fill:'green',shape:'dot',text:'Cancel Button Pressed'})\n node.send([null,null,msg])\n} else if (topic === 'door' && payload === 'off') {\n node.status({fill:'green',shape:'dot',text:'Door Closed'})\n}",
|
||||
"outputs": 3,
|
||||
"timeout": 0,
|
||||
"noerr": 0,
|
||||
|
Reference in New Issue
Block a user