When populating the original lovelace weather-card with meteo_france weather sensor, the visibility doesn’t show. The attribute is missing from the weather entity but is available in a dedicated sensor.
I would like to know if it’s possible to force weather-card.js to load a specific sensor state ?
(I like the simplicity of this rarely updated card, editing the js code will not be so boring to manage in the future)
I have found the relevant lines in the card’s code but can’t find the proper code to replace "stateObj.attributes.visibility:
If you don’t have visibility from any other source, you can also calculate an estimate based on your elevation and humidity in the air:
First find your max possible visibility:
1.22459 * sqrt (height in feet above sea level) = Distance to the horizon in nautical miles
using 1.2 will yield good accuracy also
3.56972 * sqrt (height in meters above sea level) = Distance to the horizon in km
using 3.6 will yield good accuracy also
Then:
Tair = air temperature
Tdp = Dew Point
In F:
[0.63(Tair - Tdp) - 1.15]/10
In C:
[1.13(Tair - Tdp) - 1.15]/10
With this result multiply it to the max visibility to determine visibility based on conditions (dew point).
The below code is in python taken from a PR I did recently for a Personal Weather Station setup for WeatherFlow Tempest to MQTT to HomeAssistant:
async def visibility(self, elevation, temp, humidity):
"""Returns the visibility.
Input:
Elevation in Meters
Temperature in Celcius
Humidity in percent
"""
if temp is None or elevation is None or humidity is None:
return None
dewpoint_c = await self.dewpoint(temp, humidity, True)
# Set minimum elevation for cases of stations below sea level
if elevation > 2:
elv_min = float(elevation)
else:
elv_min = float(2)
# Max possible visibility to horizon (units km)
mv = float(3.56972 * math.sqrt(elv_min))
# Percent reduction based on quatity of water in air (no units)
# 76 percent of visibility variation can be accounted for by humidity accourding to US-NOAA.
pr_a = float((1.13 * abs(temp - dewpoint_c)-1.15)/10)
if pr_a > 1:
# Prevent visibility exceeding maximum distance
pr = float(1)
elif pr_a < 0.025:
# Prevent visibility below minimum distance
pr = float(0.025)
else:
pr = pr_a
# Visibility in km to horizon
vis = float(mv * pr)
if self._unit_system == UNITS_IMPERIAL:
# Originally was in nautical miles; HA displays miles as imperial, therefore converted to miles
return round(vis/1.609344, 1)
return round(vis, 1)
You should be able to make a template sensor from the above, if you need help let me know. But I don’t think you will since you can just point the template sensor to the sensor you can already get for visibility.