Initial commit
This commit is contained in:
40
laundry/timer-change.js
Normal file
40
laundry/timer-change.js
Normal file
@ -0,0 +1,40 @@
|
||||
const states = global.get('homeassistant.homeAssistant.states')
|
||||
const oldState = msg.data.old_state.state
|
||||
const newState = msg.data.new_state.state
|
||||
const entity_id = msg.data.entity_id
|
||||
const washerCycle = flow.get("washerCycle", "diskCon")
|
||||
const dryerCycle = flow.get("dryerCycle", "diskCon")
|
||||
|
||||
const subtract = newState - oldState
|
||||
const multiply = subtract * 60
|
||||
const diff = parseInt(multiply)
|
||||
|
||||
let machine = {}
|
||||
let timer = {}
|
||||
|
||||
if (entity_id === washerCycle) {
|
||||
machine = 'washer'
|
||||
} else if (entity_id === dryerCycle) {
|
||||
machine = 'dryer'
|
||||
}
|
||||
|
||||
if (machine === 'washer') {
|
||||
timer = flow.get("washerTimer", "diskCon")
|
||||
} else if (machine === 'dryer') {
|
||||
timer = flow.get("dryerTimer", "diskCon")
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
let running = states[timer].state
|
||||
|
||||
let changeMsg = {
|
||||
"timer": timer,
|
||||
"change": diff
|
||||
}
|
||||
|
||||
if (running === 'active') {
|
||||
node.send(changeMsg)
|
||||
node.status({fill:"green",shape:"dot",text:"Timer Changed"})
|
||||
} else {
|
||||
node.status({fill:"red",shape:"ring",text:"Blocked"})
|
||||
}
|
Reference in New Issue
Block a user