Custom Dark Sky Animated Weather Card

Added configuration flag ability to the card. So far the following two flags are available.

  1. tooltips (Turns daily summary tooltips on and off)
  2. static_icons (switches between static and animated icons)

Flags are entered into ui-lovelace.yaml file which should allow for some interesting configuration changes without having to edit the source js file.

        entity_summary_4: sensor.dark_sky_summary_4
        entity_summary_5: sensor.dark_sky_summary_5
        tooltips: true
        static_icons: false

Did you test it on HA 0.84.1 with new lovelace with config in /.storage ?

HI,

followed all your install instructions with the latest (dlā€™d today) and this is what shows:

18

no tempā€¦and no station name or location?

suggestion/feature request: please add sun up/sun down to your card? I use this in my other custom crd, and it really is a nice addition as is the feels like below the temp:

28

code:

const windBft = hass.states[this.config.entity_wind_force].state;
const forecast = entity.attributes.forecast.slice(0, 5);
const apparent_temperature = hass.states[this.config.entity_apparent_temperature].state;

var sunSetOrRiseA = new Date(hass.states[this.config.entity_sun].attributes.next_setting);
var sunSetOrRiseIconA = "mdi:weather-sunset-down";
var sunSetOrRiseB = new Date(hass.states[this.config.entity_sun].attributes.next_rising);
var sunSetOrRiseIconB = "mdi:weather-sunset-up";
// A == sunset   B == sunrise
if ( hass.states[this.config.entity_sun].state == "above_horizon" ) {
    // sun has risen, but hasn't set
    // sunset is today (no date displayed). sunrise is tomorrow (display date)
    // next is sunset == A
    
    sunSetOrRiseA = sunSetOrRiseA.toLocaleTimeString();
    var ssrI = sunSetOrRiseA.lastIndexOf(":");
    sunSetOrRiseA = sunSetOrRiseA.substr(0,ssrI) + sunSetOrRiseA.substr(ssrI+4);
    sunSetOrRiseB = sunSetOrRiseB.toDateString().substr(0,3) + " " + sunSetOrRiseB.toLocaleTimeString();
    ssrI = sunSetOrRiseB.lastIndexOf(":");
    sunSetOrRiseB = sunSetOrRiseB.substr(0,ssrI) + sunSetOrRiseB.substr(ssrI+4);
} else {
    // next is sunrise == B
    var ss = sunSetOrRiseA;
    if ( new Date().getDate() != sunSetOrRiseB.getDate() ) {
        // sun hasn't risen, and it's not same day
        // so display dates for both
        sunSetOrRiseA = sunSetOrRiseB.toDateString().substr(0,3) + " " + sunSetOrRiseB.toLocaleTimeString();
        sunSetOrRiseB = ss.toDateString().substr(0,3) + " " + ss.toLocaleTimeString();
    } else {
        // sun hasn't risen, but it's the same day
        // since rise and set are today, no dates displayed
        sunSetOrRiseA = sunSetOrRiseB.toLocaleTimeString();
        sunSetOrRiseB = ss.toLocaleTimeString();
    }
    var ssrI = sunSetOrRiseA.lastIndexOf(":");
    sunSetOrRiseA = sunSetOrRiseA.substr(0,ssrI) + sunSetOrRiseA.substr(ssrI+4);
    ssrI = sunSetOrRiseB.lastIndexOf(":");
    sunSetOrRiseB = sunSetOrRiseB.substr(0,ssrI) + sunSetOrRiseB.substr(ssrI+4);
    sunSetOrRiseIconA = "mdi:weather-sunset-up";
    sunSetOrRiseIconB = "mdi:weather-sunset-down";
}

this.content.innerHTML = `
  <span class="header" >${currentCondition}</span><span class="weather">${station}</span>
  <span class="icon bigger" style="background: none, url(/local/weather/animated/${weatherIcons[currentCondition]}.svg) no-repeat; background-size: contain;"> </span>
  <ul style="list-style-type:none">
    <li><span class="temp">${temperature}</span><span class="tempc"> ${getUnit('temperature')}</span></li>
    <li><span class="tempa">Feels like ${apparent_temperature}</span><span class="unitc"> ${getUnit('temperature')}</span></li>
  </ul>
  <span>
    <ul class="variations right">
        <li><span class="ha-icon"><ha-icon icon="mdi:water-percent"></ha-icon></span>${humidity}<span class="unit"> %</span></li>
        <li><span class="ha-icon"><ha-icon icon="mdi:gauge"></ha-icon></span>${pressure}<span class="unit"> ${getUnit('air_pressure')}</span></li>
        <li><span class="ha-icon"><ha-icon icon=${sunSetOrRiseIconB}></ha-icon></span>${sunSetOrRiseB}</li>
    </ul>
    <ul class="variations">
        <li><span class="ha-icon"><ha-icon icon="mdi:weather-windy"></ha-icon></span>Bft: ${windBft} - ${windBearing} ${windSpeed}<span class="unit"> ${getUnit('length')}/h</span></li>
        <li><span class="ha-icon"><ha-icon icon="mdi:weather-fog"></ha-icon></span>${visibility}<span class="unit"> ${getUnit('visibility')}</span></li>
        <li><span class="ha-icon"><ha-icon icon=${sunSetOrRiseIconA}></ha-icon></span>${sunSetOrRiseA}</li>
    </ul>
  </span>
  <div class="forecast clear">
      ${forecast.map(daily => `
          <div class="day">
              <span class="dayname">${(new Date(daily.datetime)).toLocaleDateString((navigator.language) ? navigator.language : navigator.userLanguage, {weekday: 'short'}).split(' ')[0]}</span>
              <br><i class="icon" style="background: none, url(/local/weather/animated/forecast/${weatherIcons[daily.condition]}.svg);"></i>
              <br><span class="highTemp">${daily.temperature}${getUnit('temperature')}</span>
              <br><span class="lowTemp">${daily.templow}${getUnit('temperature')}</span>
          </div>`).join('')}
  </div>`;

}

