const states = global.get('homeassistant.homeAssistant.states') const vacationMode = states['input_boolean.vacation_mode'].state const overnight = states['input_boolean.kallen_overnight'].state const kallenLoc = states['person.kallen_stork'].state const nightVolume = states['input_number.kallen_bedroom_google_speaker_night_volume'].state const brightness = states['switch.adaptive_lighting_kallen_bedroom'].attributes.brightness_pct const fadeDay = states['input_number.wakeup_lights_fade_day'].state const fadeNight = states['input_number.wakeup_lights_fade_night'].state const hotDay = states['input_boolean.hot_day'].state const heatWarning = states['binary_sensor.heat_warning'].state const fanSeparate = states['binary_sensor.kallen_fan_separate_schedule'].state const topic = msg.topic const toggle = msg.toggle let fan = [] if (hotDay === 'on' || heatWarning === 'on') { fan = 'on' } else { fan = 'off' } if (vacationMode === 'off' && overnight === 'off' && kallenLoc === 'home') { if (topic === 'kallen-fan' && fanSeparate === 'on') { node.status({fill:"green",shape:"dot",text:"Fan"}); return[null,null,null,msg] } else if (toggle === 'off') { msg.brightness = brightness msg.fade_day = fadeDay * 60 msg.fade_night = fadeNight * 60 msg.fan = fan node.status({fill:"green",shape:"dot",text:"Wakeup"}); return[null,msg,null,null] } else if (toggle === 'on') { msg.volume = nightVolume node.status({fill:"green",shape:"dot",text:"Sleep"}); return[null,null,msg,null] } } else { if (topic === 'boolean') { msg.toggle = 'off' node.status({fill:"red",shape:"ring",text:"Blocked"}); return [msg,null,null,null] } else { node.status({fill:"red",shape:"ring",text:"Blocked"}); return null } }