Complete fucking garbage, but I gotta save, outta time

This commit is contained in:
2023-10-20 18:22:46 -04:00
parent f758c36508
commit 8a002c6599
3 changed files with 97 additions and 66 deletions

View File

@ -86,3 +86,6 @@ flow.set('lightsBasement', lightsBasement, 'diskCon')
flow.set('lightsLivingRoom', lightsLivingRoom, 'diskCon') flow.set('lightsLivingRoom', lightsLivingRoom, 'diskCon')
flow.set('lightsDiningRoom', lightsDiningRoom, 'diskCon') flow.set('lightsDiningRoom', lightsDiningRoom, 'diskCon')
flow.set('lightsStairwell', lightsStairwell, 'diskCon') flow.set('lightsStairwell', lightsStairwell, 'diskCon')
flow.set('alertFirstFloor', false)
flow.set('alertBasement', false)

View File

@ -19,7 +19,7 @@ const currentSceneTinaDesk = states["input_text.tina_desk_selected_scene"].state
const currentSceneDiningRoom = states["input_text.dining_room_lamp_selected_scene"].state const currentSceneDiningRoom = states["input_text.dining_room_lamp_selected_scene"].state
const effectBasement = msg.payload.event.basement const effectBasement = msg.payload.event.basement
const effectFirstFloor = msg.payload.event.first_floor const effectFirstFloor = msg.payload.event.first_floor
const effectType = msg.payload.event.type const effectColor = msg.payload.event.color
const effectDivide = msg.payload.event.divide const effectDivide = msg.payload.event.divide
const duration = msg.payload.event.duration const duration = msg.payload.event.duration
const delay = duration * 1000 const delay = duration * 1000
@ -29,6 +29,8 @@ const lightsTinaDesk = flow.get('lightsTinaDesk', 'diskCon')
const lightsBasement = flow.get('lightsBasement', 'diskCon') const lightsBasement = flow.get('lightsBasement', 'diskCon')
const lightsLivingRoom = flow.get('lightsLivingRoom', 'diskCon') const lightsLivingRoom = flow.get('lightsLivingRoom', 'diskCon')
const lightsDiningRoom = flow.get('lightsDiningRoom', 'diskCon') const lightsDiningRoom = flow.get('lightsDiningRoom', 'diskCon')
const alertFirstFloor = flow.get('alertFirstFloor')
const alertBasement = flow.get('alertBasement')
// Set flow contexts to be used later in the reset node // Set flow contexts to be used later in the reset node
flow.set("currentSceneBasement", currentSceneBasement) flow.set("currentSceneBasement", currentSceneBasement)
@ -55,10 +57,11 @@ let livingRoom1 = []
let livingRoom2 = [] let livingRoom2 = []
let livingRoomFull = [] let livingRoomFull = []
// Color names are set by default, however certain effects can override them below // Color names are set by default, however certain effects can override them below
let colorName1 = effectType let colorName1 = effectColor
let colorName2 = "white" let colorName2 = "white"
// Define empty array for input texts // Define empty object for LIFX effect settings
let inputTexts = [] let lifxData = {}
let effectLifx = msg.payload.event.lifx
// Setup the proper zones to use for the effect // Setup the proper zones to use for the effect
if (effectDivide === 'half') { if (effectDivide === 'half') {
@ -77,43 +80,59 @@ if (effectDivide === 'half') {
} }
if (effectFirstFloor === true) { if (effectFirstFloor === true) {
inputTexts.push('input_text.living_room_selected_scene','input_text.tina_desk_selected_scene') flow.set('alertFirstFloor', true)
} }
if (effectBasement === true) { if (effectBasement === true) {
inputTexts.push('input_text.basement_studio_selected_scene') flow.set('alertBasement', true)
} }
// Set/change colors if necessary // Set/change colors if necessary
if (effectType === 'police') { if (effectColor === 'police') {
colorName1 = 'red' colorName1 = 'red'
colorName2 = 'blue' colorName2 = 'blue'
} }
// Set message payloads // Define parameters for different LIFX effects
let sendInputTexts = { if (effectLifx === 'move') {
"payload": "input_text", lifxData = {
"service": "set_value", "speed": 0.5,
"target": { "direction": "right",
"entity_id": inputTexts "power_on": false
}, }
"data": { } else if (effectLifx === 'ping') {
"value": "Alert" effectLifx = 'pulse'
colorName2 = colorName1
lifxData = {
"power_on": false,
"mode": "ping",
"period": 1,
"cycles": duration,
"color_name": "white",
"brightness": 255
}
} else if (effectLifx === 'blink') {
effectLifx = 'pulse'
colorName2 = colorName1
lifxData = {
"power_on": false,
"mode": "blink",
"period": 0.5,
"cycles": duration * 2,
"color_name": "white",
"brightness": 255
} }
} }
// Define messages
let sendBasementStripFX = { let sendBasementStripFX = {
"payload": { "payload": {
"domain": "lifx", "domain": "lifx",
"service": "effect_move", "service": "effect_" + effectLifx,
"target": { "target": {
"entity_id": ["light.basement_led_strip_1"] "entity_id": ["light.basement_led_strip_1"]
}, },
"data": { "data": lifxData
"speed": 0.5,
"direction": "right",
"power_on": false
}
} }
} }
@ -169,15 +188,11 @@ let sendBasementLights = {
let sendLivingRoomStripFX = { let sendLivingRoomStripFX = {
"payload": { "payload": {
"domain": "lifx", "domain": "lifx",
"service": "effect_move", "service": "effect_" + effectLifx,
"target": { "target": {
"entity_id": ["light.living_room_led_strip"] "entity_id": ["light.living_room_led_strip"]
}, },
"data": { "data": lifxData
"speed": 0.5,
"direction": "right",
"power_on": false
}
} }
} }
@ -316,26 +331,28 @@ let sendReset = {
} }
// Send backup messages // Send backup messages
if (stateLivingRoom === 'on' && currentSceneLivingRoom != 'Alert') { if (stateLivingRoom === 'on' && alertFirstFloor === false) {
node.send([backupLivingRoom,null,null,null,null,null]) node.send([backupLivingRoom,null,null,null,null,null])
} }
if (stateTinaDesk === 'on' && currentSceneTinaDesk != 'Alert') { if (stateTinaDesk === 'on' && alertFirstFloor === false) {
node.send([backupTinaDesk,null,null,null,null,null]) node.send([backupTinaDesk,null,null,null,null,null])
} }
if (stateBasement === 'on' && currentSceneBasement != 'Alert') { if (stateBasement === 'on' && alertBasement === false) {
node.send([backupBasement,null,null,null,null,null]) node.send([backupBasement,null,null,null,null,null])
} }
// Send effect messages // Send effect messages
if (effectBasement === true) { if (effectBasement === true) {
node.send([sendAdaptiveBasement,null,null,null,[sendBasementStripFX,sendBasementLights,sendBasementStrip1,sendBasementStrip2],null]) node.send([null,null,null,null,[sendAdaptiveBasement,sendBasementLights,sendBasementStripFX,sendBasementStrip1,sendBasementStrip2],null])
} }
if (effectFirstFloor === true) { if (effectFirstFloor === true) {
node.send([sendAdaptiveFirstFloor,[sendLivingRoomStripFX,sendLivingRoomLights,sendLivingRoomStrip1,sendLivingRoomStrip2],sendTinaDeskLights,sendDiningRoomLamp,null,null]) node.send([null,[sendAdaptiveFirstFloor,sendLivingRoomLights,sendLivingRoomStripFX,sendLivingRoomStrip1,sendLivingRoomStrip2],sendTinaDeskLights,sendDiningRoomLamp,null,null])
} }
// Send the reset message to start the timer // Send the reset message to start the timer
node.send([null,null,null,null,null,sendReset]) node.send([null,null,null,null,null,sendReset])
node.status({fill:'green',shape:'dot',text:'Alert Sent'})

View File

@ -35,7 +35,6 @@ let setServiceBasement = []
let restoreLivingRoom = {} let restoreLivingRoom = {}
let restoreTinaDesk = {} let restoreTinaDesk = {}
let restoreBasement = {} let restoreBasement = {}
let inputTexts = []
// Decide what to restore for each room // Decide what to restore for each room
if (stateLivingRoom === 'on') { if (stateLivingRoom === 'on') {
@ -52,12 +51,11 @@ if (stateLivingRoom === 'on') {
} else { } else {
restoreLivingRoom = 'backup' restoreLivingRoom = 'backup'
setSceneLivingRoom = 'living_room_alert_restore' setSceneLivingRoom = 'living_room_alert_restore'
inputTexts.push('input_text.living_room_selected_scene')
} }
} else { } else {
restoreLivingRoom = 'off' restoreLivingRoom = 'off'
setServiceLivingRoom = 'turn_off' setServiceLivingRoom = 'turn_off'
inputTexts.push('input_text.living_room_selected_scene') setSceneLivingRoom = 'Adaptive'
} }
if (stateTinaDesk === 'on') { if (stateTinaDesk === 'on') {
@ -72,7 +70,6 @@ if (stateTinaDesk === 'on') {
} else { } else {
restoreTinaDesk = 'off' restoreTinaDesk = 'off'
setServiceTinaDesk = 'turn_off' setServiceTinaDesk = 'turn_off'
inputTexts.push('input_text.tina_desk_selected_scene')
} }
if (stateDiningRoom === 'on') { if (stateDiningRoom === 'on') {
@ -84,7 +81,6 @@ if (stateDiningRoom === 'on') {
} }
} else { } else {
setServiceDiningRoom = 'turn_off' setServiceDiningRoom = 'turn_off'
inputTexts.push('input_text.dining_room_lamp_selected_scene')
} }
if (stateBasement === 'on') { if (stateBasement === 'on') {
@ -101,26 +97,14 @@ if (stateBasement === 'on') {
} else { } else {
restoreBasement = 'backup' restoreBasement = 'backup'
setSceneBasement = 'basement_alert_restore' setSceneBasement = 'basement_alert_restore'
inputTexts.push('input_text.basement_studio_selected_scene')
} }
} else { } else {
restoreBasement = 'off' restoreBasement = 'off'
setServiceBasement = 'turn_off' setServiceBasement = 'turn_off'
inputTexts.push('input_text.basement_studio_selected_scene') setSceneBasement = 'Adaptive'
} }
// Define messages // Define messages
let sendInputTexts = {
"payload": {
"domain": "input_text",
"service": "set_value",
"target": {
"entity_id": inputTexts
},
"data": "Adaptive"
}
}
let sendSceneLivingRoom = { let sendSceneLivingRoom = {
"payload": { "payload": {
"domain": "input_select", "domain": "input_select",
@ -240,6 +224,17 @@ let sendStateDiningRoom = {
} }
} }
let sendStateBasement = {
"payload": {
"domain": "light",
"service": setServiceBasement,
"target": {
"entity_id": ["light.basement_studio_lights"]
},
"data": {}
}
}
let sendRestoreLivingRoom = { let sendRestoreLivingRoom = {
"payload": { "payload": {
"domain": "scene", "domain": "scene",
@ -262,6 +257,17 @@ let sendRestoreTinaDesk = {
} }
} }
let sendRestoreBasement = {
"payload": {
"domain": "scene",
"service": "turn_on",
"target": {
"entity_id": setSceneBasement
},
"data": {}
}
}
let sendStairwellScript = { let sendStairwellScript = {
"payload": { "payload": {
"domain": "script", "domain": "script",
@ -283,33 +289,38 @@ let sendStairwellOff = {
// Send messages // Send messages
if (restoreLivingRoom === 'backup') { if (restoreLivingRoom === 'backup') {
node.send([sendRestoreLivingRoom,null,null,null,null]) node.send([sendRestoreLivingRoom,null,null,null])
} else if (restoreLivingRoom === 'off') {
node.send([sendStateLivingRoom,null,null,null])
} else { } else {
node.send([sendSceneLivingRoom,null,null,null,null]) node.send([sendSceneLivingRoom,null,null,null])
} }
if (restoreTinaDesk === 'backup') { if (restoreTinaDesk === 'backup') {
node.send([null,sendRestoreTinaDesk,null,null,null]) node.send([null,sendRestoreTinaDesk,null,null])
} else if (restoreTinaDesk === 'off') {
node.send([null,sendStateTinaDesk,null,null])
} else { } else {
node.send([null,sendSceneTinaDesk,null,null,null]) node.send([null,sendSceneTinaDesk,null,null])
} }
if (stateDiningRoom === 'off') { node.send([null,null,[sendStateDiningRoom,sendSceneDiningRoomLamp],null])
node.send([null,null,sendStateDiningRoom,null,null])
} else {
node.send([null,null,sendSceneDiningRoomLamp,null,null])
}
if (restoreBasement === 'backup') { if (restoreBasement === 'backup') {
node.send([null,null,null,restoreBasement,null]) node.send([null,null,null,sendRestoreBasement])
} else if (restoreBasement === 'off') {
node.send([null,null,null,sendStateBasement])
} else { } else {
node.send([null,null,null,sendSceneBasement,null]) node.send([null,null,null,sendSceneBasement])
} }
if (stateStairwell === 'on') { if (stateStairwell === 'on') {
node.send([sendStairwellScript,null,null,null,null]) node.send([sendStairwellScript,null,null,null])
} else { } else {
node.send([sendStairwellOff,null,null,null,null]) node.send([sendStairwellOff,null,null,null])
} }
node.send([null,null,null,null,sendInputTexts]) flow.set('alertFirstFloor', false)
flow.set('alertBasement', false)
node.status({fill:'green',shape:'dot',text:'Scenes Reset'})