5 Commits

4 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,33 @@
const states = global.get('homeassistant.homeAssistant.states')
const allowed = states['input_boolean.basement_studio_heat_allowed'].state
const outsideTemp = states['weather.iron_nerd_weather_station'].attributes.temperature
const todaysHighTemp = states['sensor.todays_high_temp'].state
const basementTemp = states['sensor.basement_studio_temperature'].state
let power = {}
let reason = {}
if (todaysHighTemp < 55) {
power = 'on'
reason = 'Todays High Temperature'
} else if (outsideTemp < 40) {
power = 'on'
reason = 'Outside Temperature'
} else if (basementTemp < 64) {
power = 'on'
reason = 'Basement Temperature'
} else {
power = 'off'
}
if (allowed === 'on') {
if (power === 'on') {
node.status({fill:'green',shape:'dot',text:'Heater Needed: ' + reason})
node.send(msg,null)
} else {
node.status({fill:'red',shape:'ring',text:'Heater Not Needed'})
node.send(null,msg)
}
} else {
node.status({fill:'red',shape:'ring',text:'Heat Disabled'})
}

View File

@ -0,0 +1,26 @@
let tomorrow = msg.tomorrow
let today = msg.today
let number = {}
let 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
node.status({fill:"green",shape:"dot",text:"Number " + number})
if (number == 0) {
node.send([msg,null])
} else {
node.send([null,msg])
}

46
weather/alerts_filter.js Normal file
View File

@ -0,0 +1,46 @@
let alerts = msg.payload
// Filter for Severe Thunderstorm Warnings
let ts = alerts.filter(function(alert) {
if (alert.raw.properties &&
alert.raw.properties.event === "Severe Thunderstorm Warning") {
return true
}
})
// Filter for Severe Thunderstorm Warnings with tornado detection
// that have a tornado possible parameter
let tstp = alerts.filter(function(alert) {
if (alert.raw.properties &&
alert.raw.properties.event === "Severe Thunderstorm Warning" &&
alert.raw.properties.parameters &&
alert.raw.properties.parameters.tornadoDetection &&
alert.raw.properties.parameters.tornadoDetection.length > 0) {
let tornadoPossible = alert.raw.properties.parameters.tornadoDetection[0]
return tornadoPossible === "POSSIBLE"
}
})
// Filter for Tornado Warnings
let tornado = alerts.filter(function(alert) {
if (alert.raw.properties &&
alert.raw.properties.event === "Tornado Warning") {
return true
}
})
// If there are any alerts, return them
msg.ts = ts
msg.ts_count = ts.length
msg.tstp = tstp
msg.tstp_count = tstp.length
msg.tornado = tornado
msg.tornado_count = tornado.length
return msg

46
weather/defiance.js Normal file
View File

@ -0,0 +1,46 @@
let alerts = msg.payload.features
// Filter for Severe Thunderstorm Warnings
let ts = alerts.filter(function(alert) {
if (alert.properties &&
alert.properties.event === "Severe Thunderstorm Warning") {
return true
}
})
// Filter for Severe Thunderstorm Warnings with tornado detection
// that have a tornado possible parameter
let tstp = alerts.filter(function(alert) {
if (alert.properties &&
alert.properties.event === "Severe Thunderstorm Warning" &&
alert.properties.parameters &&
alert.properties.parameters.tornadoDetection &&
alert.properties.parameters.tornadoDetection.length > 0) {
let tornadoPossible = alert.properties.parameters.tornadoDetection[0]
return tornadoPossible === "POSSIBLE"
}
})
// Filter for Tornado Warnings
let tornado = alerts.filter(function(alert) {
if (alert.properties &&
alert.properties.event === "Tornado Warning") {
return true
}
})
// If there are any alerts, return them
msg.ts = ts
msg.ts_count = ts.length
msg.tstp = tstp
msg.tstp_count = tstp.length
msg.tornado = tornado
msg.tornado_count = tornado.length
return msg