Skip to content

Commit

Permalink
Add ability which can show the apparent temperature from a sensor (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-d authored Apr 16, 2024
1 parent 8ec9b60 commit f47fba2
Show file tree
Hide file tree
Showing 39 changed files with 164 additions and 109 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ hourly_forecast: false
use_browser_time: false
time_zone: null
show_decimal: false
apparent_sensor: sensor.real_feel_temperature
```

### Options
Expand Down Expand Up @@ -143,7 +144,8 @@ show_decimal: false
| hourly_forecast | boolean | **Optional** | Displays an hourly forecast instead of daily | `false` |
| use_browser_time | boolean | **Optional** | Uses the time from your browser to indicate the current time. If not provided, uses the [time_zone](https://www.home-assistant.io/blog/2015/05/09/utc-time-zone-awareness/#setting-up-your-time-zone) configured in HA | `false` |
| time_zone | string | **Optional** | Uses the given [time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) to indicate the current date and time. If not provided, uses the time zone configured in HA | `null` |
| show_decimal | boolean | **Optional** | Displays main temperature without rounding | `false` |
| show_decimal | boolean | **Optional** | Displays main temperature without rounding | `false` |
| apparent_sensor | string | **Optional** | ID of the apparent temperature sensor entity. It is used to show the apparent temperature based on a sensor and will only show it if value is provided. | `''` |

## Footnotes

Expand Down
19 changes: 18 additions & 1 deletion src/clock-weather-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,15 @@ export class ClockWeatherCard extends LitElement {
const state = weather.state
const temp = this.config.show_decimal ? this.getCurrentTemperature() : roundIfNotNull(this.getCurrentTemperature())
const tempUnit = weather.attributes.temperature_unit
const apparentTemp = this.config.show_decimal ? this.getApparentTemperature() : roundIfNotNull(this.getApparentTemperature())
const humidity = roundIfNotNull(this.getCurrentHumidity())
const iconType = this.config.weather_icon_type
const icon = this.toIcon(state, iconType, false, this.getIconAnimationKind())
const weatherString = this.localize(`weather.${state}`)
const localizedTemp = temp !== null ? this.toConfiguredTempWithUnit(tempUnit, temp) : null
const localizedHumidity = humidity !== null ? `${humidity}% ${this.localize('misc.humidity')}` : null
const localizedApparent = apparentTemp !== null ? this.toConfiguredTempWithUnit(tempUnit, apparentTemp) : null
const apparentString = this.localize('misc.feels-like')

return html`
<clock-weather-card-today-left>
Expand All @@ -227,6 +230,7 @@ export class ClockWeatherCard extends LitElement {
<clock-weather-card-today-right-wrap-top>
${this.config.hide_clock ? weatherString : localizedTemp ? `${weatherString}, ${localizedTemp}` : weatherString}
${this.config.show_humidity && localizedHumidity ? html`<br>${localizedHumidity}` : ''}
${this.config.apparent_sensor && apparentTemp ? html`<br>${apparentString}: ${localizedApparent}` : ''}
</clock-weather-card-today-right-wrap-top>
<clock-weather-card-today-right-wrap-center>
${this.config.hide_clock ? localizedTemp ?? 'n/a' : this.time()}
Expand Down Expand Up @@ -426,7 +430,8 @@ export class ClockWeatherCard extends LitElement {
date_pattern: config.date_pattern ?? 'D',
use_browser_time: config.use_browser_time ?? false,
time_zone: config.time_zone ?? undefined,
show_decimal: config.show_decimal ?? false
show_decimal: config.show_decimal ?? false,
apparent_sensor: config.apparent_sensor ?? undefined
}
}

Expand Down Expand Up @@ -472,6 +477,18 @@ export class ClockWeatherCard extends LitElement {
return this.getWeather().attributes.humidity ?? null
}

private getApparentTemperature (): number | null {
if (this.config.apparent_sensor) {
const apparentSensor = this.hass.states[this.config.apparent_sensor] as TemperatureSensor | undefined
const temp = apparentSensor?.state ? parseFloat(apparentSensor.state) : undefined
const unit = apparentSensor?.attributes.unit_of_measurement ?? this.getConfiguredTemperatureUnit()
if (temp !== undefined && !isNaN(temp)) {
return this.toConfiguredTempWithoutUnit(unit, temp)
}
}
return null
}

private getSun (): HassEntityBase | undefined {
return this.hass.states[this.config.sun_entity]
}
Expand Down
5 changes: 3 additions & 2 deletions src/localize/languages/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Нд"
},
"misc": {
"humidity": "влажност"
"humidity": "влажност",
"feels-like": "Feels like"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Dg."
},
"misc": {
"humidity": "humitat"
"humidity": "humitat",
"feels-like": "Feels like"
}
}
5 changes: 3 additions & 2 deletions src/localize/languages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Ne"
},
"misc": {
"humidity": "vlhkost"
"humidity": "vlhkost",
"feels-like": "Feels like"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Søn"
},
"misc": {
"humidity": "fugtighed"
"humidity": "fugtighed",
"feels-like": "Feels like"
}
}
5 changes: 3 additions & 2 deletions src/localize/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "So"
},
"misc": {
"humidity": "Luftfeuchtigkeit"
"humidity": "Luftfeuchtigkeit",
"feels-like": "Feels like"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Κυρ"
},
"misc": {
"humidity": "υγρασία"
"humidity": "υγρασία",
"feels-like": "Feels like"
}
}
4 changes: 2 additions & 2 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"7": "Sun"
},
"misc": {
"humidity": "Humidity"
"humidity": "Humidity",
"feels-like": "Feels like"
}

}
3 changes: 2 additions & 1 deletion src/localize/languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Dom"
},
"misc": {
"humidity": "humedad"
"humidity": "humedad",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "P"
},
"misc": {
"humidity": "niiskus"
"humidity": "niiskus",
"feels-like": "Feels like"
}
}
5 changes: 3 additions & 2 deletions src/localize/languages/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Su"
},
"misc": {
"humidity": "kosteus"
"humidity": "kosteus",
"feels-like": "Feels like"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Dim"
},
"misc": {
"humidity": "humidité"
"humidity": "humidité",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "ראשון"
},
"misc": {
"humidity": "לחות"
"humidity": "לחות",
"feels-like": "Feels like"
}
}
5 changes: 3 additions & 2 deletions src/localize/languages/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "V"
},
"misc": {
"humidity": "páratartalom"
"humidity": "páratartalom",
"feels-like": "Feels like"
}
}
}
61 changes: 31 additions & 30 deletions src/localize/languages/is.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"weather": {
"clear-night": "Heiðskýrt",
"cloudy": "Skýjað",
"fog": "Þoka",
"hail": "Hagl",
"lightning": "Eldingar",
"lightning-rainy": "Þrumur",
"partlycloudy": "Skýjað að hluta",
"pouring": "mikil rigning",
"rainy": "Rigning",
"snowy": "Snjókoma",
"snowy-rainy": "Él",
"sunny": "Sólríkt",
"windy": "Hvasst",
"windy-variant": "Stórmur",
"exceptional": "Óveður"
},
"day": {
"1": "Mán",
"2": "Þri",
"3": "Mið",
"4": "Fim",
"5": "Fös",
"6": "Lau",
"7": "Sun"
},
"misc": {
"humidity": "raki"
}
}
"weather": {
"clear-night": "Heiðskýrt",
"cloudy": "Skýjað",
"fog": "Þoka",
"hail": "Hagl",
"lightning": "Eldingar",
"lightning-rainy": "Þrumur",
"partlycloudy": "Skýjað að hluta",
"pouring": "mikil rigning",
"rainy": "Rigning",
"snowy": "Snjókoma",
"snowy-rainy": "Él",
"sunny": "Sólríkt",
"windy": "Hvasst",
"windy-variant": "Stórmur",
"exceptional": "Óveður"
},
"day": {
"1": "Mán",
"2": "Þri",
"3": "Mið",
"4": "Fim",
"5": "Fös",
"6": "Lau",
"7": "Sun"
},
"misc": {
"humidity": "raki",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Dom"
},
"misc": {
"humidity": "umidità"
"humidity": "umidità",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": ""
},
"misc": {
"humidity": "습도"
"humidity": "습도",
"feels-like": "Feels like"
}
}
5 changes: 3 additions & 2 deletions src/localize/languages/lt.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Sk"
},
"misc": {
"humidity": "drėgmė"
"humidity": "drėgmė",
"feels-like": "Feels like"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Søn"
},
"misc": {
"humidity": "fuktighet"
"humidity": "fuktighet",
"feels-like": "Feels like"
}
}
5 changes: 3 additions & 2 deletions src/localize/languages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Zo"
},
"misc": {
"humidity": "vochtigheid"
"humidity": "vochtigheid",
"feels-like": "Feels like"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "niedz."
},
"misc": {
"humidity": "wilgotność"
"humidity": "wilgotność",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Dom"
},
"misc": {
"humidity": "umidade"
"humidity": "umidade",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Dom"
},
"misc": {
"humidity": "humidade"
"humidity": "humidade",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Dum"
},
"misc": {
"humidity": "umiditate"
"humidity": "umiditate",
"feels-like": "Feels like"
}
}
5 changes: 3 additions & 2 deletions src/localize/languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Вс"
},
"misc": {
"humidity": "влажность"
"humidity": "влажность",
"feels-like": "Feels like"
}
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Ned"
},
"misc": {
"humidity": "vlhkosť"
"humidity": "vlhkosť",
"feels-like": "Feels like"
}
}
3 changes: 2 additions & 1 deletion src/localize/languages/sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"7": "Ned"
},
"misc": {
"humidity": "vlažnost"
"humidity": "vlažnost",
"feels-like": "Feels like"
}
}
Loading

0 comments on commit f47fba2

Please sign in to comment.