Skip to content

Instantly share code, notes, and snippets.

@johnlpage
Created March 17, 2022 09:36
Show Gist options
  • Save johnlpage/a0c6116e3a6dc57af0e66f8106e25014 to your computer and use it in GitHub Desktop.
Save johnlpage/a0c6116e3a6dc57af0e66f8106e25014 to your computer and use it in GitHub Desktop.
exports = async function() {
let APIKEY = context.values.get('ifftkey_value')
const collection = context.services.get("mongodb-atlas").db("energy").collection("meter");
const docs = await collection.find({ type: "electric" }).sort({_id:-1}).limit(1).toArray();
if(docs.length == 1)
{
if(docs[0].solarwatts > 800) {
console.log("turning off lights")
const response = context.http.get({ url: `https://maker.ifttt.com/trigger/AllLightsOff/with/key/${APIKEY}` })
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment