homebridge-solar-monitor-ivk
Version:
Solar production monitor for Homebridge with Pushover notifications
95 lines (77 loc) • 3.14 kB
JavaScript
/**
* Force notification test for Solar Monitor plugin
*/
const https = require('https');
const querystring = require('querystring');
// Pushover credentials - UPDATE THESE WITH YOUR ACTUAL KEYS
const PUSHOVER_APP_TOKEN = "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"; // Replace with your actual app token
const PUSHOVER_USER_KEY = "u1v2w3x4y5z6a7b8c9d0e1f2g3h4i5j6"; // Replace with your actual user key
const SECOND_USER_KEY = "us5sg9aqb2i7iqbjmmocr7p2df1ymp";
function sendPushoverNotification(userKey, appToken, message) {
return new Promise((resolve, reject) => {
const postData = querystring.stringify({
token: appToken,
user: userKey,
message: message,
title: '⚡ Solar Monitor Test',
sound: 'cosmic',
priority: 0
});
const options = {
hostname: 'api.pushover.net',
port: 443,
path: '/1/messages.json',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
if (res.statusCode === 200) {
console.log(`✅ Pushover notification sent to user ${userKey}`);
resolve(true);
} else {
console.log(`❌ Pushover API error: ${res.statusCode} - ${data}`);
reject(new Error(`Pushover API error: ${res.statusCode} - ${data}`));
}
});
});
req.on('error', (error) => {
console.log(`❌ Error sending notification: ${error.message}`);
reject(error);
});
req.write(postData);
req.end();
});
}
async function main() {
console.log('🧪 Testing Pushover notifications...');
console.log(`⏰ Current time: ${new Date().toLocaleString()}`);
// Test message
const message = `🧪 TEST NOTIFICATION
🔋 Current Power: 2.5 kW
📊 E Today: 12.3 kWh
📈 E Yesterday: 15.7 kWh
📅 E This Month: 234.5 kWh
⏰ ${new Date().toLocaleString()}
🎯 This is a test notification from Solar Monitor plugin!`;
try {
console.log('📤 Sending test message to primary user...');
await sendPushoverNotification(PUSHOVER_USER_KEY, PUSHOVER_APP_TOKEN, message);
console.log('📤 Sending test message to second user...');
await sendPushoverNotification(SECOND_USER_KEY, PUSHOVER_APP_TOKEN, message);
console.log('🎉 All test notifications sent successfully!');
console.log('📱 Check your Pushover app for notifications!');
} catch (error) {
console.log('⚠️ Some notifications failed. Check credentials and network.');
console.log('Error:', error.message);
}
}
main();