I have mixed experiences with changing the code of the custom card myself, so would like to ask if you could have a look, and update yours (if you would) yourself to keep it all in working orderā€¦

never mind the big -1 in the screen shot, it is a remnant of the transition to HA 0.84.1 and issues with the weather cardsā€¦ --UPDATEā€“(fixed that for now, a and the temp in your card also. I had another cuts weather card in the yaml and it was listed in succession. Apparently the css didnā€™t like that? dont know if that is even possible, but now that Iā€™ve split this view up, have 1 at the top and the other further down the view, the cards she alright.??):

01

and

06

station name, condition and sunrise/setā€¦

Another updateā€¦

This version adds two new flags.

  1. sunset : this flag enables or disables the display of sunset and sunrise icons. (Defaults to false/off)
  2. locale : this flag controls the locale used to display day names and time formats. (Defaults to en/english)
 sunset: true

locale: fr

2 Likes

nice!
will test immediately.

please help me out, I am wondering why this currentConditions variable is not displayed at all unless you comment out the icon:

  <span class="icon bigger" style="background: none, url(/local/weather/animated/${weatherIcons[currentConditions]}.svg) no-repeat; background-size: contain;">${currentConditions}</span>

AS said before, I wanted it to show in my card, so changed the config to:

this.content.innerHTML = `
  <span class="header" >${currentCondition}</span><span class="weather">${station}</span>
  <span class="icon bigger" style="background: none, url(/local/weather/animated/${weatherIcons[currentCondition]}.svg) no-repeat; background-size: contain;"> </span>

  <ul style="list-style-type:none">
    <li><span class="temp">${temperature}</span><span class="tempc"> ${getUnit('temperature')}</span></li>
    <li><span class="tempa">Feels like ${apparent_temperature}</span><span class="unitc"> ${getUnit('temperature')}</span></li>
  </ul>
  <span>

maybe you could try and see what happend if you added that?

station is:

const station = entity.attributes.friendly_name;

I just added your code but I get the following error :

dark-sky-weather-card.js:132:47 Uncaught TypeError: nextSunRise.getDate is not a function

Any idea whatā€™s up ?

I did copy your dark-sky-weather-card.js and lovelace config.

Iā€™m having the same exact error.

@Mariusthvdb] The value of currentConditions is actually displayedā€¦ Itā€™s just hidden behind the icon. The purpose is to show a value if something bad happens to the icon or if Dark Sky adds a condition that isnā€™t mapped to an icon.

Not quite sure what your ā€œStationā€ is. You are referencing an object called entity. What is that object? Where does it come from ?

@Kaostral @Narfel Do you have the sun entity defined in your ui-lovelace.yaml

entity_sun: sun.sun

I do.

 - type: custom:dark-sky-weather-card
        entity_sun: sun.sun

Okā€¦ looks like a bugā€¦ The sun was above the horizon when I wrote the code so this code path didnā€™t get thoroughly testedā€¦ will put out an update soon

If you comment out the 132 and 135 it ā€œworksā€. So it has to be something about that method.

edit: man, youā€™re too fast :slight_smile:

I figured as much. Still, I want it to show always, sort of a header for the cardā€¦ I might rethink the options then, and think of some default icon to show if the weather component goes wrongā€¦

i use the buienradar component for this card.

  - type: custom:card-modder
    style:
      background-image: url("/local/lovelace/images/weather-background-[[ sun.sun.state ]].png")
      background-size: 100% 400px
      --primary-text-color: var(--primary-text-color)
      --secondary-text-color: var(--secondary-text-color)
      --paper-item-icon-color: var(--primary-text-color) #small variation icons
    card:
      type: custom:weather-card
      title: Modded Woensdrecht
      entity_weather: weather.woensdrecht
      entity_sun: sun.sun
      entity_apparent_temperature: sensor.jagti_windchill
      entity_wind_force: sensor.br_wind_force

which has the station name as attributes.friendly_name.

@Kaostral @Narfel I have updated the card. Try it again if you wouldnā€™t mind. It is working now for me.

I can confirm, it is working fine.

Thank you for the quick update !

By the way, i noticed that you used this in your lovelace
entity_forecast_low_temp_1: sensor.dark_sky_overnight_low_temperature_0

It doesnā€™t seem to be working unless I replace it by
entity_forecast_low_temp_1: sensor.dark_sky_overnight_low_temperature_1

Getting this error when I do not
dark-sky-weather-card.js:169:85 Uncaught TypeError: Cannot read property 'state' of undefined

You need to add the 0th forecast day to your Dark Sky sensor config.

    forecast:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5

This was a note I had in the original post about this ā€¦

More info on this ā€¦

Oh thank you, I actually read those but i guess I missed this.

this pops up every time the card is loaded:

frontend_latest/app-0d042052.js:773:25742 TypeError: this.detached is not a function. (In 'this.detached()', 'this.detached' is undefined)

have another weather card which gives the same, which might be expected, since the cards use plenty same code.

always points at the line:

this.content.innerHTML = `

canā€™t and the detached in the code though so what might that be?

Great work! Like it!
Would be nice if the locale setting also changes the wind direction letters.
So ā€˜Eā€™ (East) would be ā€˜Oā€™ (Ost) in my language.

Does the card eventually load or does it stay at that errorā€¦