Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.