@BBE j’adore ton dashboard, je m’en inspire pour améliorer le mien.
J’avais une tuile qui affichait mon vélotaf

Les icones du haut correspondent à l’aller, celles du bas au retour.
Code:
title: Vélotaf
type: vertical-stack
cards:
- type: horizontal-stack
cards:
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_monday_morning
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_tuesday_morning
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_wednesday_morning
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_thursday_morning
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_friday_morning
- type: horizontal-stack
cards:
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_monday_morning
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_tuesday_morning
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_wednesday_morning
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_thursday_morning
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_friday_morning
- type: horizontal-stack
cards:
- type: horizontal-stack
cards:
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_monday_evening
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_tuesday_evening
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_wednesday_evening
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_thursday_evening
- type: custom:button-card
template: velotaf_button
entity: sensor.velotaf_friday_evening
- type: horizontal-stack
cards:
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_monday_evening
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_tuesday_evening
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_wednesday_evening
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_thursday_evening
- type: custom:button-card
template: velotaf_day
entity: sensor.velotaf_friday_evening
J’ai un script python qui génère les différents sensors en analysant la météo de chez moi et celle de mon travail (à 30 km au nord).
LOW_TEMP_RED_THRESHOLD = 0.0
LOW_TEMP_ORANGE_THRESHOLD = 2.0
WIND_SPEED_RED_THRESHOLD = 20
WIND_SPEED_ORANGE_THRESHOLD = 10
RAIN_RED_THRESHOLD = 5
RAIN_ORANGE_THRESHOLD = 0
velotaf_morning_sensor = ['sensor.velotaf_monday_morning', 'sensor.velotaf_tuesday_morning', 'sensor.velotaf_wednesday_morning', 'sensor.velotaf_thursday_morning', 'sensor.velotaf_friday_morning']
velotaf_evening_sensor = ['sensor.velotaf_monday_evening', 'sensor.velotaf_tuesday_evening', 'sensor.velotaf_wednesday_evening', 'sensor.velotaf_thursday_evening', 'sensor.velotaf_friday_evening']
commuting_days = [True, True, True, True, True]
commuting = [{'hour': 6, 'city': 'Toussieu', 'sensor':'weather.toussieu', 'direction':'N', 'returning':False, 'last':False},
{'hour': 6, 'city': 'Montluel', 'sensor':'weather.montluel', 'direction':'N', 'returning':False, 'last':True },
{'hour':18, 'city': 'Montluel', 'sensor':'weather.montluel', 'direction':'S', 'returning':True , 'last':False},
{'hour':18, 'city': 'Toussieu', 'sensor':'weather.toussieu', 'direction':'S', 'returning':True , 'last':True }]
attr_timestamp = []
attr_temp = []
attr_wind_bearing = []
attr_wind_speed = []
attr_rain = []
val_city = []
val_timestamp = []
val_temp = []
val_wind_bearing = []
val_wind_speed = []
val_rain = []
#attr_text = []
attr_icon = ""
attr_wind = ""
attr_raw_data = []
def getCompassFromBearing(num):
val = int((num/22.5) + 0.5)
arr = ["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"]
return arr[(val % 16)]
# Get today
today = datetime.datetime.now()
for day_idx, day in enumerate(commuting_days):
if day == True:
for data in commuting:
city_weather = hass.states.get(data['sensor']).attributes
short_forecast = True
for forecast in city_weather['forecast']:
timestamp = datetime.datetime.strptime(forecast['datetime'][0:16], "%Y-%m-%dT%H:%M")
if timestamp.weekday() == day_idx and timestamp.hour == data['hour']:
val_city.append(data['city'])
val_timestamp.append(timestamp)
val_temp.append(forecast['temperature'])
val_wind_bearing.append(forecast['wind_bearing'])
val_wind_speed.append(forecast['wind_speed'])
tmp_str = data['city'] + " " + str(timestamp) + " " + str(forecast['temperature']) + " " + str(forecast['wind_bearing']) + " " + str(forecast['wind_speed'])
# Rain is not available in long term forecasts
try:
val_rain.append(forecast['precipitation'])
tmp_str = tmp_str + " " + str(forecast['precipitation'])
except:
pass
attr_raw_data.append(tmp_str)
break
if data['last'] == True:
state = ""
# Refresh sensor
# Check temperature
min_temp = 99.0
for temp in val_temp:
if temp < min_temp:
min_temp = temp
if temp < LOW_TEMP_RED_THRESHOLD:
state = "Red"
attr_icon = "mdi:snowflake-thermometer"
elif temp < LOW_TEMP_ORANGE_THRESHOLD:
state = "Orange"
attr_icon = "mdi:snowflake-thermometer"
# Check wind direction and speed
max_wind_speed = 0
wind_compass = ""
attr_wind_speed = ""
attr_wind_compass = ""
if data['direction'] == 'N':
for wind_bearing, wind_speed in zip(val_wind_bearing, val_wind_speed):
if wind_speed > max_wind_speed:
max_wind_speed = wind_speed
if wind_bearing is not None:
wind_compass = getCompassFromBearing(wind_bearing)
if wind_compass == "NW" or wind_compass == "NNW" or wind_compass == "N" or wind_compass == "NNE" or wind_compass == "NE":
if max_wind_speed > WIND_SPEED_RED_THRESHOLD:
state = "Red"
attr_icon = "mdi:weather-windy"
elif max_wind_speed > WIND_SPEED_ORANGE_THRESHOLD:
state = "Orange"
attr_icon = "mdi:weather-windy"
elif data['direction'] == 'S':
for wind_bearing, wind_speed in zip(val_wind_bearing, val_wind_speed):
if wind_speed > max_wind_speed:
max_wind_speed = wind_speed
if wind_bearing is not None:
wind_compass = getCompassFromBearing(wind_bearing)
if wind_compass == "SW" or wind_compass == "SSW" or wind_compass == "S" or wind_compass == "SSE" or wind_compass == "SE":
if max_wind_speed > WIND_SPEED_RED_THRESHOLD:
state = "Red"
attr_icon = "mdi:weather-windy"
elif max_wind_speed > WIND_SPEED_ORANGE_THRESHOLD:
state = "Orange"
attr_icon = "mdi:weather-windy"
# Check rain
max_rain = 0
for rain in val_rain:
if rain > max_rain:
max_rain = rain
if rain > RAIN_RED_THRESHOLD:
state = "Red"
attr_icon = "mdi:weather-pouring"
elif rain > RAIN_ORANGE_THRESHOLD:
state = "Orange"
attr_icon = "mdi:weather-rainy"
# Weather is good!
if state == "":
state = "Green"
if max_wind_speed > WIND_SPEED_ORANGE_THRESHOLD: attr_icon = "mdi:bike-fast"
else: attr_icon = "mdi:bike"
attr_temp = min_temp
attr_wind_speed = max_wind_speed
attr_wind_compass = wind_compass
attr_rain = max_rain
# Refresh sensor
if data['returning'] == True:
sensor_name = velotaf_evening_sensor[day_idx]
attr_daytime = "Evening"
else:
sensor_name = velotaf_morning_sensor[day_idx]
attr_daytime = "Morning"
attributes = {'icon': attr_icon, 'datetime': val_timestamp[0], 'weekday': day_idx, 'daytime': attr_daytime, 'temp': attr_temp, 'wind_speed': attr_wind_speed, 'wind_compass': attr_wind_compass, 'rain': attr_rain }
hass.states.remove(sensor_name)
hass.states.set(sensor_name, state, attributes)
# Determine next morning and next evening sensors
if today.hour < 13: next_morning_day = today.weekday()
elif today.weekday() < 4: next_morning_day = today.weekday() + 1
else: next_morning_day = 0
if today.hour < 20: next_evening_day = today.weekday()
elif today.weekday() < 4: next_evening_day = today.weekday() + 1
else: next_evening_day = 0
if day_idx == next_morning_day and data['returning'] == False:
# Refresh next morning sensor
sensor_name = "sensor.velotaf_next_morning"
attr_daytime = "Morning"
attributes = {'icon': attr_icon, 'datetime': val_timestamp[0], 'weekday': day_idx, 'daytime': attr_daytime, 'temp': attr_temp, 'wind_speed': attr_wind_speed, 'wind_compass': attr_wind_compass, 'rain': attr_rain }
hass.states.remove(sensor_name)
hass.states.set(sensor_name, state, attributes)
if day_idx == next_evening_day and data['returning'] == True:
# Refresh next evening sensor
sensor_name = "sensor.velotaf_next_evening"
attr_daytime = "Evening"
attributes = {'icon': attr_icon, 'datetime': val_timestamp[0], 'weekday': day_idx, 'daytime': attr_daytime, 'temp': attr_temp, 'wind_speed': attr_wind_speed, 'wind_compass': attr_wind_compass, 'rain': attr_rain }
hass.states.remove(sensor_name)
hass.states.set(sensor_name, state, attributes)
# Clear temp variables
val_city.clear()
val_timestamp.clear()
val_temp.clear()
val_wind_bearing.clear()
val_wind_speed.clear()
val_rain.clear()
attr_raw_data.clear()
```