Add current outside temp from HA sensor.air_temp to weather line
This commit is contained in:
parent
4b9483a835
commit
470f83bc5a
|
|
@ -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 += ' <span class="wx-alert">⚠️ ' + d.alerts.join(', ') + '</span>';
|
||||
}
|
||||
|
|
|
|||
18
server.js
18
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) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue