Initial commit
This commit is contained in:
34
sports/events-today.js
Normal file
34
sports/events-today.js
Normal file
@ -0,0 +1,34 @@
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const teams = flow.get("teams", "diskCon")
|
||||
let teamsToday = []
|
||||
let options = []
|
||||
|
||||
for (let index = 0; index < teams.length; index++) {
|
||||
const element = teams[index];
|
||||
let sensor = "sensor." + element
|
||||
let binary_today = "binary_sensor." + element + "_event_today"
|
||||
let binary_inhibit = "binary_sensor." + element + "_inhibit"
|
||||
let today = states[binary_today].state
|
||||
let inhibit = states[binary_inhibit].state
|
||||
let teamName = states[sensor].attributes.friendly_name
|
||||
if (today === 'on' && inhibit === 'off') {
|
||||
teamsToday.push(teamName)
|
||||
}
|
||||
}
|
||||
|
||||
flow.set("teamsToday", teamsToday, "diskCon")
|
||||
|
||||
if (teamsToday.length > 0) {
|
||||
options = teamsToday
|
||||
node.status({fill:"green",shape:"dot",text:"Events today: " + teamsToday.length})
|
||||
} else {
|
||||
options = ['No events today']
|
||||
node.status({fill:"red",shape:"ring",text:"No events today"});
|
||||
}
|
||||
|
||||
msg.payload = {
|
||||
"options": options
|
||||
}
|
||||
|
||||
node.send(msg)
|
||||
node.done
|
Reference in New Issue
Block a user