Please note : this fork is just sending the last 5 min consumption and current charging session to mqtt at this stage. I did never code in Node JS so I'll see what I can do... Todo list :
- Store token in file ✅
- Read token from file ✅
- Request new token if token is expired ✅
- Implement EV line API requests ✅ (read current session only)
- Send data to MQTT server : partial
- Remove deprecated dependency : request/request#3142
This nodejs project allows to read data from the smappee API and send it to an MQTT server. Tested with Mosquitto MQTT server and openHab to import Electric Car (EV) charging session status and house consumption.
Based on https://support.smappee.com/hc/en-us/articles/202153935-Where-can-I-find-the-API-documentation-
npm install smappee2mqtt --save
var SmappeeAPI = require('smappee2mqtt');
var smappee = new SmappeeAPI({
debug: false,
noAPIcall: false,
clientId: "xxx",
clientSecret: "xxx",
username: "xxx",
password: "xxx",
mqtt_server: "xxx",
mqtt_port: "xxx",
mqtt_baseTopic : "smappee/"
});
module.exports = smappee;
var smappee = require('./my-smappee');
smappee.getServiceLocations(function(output) {
console.log(output);
})
node test.js
The following functions are available:
getServiceLocations(callback)
, getServiceLocationInfo(serviceLocationId, callback)
, ...
This method will get all smappee devices configured on the account. See https://smappee.atlassian.net/wiki/display/DEVAPI/Get+Servicelocations
smappee.getServiceLocations(function(output) {
console.log(output);
})
Get the details about 1 service location (list of appliances, list of actuators, ...). See https://smappee.atlassian.net/wiki/display/DEVAPI/Get+Servicelocation+Info
smappee.getServiceLocationInfo("0000", function(output) {
console.log(output);
})
Get a list of all consumptions for the specified period and interval. The aggregation can be selected from one of the values of smappee.AGGREGATION_TYPES. See https://smappee.atlassian.net/wiki/display/DEVAPI/Get+Consumption
var moment = require('moment');
//This will get the consumptions for the last year til now.
var from = moment().subtract(1, 'year').utc().valueOf();
var to = moment().utc().valueOf();
smappee.getConsumptions("0000", smappee.AGGREGATION_TYPES.MONTHLY, from, to, function(output) {
console.log(output);
})
Get a list of latest consumptions
var smappee = require('./my-smappee');
smappee.getLatestConsumption(serviceLocationId, function(output) {
console.log("getLatestConsumption (multiply WH by 12 if aggregate by 5 minutes since 5*12 = one hour to get Watts) : ",output);
})
Get a list of current charging session (will return -1 if no car is charging)
var smappee = require('./my-smappee');
smappee.getCurrentChargingSession(chargingStationSN, function(output){
console.log(output);
})
TIP: To convert the 5 minute interval from Energy [Wh] to Power [W], like the Smappee Dashboard reports these, you have to do these values times 12 as there are 12 x 5 minute intervals in an hour.