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
|
10
sports/notes.json
Normal file
10
sports/notes.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"teamScore": 0,
|
||||
"teamPreviousScore": 0,
|
||||
"_msgid": "75e0427b3d2626fd"
|
||||
}
|
||||
{
|
||||
"oppScore": 0,
|
||||
"oppPreviousScore": 0,
|
||||
"_msgid": "c9945886cc6bd22e"
|
||||
}
|
24
sports/scores.js
Normal file
24
sports/scores.js
Normal file
@ -0,0 +1,24 @@
|
||||
// Get sensor
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const active = states['switch.watching_sports'].state
|
||||
|
||||
if (active === 'on') {
|
||||
// Get scores
|
||||
const team = flow.get("team")
|
||||
const teamSensor = states["sensor." + team]
|
||||
const status = teamSensor.state
|
||||
if (status === 'IN') {
|
||||
const teamScore = teamSensor.attributes.team_score
|
||||
const oppScore = teamSensor.attributes.opponent_score
|
||||
msg = {
|
||||
"teamscore": teamScore,
|
||||
"oppscore": oppScore
|
||||
}
|
||||
node.status({fill:"green",shape:"dot",text:"Score: " + teamScore + "-" + oppScore})
|
||||
node.send(msg)
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Not in game"})
|
||||
}
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Inactive"})
|
||||
}
|
Reference in New Issue
Block a user