setup node
Code needs to be in the 'On Start' tab of the node. This separates out the defaults/variables
This commit is contained in:
79
setup.js
Normal file
79
setup.js
Normal file
@@ -0,0 +1,79 @@
|
||||
// -----------------------------------------
|
||||
// Notify and store power use and cost for an appliance
|
||||
// FLOW VARIABLES
|
||||
// Full loop to calculate power average of appliance and
|
||||
// work out when it is operating. When operational
|
||||
// fill arrays with power used, and cost of power calculated.
|
||||
// -----------------------------------------
|
||||
// 2021-04-12 V1.3 - zorruno
|
||||
// - Fixed loop not detecting Finished-> Standby
|
||||
// - Moved some flow variables to context
|
||||
// - Changed csv filename to reflect appliance
|
||||
// -----------------------------------------
|
||||
|
||||
// Debugging nodes
|
||||
flow.set("debugFlow", false);
|
||||
|
||||
// Appliance Names (for notifications)
|
||||
flow.set("applianceName", "Washer");
|
||||
flow.set("applianceAction", "washing");
|
||||
|
||||
//flow.set("JSONPowerTopic", msg.payload.ENERGY.Power);
|
||||
|
||||
// Announcement text (for voice notifications)
|
||||
flow.set("voiceAnnouncements", [
|
||||
"Hey, the washing machine is now complete",
|
||||
"Hey, your washing is complete",
|
||||
"The washing is done",
|
||||
"The washing machine has finished",
|
||||
"Washing has now finished",
|
||||
]);
|
||||
|
||||
// Electrical tariff info
|
||||
// Updated with Auckland Contact Energy Costs, Feb 2021
|
||||
// cost is in cents per kWh and start and end are the times
|
||||
// to change tariffs.
|
||||
var tariff = {"costDay": 0.2023,
|
||||
"costNight": 0.0,
|
||||
"start": 0,
|
||||
"end": 21};
|
||||
|
||||
//---------------------------------------
|
||||
// Appliance power settings
|
||||
//---------------------------------------
|
||||
|
||||
// Average power in standby mode (it will show off if average
|
||||
// power is above this and below the operatingPowerMinimum)
|
||||
// Currently this just affects showing 'standby' vs 'off'
|
||||
// so actual value is not critical.
|
||||
flow.set("standbyPower", 2);
|
||||
// Minimum power when actually operating.
|
||||
// This is averaged over 'resolution' values, so no problem
|
||||
// if it drops below this value at times during operation.
|
||||
flow.set("operatingPowerMinium", 11);
|
||||
// How many times to do a power reading for rolling average.
|
||||
flow.set("resolution", 7);
|
||||
// How often does the appliance report back (seconds)
|
||||
flow.set("metricFrequency", 60);
|
||||
|
||||
//---------------------------------------
|
||||
// No need to change these
|
||||
//---------------------------------------
|
||||
flow.set("tariff", tariff);
|
||||
|
||||
flow.set("recentPowerArray", [0]);
|
||||
flow.set("cycleCostArray", [0]);
|
||||
flow.set("cyclePowerArray", [0]);
|
||||
|
||||
var cycle = { "cycleTimeStart": null,
|
||||
"cycleTimeStop": null,
|
||||
"totalCycleCostFormatted": 0,
|
||||
"totalCycleCostDollars": 0,
|
||||
"totalCyclePowerFormatted": 0,
|
||||
"totalCyclePowerWattHours": 0,
|
||||
}
|
||||
|
||||
flow.set("currentApplianceCycle",cycle);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user