diff --git a/index.html b/index.html
index fe9d8f9..62b7218 100644
--- a/index.html
+++ b/index.html
@@ -366,7 +366,7 @@ async function updateWeather() {
try {
const r = await fetch('/api/weather');
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) {
html += ' ⚠️ ' + d.alerts.join(', ') + '';
}
diff --git a/server.js b/server.js
index 706ec59..4e02660 100644
--- a/server.js
+++ b/server.js
@@ -105,7 +105,23 @@ app.get('/api/weather', async (req, res) => {
return res.json(weatherCache.data);
}
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
const wttr = await new Promise((resolve, reject) => {