Initial commit
This commit is contained in:
11
time-based/old/early-night.js
Normal file
11
time-based/old/early-night.js
Normal file
@ -0,0 +1,11 @@
|
||||
var daynight = msg.payload
|
||||
|
||||
if (daynight === 0) {
|
||||
node.status({fill:"red",shape:"ring",text:"Off"});
|
||||
msg.payload = "off"
|
||||
} else if (daynight === 1) {
|
||||
node.status({fill:"green",shape:"dot",text:"On"});
|
||||
msg.payload = "on"
|
||||
}
|
||||
|
||||
return msg;
|
20
time-based/old/holiday-day.js
Normal file
20
time-based/old/holiday-day.js
Normal file
@ -0,0 +1,20 @@
|
||||
var states = global.get('homeassistant.homeAssistant.states')
|
||||
var holidayMode = states['input_boolean.holiday_mode'].state
|
||||
var holidayHold = states['input_boolean.holiday_mode_hold'].state
|
||||
var currentHoliday = states['input_select.holiday_animation'].state
|
||||
var holiday = currentHoliday.toLowerCase()
|
||||
|
||||
if (holidayMode === 'on') {
|
||||
if (holidayHold === 'off') {
|
||||
node.status({fill:"green",shape:"dot",text:"Holiday On" });
|
||||
msg.holiday = holiday
|
||||
return msg;
|
||||
} else {
|
||||
node.status({fill:"yellow",shape:"dot",text:"Holiday Hold On"});
|
||||
msg.holiday = holiday
|
||||
return msg;
|
||||
}
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Holiday Off"});
|
||||
return null;
|
||||
}
|
13
time-based/old/holiday-night.js
Normal file
13
time-based/old/holiday-night.js
Normal file
@ -0,0 +1,13 @@
|
||||
var states = global.get('homeassistant.homeAssistant.states')
|
||||
var holidayMode = states['input_boolean.holiday_mode'].state
|
||||
var currentHoliday = states['input_select.holiday_animation'].state
|
||||
var holiday = currentHoliday.toLowerCase()
|
||||
|
||||
if (holidayMode === 'on') {
|
||||
msg.holiday = holiday
|
||||
node.status({fill:"green",shape:"dot",text:"Holiday On"});
|
||||
return msg;
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Holiday Off"});
|
||||
return null;
|
||||
}
|
18
time-based/old/sunset-lights.js
Normal file
18
time-based/old/sunset-lights.js
Normal file
@ -0,0 +1,18 @@
|
||||
var states = global.get('homeassistant.homeAssistant.states')
|
||||
var sunsetLights = states['input_boolean.sunset_lights_on'].state
|
||||
var weather = states['weather.iron_nerd_weather_station'].state
|
||||
|
||||
if (sunsetLights === 'on') {
|
||||
if (weather === 'sunny' || weather === 'clear-night') {
|
||||
node.status({fill:"green",shape:"dot",text:"Nice Weather"});
|
||||
return[msg,null,null]
|
||||
} else {
|
||||
node.status({fill:"grey",shape:"dot",text:"Shitty Weather"});
|
||||
return[null,msg,null]
|
||||
}
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Disabled"});
|
||||
return[null,null,msg]
|
||||
}
|
||||
|
||||
return msg;
|
26
time-based/old/work-processing.js
Normal file
26
time-based/old/work-processing.js
Normal file
@ -0,0 +1,26 @@
|
||||
var tomorrow = msg.tomorrow
|
||||
var today = msg.today
|
||||
var number = {}
|
||||
var work_tomorrow = {}
|
||||
|
||||
if (tomorrow > 0) {
|
||||
work_tomorrow = "true"
|
||||
if (today == 0) {
|
||||
number = 0
|
||||
} else {
|
||||
number = 1
|
||||
}
|
||||
} else {
|
||||
work_tomorrow = "false"
|
||||
number = 0
|
||||
}
|
||||
|
||||
msg.work_tomorrow = work_tomorrow
|
||||
|
||||
if (number == 0) {
|
||||
node.status({fill:"green",shape:"dot",text:"Number 0"})
|
||||
return[msg,null]
|
||||
} else {
|
||||
node.status({fill:"green",shape:"dot",text:"Number 1"})
|
||||
return[null,msg]
|
||||
}
|
87
time-based/processing-start.js
Normal file
87
time-based/processing-start.js
Normal file
@ -0,0 +1,87 @@
|
||||
//! ---------- DAY MODE ----------
|
||||
// Lists of adaptive lighting switches for different scenarios
|
||||
const adaptiveDay = [
|
||||
"switch.adaptive_lighting_basement_studio",
|
||||
"switch.adaptive_lighting_dining_room_lamp",
|
||||
"switch.adaptive_lighting_downstairs_bathroom",
|
||||
"switch.adaptive_lighting_emma_bedroom",
|
||||
"switch.adaptive_lighting_kallen_bedroom",
|
||||
"switch.adaptive_lighting_living_room",
|
||||
"switch.adaptive_lighting_master_bedroom",
|
||||
"switch.adaptive_lighting_mud_room",
|
||||
"switch.adaptive_lighting_tina_lamp",
|
||||
"switch.adaptive_lighting_upstairs_bathroom",
|
||||
"switch.adaptive_lighting_upstairs_hallway",
|
||||
"switch.adaptive_lighting_front_porch"
|
||||
]
|
||||
|
||||
const adaptiveDayHoliday = [
|
||||
"switch.adaptive_lighting_basement_studio",
|
||||
"switch.adaptive_lighting_dining_room_lamp",
|
||||
"switch.adaptive_lighting_downstairs_bathroom",
|
||||
"switch.adaptive_lighting_emma_bedroom",
|
||||
"switch.adaptive_lighting_kallen_bedroom",
|
||||
"switch.adaptive_lighting_living_room",
|
||||
"switch.adaptive_lighting_master_bedroom",
|
||||
"switch.adaptive_lighting_mud_room",
|
||||
"switch.adaptive_lighting_tina_lamp",
|
||||
"switch.adaptive_lighting_upstairs_bathroom",
|
||||
"switch.adaptive_lighting_upstairs_hallway",
|
||||
]
|
||||
|
||||
// List of adaptive lighting sleep mode switches to turn off
|
||||
const adaptiveSleep = [
|
||||
"switch.adaptive_lighting_sleep_mode_basement_studio",
|
||||
"switch.adaptive_lighting_sleep_mode_dining_room_lamp",
|
||||
"switch.adaptive_lighting_sleep_mode_downstairs_bathroom",
|
||||
"switch.adaptive_lighting_sleep_mode_emma_bedroom",
|
||||
"switch.adaptive_lighting_sleep_mode_kallen_bedroom",
|
||||
"switch.adaptive_lighting_sleep_mode_living_room",
|
||||
"switch.adaptive_lighting_sleep_mode_master_bedroom",
|
||||
"switch.adaptive_lighting_sleep_mode_mud_room",
|
||||
"switch.adaptive_lighting_sleep_mode_tina_lamp",
|
||||
"switch.adaptive_lighting_sleep_mode_upstairs_bathroom",
|
||||
"switch.adaptive_lighting_sleep_mode_upstairs_hallway"
|
||||
]
|
||||
|
||||
// List of selected scene input texts to reset to Adaptive
|
||||
const selScenesMain = [
|
||||
"input_text.basement_studio_selected_scene",
|
||||
"input_text.dining_room_lamp_selected_scene",
|
||||
"input_text.downstairs_bathroom_selected_scene",
|
||||
"input_text.emma_bedroom_selected_scene",
|
||||
"input_text.front_porch_selected_scene",
|
||||
"input_text.kallen_bedroom_selected_scene",
|
||||
"input_text.living_room_selected_scene",
|
||||
"input_text.master_bedroom_selected_scene",
|
||||
"input_text.mud_room_selected_scene",
|
||||
"input_text.tina_lamp_selected_scene",
|
||||
"input_text.upstairs_bathroom_selected_scene",
|
||||
"input_text.upstairs_hallway_selected_scene"
|
||||
]
|
||||
|
||||
// Tina's desk reset
|
||||
const selScenesTinaDesk = ["input_text.tina_desk_selected_scene"]
|
||||
|
||||
// List of booleans to turn off
|
||||
const booleanOff = [
|
||||
"input_boolean.give_me_darkness",
|
||||
"input_boolean.goodnight",
|
||||
"input_boolean.kallen_computer_updates",
|
||||
"input_boolean.night_mode"
|
||||
]
|
||||
|
||||
//! ---------- NIGHT MODE ----------
|
||||
// Booleans to turn on at night
|
||||
const adaptiveNight = [
|
||||
"switch.adaptive_lighting_front_porch"
|
||||
]
|
||||
|
||||
|
||||
flow.set("adaptiveDay", adaptiveDay, "diskCon")
|
||||
flow.set("adaptiveDayHoliday", adaptiveDayHoliday, "diskCon")
|
||||
flow.set("adaptiveNight", adaptiveNight, "diskCon")
|
||||
flow.set("adaptiveSleep", adaptiveSleep, "diskCon")
|
||||
flow.set("selScenesMain", selScenesMain, "diskCon")
|
||||
flow.set("selScenesTinaDesk", selScenesTinaDesk, "diskCon")
|
||||
flow.set("booleanOff", booleanOff, "diskCon")
|
378
time-based/processing.js
Normal file
378
time-based/processing.js
Normal file
@ -0,0 +1,378 @@
|
||||
//! FLOW VARIABLES DEFINED IN START TAB
|
||||
|
||||
// Set Constants
|
||||
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const holidayMode = states['input_boolean.holiday_mode'].state
|
||||
const holidayHold = states['input_boolean.holiday_mode_hold'].state
|
||||
const currentHoliday = states['input_select.holiday_animation'].state
|
||||
const holiday = currentHoliday.toLowerCase()
|
||||
const sunsetLights = states['input_boolean.sunset_lights_on'].state
|
||||
const weather = states['weather.iron_nerd_weather_station'].state
|
||||
const vacation = states['input_boolean.vacation_mode'].state
|
||||
const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state
|
||||
const deskLights = states['light.tina_desk_lights'].state
|
||||
const adaptiveSleep = flow.get("adaptiveSleep", "diskCon")
|
||||
const selScenesMain = flow.get("selScenesMain", "diskCon")
|
||||
const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon")
|
||||
const booleanOff = flow.get("booleanOff", "diskCon")
|
||||
const payload = msg.payload
|
||||
node.log("Time-based Automations: Constants Set")
|
||||
|
||||
// Set a few important variables
|
||||
|
||||
let time = {}
|
||||
let topic = {}
|
||||
let delay = {}
|
||||
|
||||
if (payload == 0 || payload === 'weather') {
|
||||
time = "night"
|
||||
} else if (payload == 1) {
|
||||
time = "day"
|
||||
}
|
||||
|
||||
if (msg.topic === 'timer-finished' || msg.topic === 'manual-trigger' || msg.topic === 'weather') {
|
||||
topic = msg.topic
|
||||
}
|
||||
|
||||
if (topic === 'timer-finished' || topic === 'manual-trigger') {
|
||||
delay = 'off'
|
||||
} else if (topic === 'weather') {
|
||||
delay = 'off'
|
||||
} else if (weather === 'sunny' || weather === 'clear-night') {
|
||||
delay = 'on'
|
||||
} else {
|
||||
delay = 'off'
|
||||
}
|
||||
node.log("Time-based Automations: Main variables defined")
|
||||
|
||||
// ---------- Configuration ----------
|
||||
// Decide which nighttime lighting to turn off at sunrise
|
||||
let lightsOff = ["light.hallway_overhead"]
|
||||
|
||||
if (holidayHold === 'off') {
|
||||
lightsOff.push("light.front_porch_light")
|
||||
}
|
||||
|
||||
if (upBathOcc === 'off') {
|
||||
lightsOff.push("light.upstairs_bathroom_lights")
|
||||
}
|
||||
|
||||
// Stairwell light strip settings
|
||||
let stairKelvin = 2000
|
||||
let stairBrt = {}
|
||||
let stairEntity = ["light.stairwell_led_strip"]
|
||||
if (time === 'day') {
|
||||
stairBrt = 255
|
||||
} else if (time === 'night') {
|
||||
stairBrt = 150
|
||||
}
|
||||
|
||||
// Sunset lights timer settings
|
||||
let timerEntity = ["timer.sunset_lighting_timer"]
|
||||
let timerDuration = "00:30:00"
|
||||
|
||||
// Adaptive lighting switches to set
|
||||
let switchAdaptive = []
|
||||
let setAdaptive = {}
|
||||
|
||||
if (time === 'day') {
|
||||
if (holidayHold === 'on'){
|
||||
switchAdaptive = flow.get("adaptiveDayHoliday", "diskCon")
|
||||
} else {
|
||||
switchAdaptive = flow.get("adaptiveDay", "diskCon")
|
||||
}
|
||||
setAdaptive = 'on'
|
||||
} else if (time === 'night') {
|
||||
switchAdaptive = flow.get("adaptiveNight", "diskCon")
|
||||
if (holidayMode === 'on') {
|
||||
setAdaptive = 'off'
|
||||
} else {
|
||||
setAdaptive = 'on'
|
||||
}
|
||||
}
|
||||
|
||||
// Notification settings
|
||||
let notifyTitle = {}
|
||||
let notifyMsg = {}
|
||||
let sunsetStatus = {}
|
||||
if (sunsetLights === 'off') {
|
||||
notifyTitle = "Sunset Lights SKIPPED"
|
||||
notifyMsg = "Lights not on due to nobody home, or toggle shutoff"
|
||||
sunsetStatus = "Skipped"
|
||||
} else {
|
||||
notifyTitle = "Sunset Lights On"
|
||||
if (topic === 'weather') {
|
||||
notifyMsg = "Lights on, delay cancelled due to weather change"
|
||||
sunsetStatus = "Weather Change"
|
||||
} else if (delay === 'on') {
|
||||
notifyMsg = "Lights on after delay due to clear weather"
|
||||
sunsetStatus = "Delayed"
|
||||
} else if (delay === 'off') {
|
||||
notifyMsg = "Lights on early due to cloudy weather"
|
||||
sunsetStatus = "Early"
|
||||
}
|
||||
}
|
||||
|
||||
// Holiday Settings
|
||||
let setHoliday = {}
|
||||
let switchHoliday = ["switch.animated_scene_" + holiday]
|
||||
if (holidayMode === 'on') {
|
||||
if (time === 'day') {
|
||||
setHoliday = 'off'
|
||||
} else if (time === 'night') {
|
||||
setHoliday = 'on'
|
||||
}
|
||||
}
|
||||
|
||||
node.log("Time-based Automations: Decision Logic Complete")
|
||||
|
||||
// ---------- Service Calls ----------
|
||||
let sendLights = {
|
||||
"payload": {
|
||||
"domain": "light",
|
||||
"service": "turn_off",
|
||||
"target": {
|
||||
"entity_id": lightsOff
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendStairwellScript = {
|
||||
"payload": {
|
||||
"domain": "script",
|
||||
"service": "stairwell_led_strip",
|
||||
"data": {
|
||||
"color_temp_kelvin": stairKelvin,
|
||||
"brightness": stairBrt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendStairwellOff = {
|
||||
"payload": {
|
||||
"domain": "light",
|
||||
"service": "turn_off",
|
||||
"target": {
|
||||
"entity_id": stairEntity
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendSleepOff = {
|
||||
"payload": {
|
||||
"domain": "switch",
|
||||
"service": "turn_off",
|
||||
"target": {
|
||||
"entity_id": adaptiveSleep
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendBooleanOff = {
|
||||
"payload": {
|
||||
"domain": "input_boolean",
|
||||
"service": "turn_off",
|
||||
"target": {
|
||||
"entity_id": booleanOff
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendAdaptive = {
|
||||
"payload": {
|
||||
"domain": "switch",
|
||||
"service": "turn_" + setAdaptive,
|
||||
"target": {
|
||||
"entity_id": switchAdaptive
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendSceneResetMain = {
|
||||
"payload": {
|
||||
"domain": "input_text",
|
||||
"service": "set_value",
|
||||
"target": {
|
||||
"entity_id": selScenesMain
|
||||
},
|
||||
"data": {
|
||||
"option": "Adaptive"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendSceneResetDesk = {
|
||||
"payload": {
|
||||
"domain": "input_text",
|
||||
"service": "set_value",
|
||||
"target": {
|
||||
"entity_id": selScenesTinaDesk
|
||||
},
|
||||
"data": {
|
||||
"option": "Day Mode"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendHoliday = {
|
||||
"payload": {
|
||||
"domain": "switch",
|
||||
"service": "turn_" + setHoliday,
|
||||
"target": {
|
||||
"entity_id": switchHoliday
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendTimer = {
|
||||
"payload": {
|
||||
"domain": "timer",
|
||||
"service": "start",
|
||||
"target": {
|
||||
"entity_id": timerEntity
|
||||
},
|
||||
"data": {
|
||||
"duration": timerDuration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendTimerCancel = {
|
||||
"payload": {
|
||||
"domain": "timer",
|
||||
"service": "cancel",
|
||||
"target": {
|
||||
"entity_id": timerEntity
|
||||
},
|
||||
"data": {}
|
||||
}
|
||||
}
|
||||
|
||||
let sendNotifyPhone = {
|
||||
"payload": {
|
||||
"domain": "script",
|
||||
"service": "text_notify",
|
||||
"data": {
|
||||
"who": "all",
|
||||
"title": notifyTitle,
|
||||
"message": notifyMsg,
|
||||
"type": "normal",
|
||||
"tag": "sunset-lights"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendNotifyTV = {
|
||||
"payload": {
|
||||
"domain": "script",
|
||||
"service": "tv_notify",
|
||||
"data": {
|
||||
"who": "all",
|
||||
"title": notifyTitle,
|
||||
"message": notifyMsg,
|
||||
"data": {
|
||||
"fontsize": "large",
|
||||
"duration": 3,
|
||||
"transparency": "25%"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendFirstFloorScene = {
|
||||
"payload": {
|
||||
"domain": "script",
|
||||
"service": "evening_on_first_floor",
|
||||
"data": {
|
||||
"sunset_lights": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendSecondFloorScene = {
|
||||
"payload": {
|
||||
"domain": "script",
|
||||
"service": "evening_on_second_floor",
|
||||
"data": {
|
||||
"sunset_lights": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let sendDeskScene = {
|
||||
"payload": {
|
||||
"domain": "input_select",
|
||||
"service": "select_option",
|
||||
"target": {
|
||||
"entity_id": ["input_select.tina_desk_scenes"]
|
||||
},
|
||||
"data": {
|
||||
"option": "Reset"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node.log("Time-based Automations: Message Payloads Defined")
|
||||
|
||||
node.log("----- Time-based Automations: Set Parameters")
|
||||
node.log("time: " + time)
|
||||
node.log("topic: " + topic)
|
||||
node.log("lightsOff: " + lightsOff)
|
||||
node.log("stairKelvin: " + stairKelvin)
|
||||
node.log("stairBrt: " + stairBrt)
|
||||
node.log("holidayMode: " + holidayMode)
|
||||
if (time === 'night') {
|
||||
node.log("weather: " + weather)
|
||||
node.log("delay: " + delay)
|
||||
node.log("sunsetStatus: " + sunsetStatus)
|
||||
}
|
||||
if (holidayMode === 'on') {
|
||||
node.log("switchHoliday: " + switchHoliday)
|
||||
node.log("holiday: " + holiday)
|
||||
node.log("holidayHold: " + holidayHold)
|
||||
node.log("switchHoliday: " + switchHoliday)
|
||||
}
|
||||
node.log("----- Time-based Automations: End Parameters -----")
|
||||
|
||||
if (vacation === 'off') {
|
||||
if (time === "day") {
|
||||
node.status({fill:"green",shape:"dot",text:"Sunrise Flow"})
|
||||
node.send([null,[sendLights,sendBooleanOff],sendStairwellScript])
|
||||
setTimeout(() => {
|
||||
node.send([null,[sendStairwellOff,sendSleepOff,sendAdaptive,sendSceneResetMain,sendSceneResetDesk],null])
|
||||
if (holidayMode === 'on' && holidayHold === 'off') {
|
||||
node.send([null,[sendHoliday],null])
|
||||
}
|
||||
}, 5000)
|
||||
} else if (time === "night") {
|
||||
node.status({fill:"green",shape:"dot",text:"Sunset Flow"})
|
||||
node.send([null,sendAdaptive,null])
|
||||
if (holidayMode === 'on') {
|
||||
setTimeout(() => {
|
||||
node.send([null,sendHoliday,null])
|
||||
}, 1000)
|
||||
}
|
||||
if (delay === 'on') {
|
||||
node.send([null,sendTimer,null])
|
||||
} else {
|
||||
if (topic === 'weather') {
|
||||
node.send([null,sendTimerCancel,null])
|
||||
}
|
||||
node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene]])
|
||||
if (deskLights === 'on') {
|
||||
node.send([null,sendDeskScene,null])
|
||||
}
|
||||
if (topic != 'manual-trigger') {
|
||||
node.send([[sendNotifyPhone,sendNotifyTV],null,null])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
node.log("Time-based Automations: Processing Complete")
|
Reference in New Issue
Block a user