// Combined Solar Calculator Integration
class IWantEnergySolarCalculator {
constructor() {
// Hobart, Tasmania coordinates
this.location = {
lat: -42.8826,
lon: 147.3257
};
// Current 2025 Tasmanian tariffs
this.tariffs = {
tariff31: {
rate: 26.906,
dailyCharge: 95.963
},
tariff41: {
rate: 17.789,
dailyCharge: 19.333
},
tariff93: {
peak: 32.656,
offPeak: 15.906,
dailyCharge: 102.509
}
};
this.systemOptions = {
small: {
size: 6.6,
price: 6500
},
medium: {
size: 8.8,
price: 8500
},
large: {
size: 10,
price: 10500
}
};
}
async calculateSolarProduction(systemSize, roofType) {
// PVWatts API call
const pvwattsUrl = `https://developer.nrel.gov/api/pvwatts/v6.json?api_key=\${process.env.PVWATTS_API_KEY}&system_capacity=\${systemSize}&module_type=1&losses=14&array_type=1&tilt=20&azimuth=180&lat=\${this.location.lat}&lon=\${this.location.lon}&dataset=intl`;
try {
const response = await fetch(pvwattsUrl);
const data = await response.json();
return data.outputs.ac_annual; // Annual production in kWh
} catch (error) {
console.error('PVWatts API Error:', error);
return null;
}
}
async calculateFinancials(systemSize, currentBill, selectedTariff) {
// Calculate savings based on production and tariffs
const annualProduction = await this.calculateSolarProduction(systemSize);
const systemCost = this.getSystemCost(systemSize);
// Calculate payback period and ROI
const annualSavings = this.calculateAnnualSavings(annualProduction, selectedTariff);
const paybackPeriod = systemCost / annualSavings;
// Government loan calculations
const govLoanAmount = Math.min(systemCost, 10000);
const monthlyLoanPayment = govLoanAmount / 36; // 3-year term
return {
systemCost: systemCost,
annualSavings: annualSavings,
paybackPeriod: paybackPeriod,
governmentLoan: {
amount: govLoanAmount,
monthlyPayment: monthlyLoanPayment,
term: 36,
interestRate: 0
},
twentyFiveYearSavings: annualSavings * 25
};
}
getSystemCost(systemSize) {
// Find closest system size and return price
const sizes = Object.values(this.systemOptions);
const closest = sizes.reduce((prev, curr) => {
return (Math.abs(curr.size - systemSize) < Math.abs(prev.size - systemSize) ? curr : prev);
});
return closest.price;
}
calculateAnnualSavings(production, tariff) {
const tariffRate = this.tariffs[tariff].rate;
return (production * tariffRate / 100);
}
}
// Frontend Implementation
document.addEventListener('DOMContentLoaded', function() {
const calculator = new IWantEnergySolarCalculator();
// Form submission handler
document.getElementById('solar-calculator-form').addEventListener('submit', async function(e) {
e.preventDefault();
const formData = {
systemSize: parseFloat(document.getElementById('system-size').value),
currentBill: parseFloat(document.getElementById('current-bill').value),
selectedTariff: document.getElementById('tariff-type').value,
roofType: document.getElementById('roof-type').value
};
// Calculate results
const results = await calculator.calculateFinancials(
formData.systemSize,
formData.currentBill,
formData.selectedTariff
);
// Display results
displayResults(results);
});
});
// Results display function
function displayResults(results) {
document.getElementById('annual-savings').textContent =
`\$\${results.annualSavings.toFixed(2)}`;
document.getElementById('payback-period').textContent =
`\${results.paybackPeriod.toFixed(1)} years`;
document.getElementById('total-savings').textContent =
`\$\${results.twentyFiveYearSavings.toFixed(2)}`;
document.getElementById('monthly-loan-payment').textContent =
`\$\${results.governmentLoan.monthlyPayment.toFixed(2)}`;
}