Advertisement
dykandDK

HA - YAML - Markdown card with weather and solar forecasts including hourly import and export rates

Nov 1st, 2024 (edited)
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.50 KB | None | 0 0
  1. #───────────────────────────────────────────────────────────────────────────────
  2. # Description:
  3. #───────────────────────────────────────────────────────────────────────────────
  4. # Card to display solar production forecast for the next 24 hours including
  5. # details on energy import and export rates.
  6. #
  7. # A sensor with the hourly weather forecast stored as attributes is required.
  8. # As of version 2024.4, the weather integration no longer includes forecast data
  9. # as attributes. A new template sensor must be created to get the forecast data.
  10. # See more here:
  11. #
  12. # https://community.home-assistant.io/t/update-from-using-weather-attributes-with-the-new-service-weather-get-forecasts/702736/1
  13. #
  14. # Solar forecast is based on the Solcast integration:
  15. #
  16. # https://github.com/oziee/ha-solcast-solar
  17. #
  18. # Energy import and export rates are based on the Energi Data Service
  19. # integration:
  20. #
  21. # https://github.com/MTrab/energidataservice
  22. #───────────────────────────────────────────────────────────────────────────────
  23. type: markdown
  24. content: >
  25.  {%- set import_rates = "sensor.import_rates" -%}
  26.   {%- set export_rates = "sensor.export_rates" -%}
  27.   {%- set solar_forecast0 = "sensor.solcast_pv_forecast_forecast_today" -%}
  28.   {%- set solar_forecast1 = "sensor.solcast_pv_forecast_forecast_tomorrow" -%}
  29.   {%- set hourly_weather = "sensor.weather_hourly" -%}
  30.   <table>
  31.   <tr>
  32.   <th width=35px></th>
  33.   <th align=left width=150px><br>Tidspunkt</th>
  34.   <th align=right width=125px>Timepris for<br>køb / salg</th> <th align=right width=125px>Estimeret <br>produktion</th>
  35.   </tr>
  36.   {% if (state_attr(hourly_weather,"forecast")[0].datetime | as_datetime | as_local).hour != now().hour -%}
  37.   <tr>
  38.   <td><ha-icon icon='mdi:weather-{{states("weather.home") |
  39.                                    replace('partly','partly-') |
  40.                                    replace('clear-night','night') |
  41.                                    replace('clear','') |
  42.                                    replace('lightning','lightning-') |    
  43.                                    replace('snowyrainy','snowy-rainy')-}}'/></ha-icon></td>
  44.   <td>Nu</td>
  45.   <td align=right> {{ "%.2f"|format(state_attr(import_rates,"raw_today")[now().hour].price)}} /
  46.                   {{ "%.2f"|format(state_attr(export_rates,"raw_today")[now().hour].price)}}</td>
  47.   <td align=right> {{"%.0f"|format((state_attr(solar_forecast0,"detailedHourly")[now().hour].pv_estimate*1000))}} W</td>
  48.   </tr>
  49.   {% endif -%}  
  50.   {% for w in state_attr(hourly_weather,'forecast') -%}
  51.   {% set h=w.datetime | as_datetime | as_local -%}  {% if h.day==now().day -%}
  52.   {% set  d='I dag' -%}
  53.   {% else %}
  54.   {% set d='I morgen' -%}
  55.   {% endif -%}  
  56.   <tr>
  57.   <td> <ha-icon icon='mdi:weather-{{w.condition |
  58.                                     replace('partly','partly-') |
  59.                                     replace('clear-night','night') |
  60.                                     replace('clear','') |
  61.                                     replace('lightning','lightning-') |
  62.                                     replace('snowyrainy','snowy-rainy')-}}'/></ha-icon></td>
  63.   <td>{{ d }} {{w.datetime | as_timestamp | timestamp_custom('%H.00', local=True) -}}</td>
  64.   {% if d=='I dag' %}
  65.   <td align=right>{{ "%.2f"|format(state_attr(import_rates,"raw_today")[h.hour].price)}} /
  66.                   {{ "%.2f"|format(state_attr(export_rates,"raw_today")[h.hour].price)}}</td>
  67.   <td align=right>{{ "%.0f"|format((state_attr(solar_forecast0,"detailedHourly")[h.hour].pv_estimate*1000))}} W</td>
  68.   </tr>
  69.   {% else %}
  70.   {% if (state_attr(import_rates,"tomorrow_valid") == true) and (state_attr(export_rates,"tomorrow_valid") == true) %}
  71.   <td align=right>{{ "%.2f"|format(state_attr(import_rates,"raw_tomorrow")[h.hour].price)}} /
  72.                   {{ "%.2f"|format(state_attr(export_rates,"raw_tomorrow")[h.hour].price)}}</td>
  73.   {% else %}
  74.   <td></td>
  75.   {% endif %}
  76.   <td align=right>{{ "%.0f"|format((state_attr(solar_forecast1,"detailedHourly")[h.hour].pv_estimate*1000))}} W</td>
  77.   </tr>
  78.   {% endif %}
  79.   {% endfor -%}
  80.   </table>
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement