Add current outside temp from HA sensor.air_temp to weather line

This commit is contained in:
James 2026-02-14 03:28:06 -05:00
parent 4b9483a835
commit 470f83bc5a
2 changed files with 18 additions and 2 deletions

View File

@ -366,7 +366,7 @@ async function updateWeather() {
try { try {
const r = await fetch('/api/weather'); const r = await fetch('/api/weather');
const d = await r.json(); const d = await r.json();
let html = `${d.low}${d.high}°F`; let html = d.current ? `${d.current}°F (${d.low}${d.high})` : `${d.low}${d.high}°F`;
if (d.alerts && d.alerts.length) { if (d.alerts && d.alerts.length) {
html += ' <span class="wx-alert">⚠️ ' + d.alerts.join(', ') + '</span>'; html += ' <span class="wx-alert">⚠️ ' + d.alerts.join(', ') + '</span>';
} }

View File

@ -105,7 +105,23 @@ app.get('/api/weather', async (req, res) => {
return res.json(weatherCache.data); return res.json(weatherCache.data);
} }
try { try {
const result = { high: null, low: null, alerts: [] }; const result = { high: null, low: null, current: null, alerts: [] };
// Current outside temp from HA
try {
const haData = await new Promise((resolve, reject) => {
const r = http.get(`${HA_URL}/api/states/sensor.air_temp`, {
headers: { 'Authorization': `Bearer ${HA_TOKEN}` }
}, (resp) => {
let body = '';
resp.on('data', c => body += c);
resp.on('end', () => { try { resolve(JSON.parse(body)); } catch(e) { reject(e); } });
});
r.on('error', reject);
r.setTimeout(3000, () => { r.destroy(); reject(new Error('timeout')); });
});
result.current = parseInt(haData.state);
} catch(e) {}
// Temp range from wttr.in // Temp range from wttr.in
const wttr = await new Promise((resolve, reject) => { const wttr = await new Promise((resolve, reject) => {