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
| import requests | |
| from pprint import pprint | |
| import json | |
| import pymongo | |
| with open("/home/pi/.mongo_uri.txt") as f: | |
| uri = f.readline().strip() | |
| mongoclient = pymongo.MongoClient(uri) |
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
| from phue import Bridge | |
| from pprint import pprint | |
| import pymongo | |
| b = Bridge("192.168.1.214") | |
| # If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time) | |
| b.connect() | |
| # Get the bridge state (This returns the full dictionary that you can explore) |
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
| import aiohttp | |
| import pysmartthings | |
| import pymongo | |
| import json | |
| import asyncio | |
| from pprint import pprint | |
| import datetime | |
| with open("/home/pi/.smartthing_token") as f: |
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
| from PyP100 import PyP110 | |
| import json | |
| from pprint import pprint | |
| import pymongo | |
| with open("/home/pi/.mongo_uri.txt") as f: | |
| uri = f.readline().strip() | |
| mongoclient = pymongo.MongoClient(uri) | |
| tapoplugs = { |
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
| [ | |
| { $match: { type: "electric" } }, | |
| { | |
| $setWindowFields: | |
| { | |
| sortBy: { date: 1 }, | |
| output: { | |
| smoothsumusage: { | |
| $expMovingAvg: { input: { $sum: "$devices.watts"} , alpha: 0.9} | |
| } |
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
| [ | |
| { $match: { type: "electric" } }, | |
| { $unwind: "$devices" }, | |
| { $match: { "devices.watts": { $gt: 0 } } }, | |
| { $setWindowFields: { sortBy: { date: 1 }, partitionBy: "$devices.name", | |
| output: { totalUsage: { $integral: { input: "$devices.watts", unit: "hour" } } } }}, | |
| ] |
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
| 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}` }) | |
| } |
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
| { | |
| CustomerId: 123, | |
| Name : { First: "John", Last: "Page"}, | |
| TotalSpend: 261, | |
| Purchases: [ | |
| { PurchaseID: 519, Item: 25, Quantity: 2, Price: 50 }, | |
| { PurchaseID: 530, Item: 25, Quantity: 1, Price: 180 }, | |
| { PurchaseId: 640, Item: 9, Quantity: 1, Price: 31 } | |
| ] | |
| } |
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
| //Query From https://data.dft.gov.uk/anonymised-mot-test/MOT_user_guide_v4.docx | |
| private final String getlatestByVehicleSQL = "select " + | |
| "tr.*, " + | |
| "ft.FUEL_TYPE, " + | |
| "tt.TESTTYPE AS TYPENAME, " + | |
| "to2.RESULT, " + | |
| "ti.*, " + | |
| "fl.*, " + "tid.MINORITEM,tid.RFRDESC,tid.RFRLOCMARKER,tid.RFRINSPMANDESC,tid.RFRADVISORYTEXT,tid.TSTITMSETSECID, " + | |
| "b.ITEMNAME AS LEVEL1, " + | |
| "c.ITEMNAME AS LEVEL2, " + |
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
| public String getMOTResultInJSON(String identifier) { | |
| long identifierLong; | |
| try { | |
| identifierLong = Long.valueOf(identifier); | |
| Bson byIdQuery = Filters.eq("vehicleid", identifierLong); | |
| testObj = testresults.find(byIdQuery).limit(1).first(); | |
| if (testObj != null) { | |
| return testObj.toJson(); | |
| } | |
| } catch (Exception e) { |