Files
HA-NerdFlows-Functions/kallen-timer/timer-change.js

20 lines
598 B
JavaScript

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 subtract = newState - oldState
const multiply = subtract * 60
const diff = parseInt(multiply)
const running = states["timer.kallen_timer"].state
let changeMsg = {
"timer": "timer.kallen_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"})
}