Last active
October 24, 2017 18:36
-
-
Save edhemphill/f828573fd8a4c37546d1028688fc3a55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var resourceID = "VirtualTemperature74"; | |
var temperature; | |
var currentlyRaised = false; | |
function raiseAlert() { | |
dev$.alert('Temperature Too Low', 'warning', true, { | |
temp: temperature | |
}); | |
currentlyRaised = true; | |
log.info('Temperature Too Low, alert raised!!'); | |
} | |
function lowerAlert() { | |
dev$.alert('Temperature Too Low', 'warning', false, { | |
temp: temperature | |
}); | |
currentlyRaised = false; | |
log.info('Temperature Too Low, alert lowered!!'); | |
} | |
function checkAlertCondition() { | |
if(temperature < 65 && !currentlyRaised) { | |
raiseAlert(); | |
} else if(temperature > 65 && currentlyRaised) { | |
lowerAlert(); | |
} | |
} | |
// if the temperature changes, check to see if we should raise or lower an alert. | |
var allStates = dev$.selectByID(resourceID); | |
allStates.subscribeToState('+'); | |
allStates.on('state', function(id, type, data) { | |
if(id == resourceID) { | |
temperature = data; | |
log.info('Got temperature state from ' + resourceID + ' data ' + temperature); | |
checkAlertCondition(); | |
} | |
}); | |
// If the motion sensor goes off, turn the Enocean swithc on | |
var allEvents = dev$.selectByID("ZW010f200108013"); | |
allEvents.subscribeToEvent('+'); | |
allEvents.on('event', function(id, type, data) { | |
if(id == 'ZW010f200108013' && type == 'motion' && data === true) { | |
dev$.selectByID('AD_HOC_ELECTRONICS_04019f5a').set('brightness', 0.5); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment