Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define the calculateGridCharge function
- function calculateGridCharge(estimatedKwhProduction, batteryCapacity) {
- // Calculate the amount of kWh produced by the solar system during the day
- var kwhProduced = estimatedKwhProduction * 24;
- // Calculate the amount of kWh that needs to be stored in the battery to reach capacity
- var kwhToCharge = batteryCapacity - kwhProduced;
- // If the amount of kWh that needs to be stored in the battery is negative, set it to zero
- if (kwhToCharge < 0) {
- kwhToCharge = 0;
- }
- return kwhToCharge;
- }
- // Use the calculateGridCharge function to calculate the number of kWh to charge from the grid
- var estimatedKwhProduction = msg.payload;
- var batteryCapacity = 28;
- var kwhToCharge = calculateGridCharge(estimatedKwhProduction, batteryCapacity);
- // Set the output message
- msg.payload = kwhToCharge;
- return msg;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement