24 lines
804 B
JavaScript
24 lines
804 B
JavaScript
// 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"})
|
|
} |