10 Commits

8 changed files with 127 additions and 80 deletions

View File

@ -0,0 +1,21 @@
const topic = msg.topic
const payload = msg.payload
const lastMode = flow.get('emmaBedroom.lastMode', 'diskCon')
if (topic === 'daytemp') {
flow.set('emmaBedroom.dayTemp', payload, 'diskCon')
} else if (topic === 'nighttemp') {
flow.set("emmaBedroom.nightTemp", payload, "diskCon")
} else if (topic === 'bedtemp') {
flow.set("emmaBedroom.bedTemp", payload, "diskCon")
}
if (lastMode === 'day') {
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.dayTemp', 'diskCon'), 'diskCon')
} else if (lastMode === 'night') {
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.nightTemp', 'diskCon'), 'diskCon')
} else if (lastMode === 'bedtime') {
flow.set('emmaBedroom.airconTargetTemp', flow.get('emmaBedroom.bedTemp', 'diskCon'), 'diskCon')
}
node.status({fill:'green',shape:'dot',text:`Set ${topic} to ${payload}`})

View File

@ -1,5 +1,6 @@
const states = global.get('homeassistant.homeAssistant.states') const states = global.get('homeassistant.homeAssistant.states')
const earlyNightMode = states['binary_sensor.early_night_mode'].state const outdoorLux = parseInt(states['sensor.home_tempest_illuminance'].state)
const threshold = parseInt(states['input_number.front_porch_lux_threshold'].state)
const frontPorchToggle = states['input_boolean.front_porch_light_on'].state const frontPorchToggle = states['input_boolean.front_porch_light_on'].state
const holidaymode = states['input_boolean.holiday_mode'].state const holidaymode = states['input_boolean.holiday_mode'].state
const currentholiday = states['input_select.holiday_animation'].state const currentholiday = states['input_select.holiday_animation'].state
@ -9,7 +10,7 @@ let holidayMsg = {
"holiday": holiday "holiday": holiday
} }
if (earlyNightMode === 'on' && frontPorchToggle === 'on') { if ((outdoorLux <= threshold) && frontPorchToggle === 'on') {
if (holidaymode === 'on') { if (holidaymode === 'on') {
node.status({fill:"blue",shape:"dot",text:"Holiday On"}) node.status({fill:"blue",shape:"dot",text:"Holiday On"})
node.send([holidayMsg,msg]) node.send([holidayMsg,msg])
@ -20,7 +21,7 @@ if (earlyNightMode === 'on' && frontPorchToggle === 'on') {
} else { } else {
if (frontPorchToggle === 'off') { if (frontPorchToggle === 'off') {
node.status({ fill: "red", shape: "ring", text: "Disabled" }) node.status({ fill: "red", shape: "ring", text: "Disabled" })
} else if (earlyNightMode === 'off') { } else if (outdoorLux > threshold) {
node.status({ fill: "red", shape: "ring", text: "Daytime" }) node.status({ fill: "red", shape: "ring", text: "Daytime" })
} }
} }

View File

@ -3,11 +3,13 @@ const lights = states['light.kallen_bedroom_lights'].state
const duration = states['input_number.kallen_bedroom_lights_off_delay'].state const duration = states['input_number.kallen_bedroom_lights_off_delay'].state
const lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state) const lux = parseInt(states['sensor.kallen_bedroom_illuminance'].state)
const threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state) const threshold = parseInt(states['input_number.kallen_bedroom_lux_threshold'].state)
const sleeping = states['input_boolean.kallen_sleeping'].state const kallenBedroomSleep = states['input_boolean.kallen_sleeping'].state
const masterBedroomSleep = states['input_boolean.master_bedroom_sleeping'].state
const peopleSleeping = (masterBedroomSleep === 'on' || kallenBedroomSleep === 'on')
const payload = msg.payload const payload = msg.payload
const newDuration = duration * 60 const newDuration = duration * 60
if (sleeping === 'off') { if (peopleSleeping === false) {
if (payload === 'on') { if (payload === 'on') {
if (lux <= threshold && lights === 'off') { if (lux <= threshold && lights === 'off') {
node.status({fill:'green',shape:'dot',text:'Turning lights on'}) node.status({fill:'green',shape:'dot',text:'Turning lights on'})

View File

@ -1,18 +1,27 @@
const states = global.get('homeassistant.homeAssistant.states') const states = global.get('homeassistant.homeAssistant.states')
const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state
const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state
const timer = states['timer.sunset_lighting_timer'].state const luxThresholdOutdoor = states['input_number.sunset_lights_outdoor_lux_threshold'].state
const earlyNight = states['binary_sensor.early_night_mode'].state
const triggered = states['input_boolean.sunset_lights_triggered'].state
const level = msg.level const level = msg.level
const room = msg.room const room = msg.room
if (timer === 'active') { if (earlyNight === 'on' && triggered === 'off') {
if (room === 'living-room' && level <= luxThresholdLivingRoom) { if (room === 'living-room' && level <= luxThresholdLivingRoom) {
node.status({fill:'green',shape:'dot',text:'Sent (Living Room)'}) node.status({fill:'green',shape:'dot',text:'Sent (Living Room)'})
node.send(msg) node.send([msg,msg])
} else if (room === 'stairwell-bottom' && level <= luxThresholdStairwell) { } else if (room === 'stairwell-bottom' && level <= luxThresholdStairwell) {
node.status({fill:'green',shape:'dot',text:'Sent (Stairwell Bottom)'}) node.status({fill:'green',shape:'dot',text:'Sent (Stairwell Bottom)'})
node.send(msg) node.send([msg,msg])
} else if (room === 'outdoor' && level <= luxThresholdOutdoor) {
node.status({fill:'green',shape:'dot',text:'Sent (Outdoor)'})
node.send([msg,msg])
} }
} else if (earlyNight === 'off') {
node.status({fill:'red',shape:'ring',text:'Not Evening'})
} else if (triggered === 'on') {
node.status({fill:'red',shape:'ring',text:'Already Triggered'})
} else { } else {
node.status({fill:'red',shape:'ring',text:'Blocked'}) node.status({fill:'red',shape:'ring',text:'No Action'})
} }

View File

@ -64,7 +64,8 @@ const booleanOff = [
"input_boolean.give_me_darkness", "input_boolean.give_me_darkness",
"input_boolean.goodnight", "input_boolean.goodnight",
"input_boolean.kallen_computer_updates", "input_boolean.kallen_computer_updates",
"input_boolean.night_mode" "input_boolean.night_mode",
"input_boolean.sunset_lights_triggered"
] ]
//! ---------- NIGHT MODE ---------- //! ---------- NIGHT MODE ----------

View File

@ -11,22 +11,18 @@ const sunsetLights = states['input_boolean.sunset_lights_on'].state
const vacation = states['input_boolean.vacation_mode'].state const vacation = states['input_boolean.vacation_mode'].state
const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state const upBathOcc = states['binary_sensor.upstairs_bathroom_occupied'].state
const deskLights = states['light.tina_desk_lights'].state const deskLights = states['light.tina_desk_lights'].state
const luxLivingRoom = states['sensor.living_room_front_illuminance'].state
const luxThresholdLivingRoom = states['input_number.living_room_lux_threshold'].state
const luxStairwell = states['sensor.stairwell_bottom_illuminance'].state
const luxThresholdStairwell = states['input_number.stairwell_lux_threshold'].state
const adaptiveSleep = flow.get("adaptiveSleep", "diskCon") const adaptiveSleep = flow.get("adaptiveSleep", "diskCon")
const selScenesMain = flow.get("selScenesMain", "diskCon") const selScenesMain = flow.get("selScenesMain", "diskCon")
const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon") const selScenesTinaDesk = flow.get("selScenesTinaDesk", "diskCon")
const booleanOff = flow.get("booleanOff", "diskCon") const booleanOff = flow.get("booleanOff", "diskCon")
const triggered = states['input_boolean.sunset_lights_triggered'].state
const payload = msg.payload const payload = msg.payload
const topic = msg.topic
node.log("Time-based Automations: Constants Set") node.log("Time-based Automations: Constants Set")
// Set a few important variables // Set a few important variables
let time = {} let time = {}
let topic = {}
let delay = {}
let eventCall = {} let eventCall = {}
if (payload == 0) { if (payload == 0) {
@ -37,17 +33,6 @@ if (payload == 0) {
eventCall = "off" eventCall = "off"
} }
if (msg.topic === 'timer-finished' || msg.topic === 'manual-trigger' || msg.topic === 'lux') {
topic = msg.topic
}
if (topic === 'timer-finished' || topic === 'manual-trigger' || topic === 'lux') {
delay = 'off'
} else if (luxLivingRoom > luxThresholdLivingRoom && luxStairwell > luxThresholdStairwell) {
delay = 'on'
} else {
delay = 'off'
}
node.log("Time-based Automations: Main variables defined") node.log("Time-based Automations: Main variables defined")
// ---------- Configuration ---------- // ---------- Configuration ----------
@ -96,19 +81,8 @@ if (sunsetLights === 'off') {
sunsetStatus = "Skipped" sunsetStatus = "Skipped"
} else { } else {
notifyTitle = "Sunset Lights On" notifyTitle = "Sunset Lights On"
if (topic === 'timer-finished') { notifyMsg = "It's getting dark, evening lighting is now active"
notifyMsg = "Lights on because timer was finished manually" sunsetStatus = "Light Level Trigger"
sunsetStatus = "Manual Trigger"
} else if (topic === 'lux') {
notifyMsg = "Lights on because light level dropped below threshold"
sunsetStatus = "Light Level Trigger"
} else if (delay === 'on') {
notifyMsg = "Lights on after delay due to sufficient light"
sunsetStatus = "Delayed"
} else if (delay === 'off') {
notifyMsg = "Lights on early due to low light"
sunsetStatus = "Early"
}
} }
// Holiday Settings // Holiday Settings
@ -125,6 +99,17 @@ if (holidayMode === 'on') {
node.log("Time-based Automations: Decision Logic Complete") node.log("Time-based Automations: Decision Logic Complete")
// ---------- Service Calls ---------- // ---------- Service Calls ----------
let sendTriggered = {
"payload": {
"action": "input_boolean.turn_on",
"target": {
"entity_id": ["input_boolean.sunset_lights_triggered"]
},
"data": {}
}
}
let sendLights = { let sendLights = {
"payload": { "payload": {
"action": "light.turn_off", "action": "light.turn_off",
@ -199,28 +184,6 @@ let sendHoliday = {
} }
} }
let sendTimer = {
"payload": {
"action": "timer.start",
"target": {
"entity_id": timerEntity
},
"data": {
"duration": timerDuration
}
}
}
let sendTimerCancel = {
"payload": {
"action": "timer.cancel",
"target": {
"entity_id": timerEntity
},
"data": {}
}
}
let sendNotifyPhone = { let sendNotifyPhone = {
"payload": { "payload": {
"action": "script.text_notify", "action": "script.text_notify",
@ -298,11 +261,6 @@ node.log("lightsOff: " + lightsOff)
node.log("holidayMode: " + holidayMode) node.log("holidayMode: " + holidayMode)
node.log("eventCall: " + eventCall) node.log("eventCall: " + eventCall)
if (time === 'night') { if (time === 'night') {
node.log("luxLivingRoom: " + luxLivingRoom)
node.log("luxThresholdLivingRoom: " + luxThresholdLivingRoom)
node.log("luxStairwell: " + luxStairwell)
node.log("luxThresholdStairwell: " + luxThresholdStairwell)
node.log("delay: " + delay)
node.log("sunsetStatus: " + sunsetStatus) node.log("sunsetStatus: " + sunsetStatus)
} }
if (holidayMode === 'on') { if (holidayMode === 'on') {
@ -324,18 +282,13 @@ if (vacation === 'off') {
} }
}, 5000) }, 5000)
} else if (time === "night") { } else if (time === "night") {
node.status({fill:"green",shape:"dot",text:"Sunset Flow"}) if (triggered === 'off') {
node.send([null,sendAdaptive,null,null]) node.status({fill:"green",shape:"dot",text:"Sunset Flow"})
if (holidayMode === 'on') { node.send([null,[sendAdaptive,sendTriggered],null,null])
setTimeout(() => { if (holidayMode === 'on') {
node.send([null,sendHoliday,null,null]) setTimeout(() => {
}, 1000) node.send([null,sendHoliday,null,null])
} }, 1000)
if (delay === 'on') {
node.send([null,sendTimer,null,null])
} else {
if (topic === 'lux') {
node.send([null,sendTimerCancel,null,null])
} }
node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights]) node.send([null,null,[sendFirstFloorScene,sendSecondFloorScene],sendExtraLights])
if (deskLights === 'on') { if (deskLights === 'on') {
@ -344,6 +297,8 @@ if (vacation === 'off') {
if (topic != 'manual-trigger') { if (topic != 'manual-trigger') {
node.send([[sendNotifyPhone,sendNotifyTV],null,null,null]) node.send([[sendNotifyPhone,sendNotifyTV],null,null,null])
} }
} else {
node.status({fill:'green',shape:'dot',text:'Sunset Flow (Already Triggered)'})
} }
} }
} }

View File

@ -0,0 +1,17 @@
const states = global.get('homeassistant.homeAssistant.states')
const precipType = states['sensor.home_tempest_precipitation_type'].state
const precipIntensity = states['sensor.home_tempest_cloud_sensors_precipitation_intensity'].state
const typeStatesRaining = ['rain','hail','rain_hail']
const intensityStatesRaining = ['very_light','light','moderate','heavy','very_heavy','extreme']
const isTypeRaining = typeStatesRaining.includes(precipType)
const isIntensityRaining = intensityStatesRaining.includes(precipIntensity)
const isRaining = isTypeRaining || isIntensityRaining
flow.set('typeStatesRaining', typeStatesRaining)
flow.set('intensityStatesRaining', intensityStatesRaining)
flow.set('isRaining', isRaining)
return null

41
weather/station_slp.js Normal file
View File

@ -0,0 +1,41 @@
const states = global.get('homeassistant.homeAssistant.states')
const temp_F = states['sensor.home_tempest_temperature'].state
const elevation_ft = 693
// Get the pressure from the payload
let pressure_inHg = msg.payload
if (isNaN(pressure_inHg)) {
node.error("Invalid pressure value in msg.payload: " + msg.payload)
msg.payload = null
return null
}
// Convert pressure from inHg to hPa
let pressure_hPa = pressure_inHg * 33.8639
// Convert temperature to °C
let temp_C = (temp_F - 32) * (5 / 9)
// Convert elevation from feet to meters
let elevation_m = elevation_ft / 3.28084
// Apply the barometric formula
let slp = pressure_hPa * Math.pow(
1 - ((0.0065 * elevation_m) / (temp_C + (0.0065 * elevation_m) + 273.15)),
-5.257
)
// Optional: Convert back to inHg
let slp_inHg = slp / 33.8639
// Round both values
slp = Math.round(slp * 100) / 100
slp_inHg = Math.round(slp_inHg * 100) / 100
// Return the SLP value
msg.payload = slp_inHg
node.status({fill:'Success',shape:'dot',text:'green'})
return msg