Custom Dark Sky Animated Weather Card

Here it is:

- platform: darksky
  api_key: !secret darksky_api
  forecast:
    - 1
    - 2
    - 3
    - 4
    - 5
  monitored_conditions:
    - icon
    - summary
    - nearest_storm_distance
    - nearest_storm_bearing
    - humidity
    - temperature
    - temperature_high
    - temperature_low
    - apparent_temperature
    - apparent_temperature_high
    - apparent_temperature_low
    - wind_speed
    - wind_bearing
    - precip_type
    - precip_probability
    - precip_accumulation
    - precip_intensity
    - precip_intensity_max
    - uv_index
    - daily_summary
    - pressure
    - visibility
  update_interval:
    minutes: 5

You are missing the 0 under forecast:

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

Ah, dang. Didnā€™t even notice that. I had the sensor set up before so I didnā€™t copy all of the config from the git. Not sure how I missed the 0, but I just added it and itā€™s working now. Thanks for the second set of eyes!

You have this in your code twice. Once near the top and again at the bottomā€¦ (haā€¦ just noticed I had it that way in my card as wellā€¦ anyway, it should only be there once. I have corrected it in my card for the next version)

You need to replace all the

this.hass

references with

this._hass

As that is what you defined the class variable to be

Hi Thomas,

Thanks, that helps. I really appreciate you taking the time to explain the issue.

I will make the change to the style property in the next version.

thanks!

took the second one out (at the bottom) and replaced all this.hass with this._hass.

Still a no showā€¦

do have this in the inspector:

line 275:

nextSunSet = new Date(this._hass.states[this.config.entity_sun].attributes.next_setting).toLocaleTimeString(this.config.locale, {hour: '2-digit', minute:'2-digit'});

my sun.sun is:

what is being passed into entity_sun in your lovelace config ? also what is being passed into the locale flag?

the exit same setting as for the card with the other Lit settings, which shows immediately with all correct info if I load it again:

  - type: custom:dark-sky-weather-card
    entity_sun: sun.sun
    entity_daily_summary: sensor.dark_sky_daily_summary
    entity_summary_today: sensor.dark_sky_forecast_summary_0
    entity_current_conditions: sensor.dark_sky_forecast_icon
    entity_humidity: sensor.dark_sky_humidity
    entity_pressure: sensor.dark_sky_pressure
    entity_apparent_temp: sensor.dark_sky_apparent_temperature
    entity_temperature: sensor.dark_sky_temperature
    entity_visibility: sensor.dark_sky_visibility
    entity_daytime_high: sensor.dark_sky_forecast_daytime_high_temperature_0
    entity_wind_bearing: sensor.dark_sky_wind_bearing
    entity_wind_speed: sensor.br_wind_speed
    entity_wind_force: sensor.br_wind_force
    entity_current_text: sensor.weather_rsd_icon
    entity_precip_intensity: sensor.dark_sky_precip_intensity
    entity_today: sensor.vandaag
    entity_forecast_high_temp_1: sensor.dark_sky_forecast_daytime_high_temperature_1
    entity_forecast_high_temp_2: sensor.dark_sky_forecast_daytime_high_temperature_2
    entity_forecast_high_temp_3: sensor.dark_sky_forecast_daytime_high_temperature_3
    entity_forecast_high_temp_4: sensor.dark_sky_forecast_daytime_high_temperature_4
    entity_forecast_high_temp_5: sensor.dark_sky_forecast_daytime_high_temperature_5
    entity_forecast_low_temp_1: sensor.dark_sky_forecast_overnight_low_temperature_1
    entity_forecast_low_temp_2: sensor.dark_sky_forecast_overnight_low_temperature_2
    entity_forecast_low_temp_3: sensor.dark_sky_forecast_overnight_low_temperature_3
    entity_forecast_low_temp_4: sensor.dark_sky_forecast_overnight_low_temperature_4
    entity_forecast_low_temp_5: sensor.dark_sky_forecast_overnight_low_temperature_5
    entity_forecast_icon_1: sensor.dark_sky_forecast_icon_1
    entity_forecast_icon_2: sensor.dark_sky_forecast_icon_2
    entity_forecast_icon_3: sensor.dark_sky_forecast_icon_3
    entity_forecast_icon_4: sensor.dark_sky_forecast_icon_4
    entity_forecast_icon_5: sensor.dark_sky_forecast_icon_5
    entity_summary_1: sensor.dark_sky_forecast_summary_1
    entity_summary_2: sensor.dark_sky_forecast_summary_2
    entity_summary_3: sensor.dark_sky_forecast_summary_3
    entity_summary_4: sensor.dark_sky_forecast_summary_4
    entity_summary_5: sensor.dark_sky_forecast_summary_5
    entity_pop: sensor.dark_sky_forecast_precip_probability
    entity_pop_1: sensor.dark_sky_forecast_precip_probability_1
    entity_pop_2: sensor.dark_sky_forecast_precip_probability_2
    entity_pop_3: sensor.dark_sky_forecast_precip_probability_3
    entity_pop_4: sensor.dark_sky_forecast_precip_probability_4
    entity_pop_5: sensor.dark_sky_forecast_precip_probability_5
    entity_precip_intensity_1: sensor.dark_sky_forecast_precip_intensity_1
    entity_precip_intensity_2: sensor.dark_sky_forecast_precip_intensity_2
    entity_precip_intensity_3: sensor.dark_sky_forecast_precip_intensity_3
    entity_precip_intensity_4: sensor.dark_sky_forecast_precip_intensity_4
    entity_precip_intensity_5: sensor.dark_sky_forecast_precip_intensity_5
    show_beaufort: true
    tooltips: true
    old_daily_format: false
    static_icons: false
    locale: nl
    tooltip_bg_color: 'rgb( 75,155,239)'
    tooltip_border_color: orange

Well, that error is basically saying that the value in [this.config.entity_sun] is undefinedā€¦ which can either mean that the value being passed in the lovelace config is not an entity in home assistant or if it is an entity, that the entityā€™s value is undefined. based on your screenshots you are passing in sun.sun and sun.sun has a value (and attributes). not sure what the issue is ā€¦ all that seems correct.

Try removing entity_sun from your lovelace config. That should prevent it from trying to display the sunset information. Just to see if the rest of the card works or if there is another error being masked by this.

sure will try, and the entities are indeed correct, see my ā€˜old config/litā€™ card, thanks for having a look:

update:

still the same error:

with this config:

# https://github.com/iammexx/home-assistant-config/tree/master/ui/darksky
  - type: custom:dark-sky-weather-card
#    entity_sun: sun.sun
    entity_daily_summary: sensor.dark_sky_daily_summary
    etc

what surprises me is that with the sun config commented out, the old card still show the sun setting/rising :wink:

Thanks M.P.
I have to say that there must be something fundamentally wrong with my setup (Iā€™ve actually tried several versions including some of the postings here that folks have gotten to work. I did what you said.

I deleted the .css file.
I downloaded your latest js file from: here and it is the only file in my custom_ui folder.
Iā€™ve checked my ui-lovelace.yaml. and here it is:

resources:
  - url: /local/custom_ui/dark-sky-weather-card.js?v=7.1
type: module
 

title: Home Assistant
views:
  - icon: mdi:weather-cloudy
  - title: Weather
    cards:
    type: 'custom:dark-sky-weather-card'
    entity_current_conditions: sensor.dark_sky_icon
    entity_temperature: sensor.dark_sky_temperature
    entity_forecast_high_temp_1: sensor.dark_sky_daytime_high_temperature_1
    entity_forecast_high_temp_2: sensor.dark_sky_daytime_high_temperature_2
    entity_forecast_high_temp_3: sensor.dark_sky_daytime_high_temperature_3
    entity_forecast_high_temp_4: sensor.dark_sky_daytime_high_temperature_4
    entity_forecast_high_temp_5: sensor.dark_sky_daytime_high_temperature_5
    entity_forecast_icon_1: sensor.dark_sky_icon_1
    entity_forecast_icon_2: sensor.dark_sky_icon_2
    entity_forecast_icon_3: sensor.dark_sky_icon_3
    entity_forecast_icon_4: sensor.dark_sky_icon_4
    entity_forecast_icon_5: sensor.dark_sky_icon_5
    entity_forecast_low_temp_1: sensor.dark_sky_overnight_low_temperature_0
    entity_forecast_low_temp_2: sensor.dark_sky_overnight_low_temperature_1
    entity_forecast_low_temp_3: sensor.dark_sky_overnight_low_temperature_2
    entity_forecast_low_temp_4: sensor.dark_sky_overnight_low_temperature_3
    entity_forecast_low_temp_5: sensor.dark_sky_overnight_low_temperature_4
    entity_summary_1: sensor.dark_sky_summary_1
    entity_summary_2: sensor.dark_sky_summary_2
    entity_summary_3: sensor.dark_sky_summary_3
    entity_summary_4: sensor.dark_sky_summary_4
    entity_summary_5: sensor.dark_sky_summary_5
    entity_sun: sun.sun
    entity_visibility: sensor.dark_sky_visibility
    entity_daytime_high: sensor.dark_sky_daytime_high_temperature_0
    entity_wind_bearing: sensor.dark_sky_wind_bearing
    entity_wind_speed: sensor.dark_sky_wind_speed
    entity_humidity: sensor.dark_sky_humidity
    entity_pressure: sensor.dark_sky_pressure
    entity_apparent_temp: sensor.dark_sky_apparent_temperature
    entity_daily_summary: sensor.dark_sky_daily_summary
    entity_pop: sensor.dark_sky_precip_probability
    entity_pop_intensity: sensor.dark_sky_precip_intensity
    entity_pop_1: sensor.dark_sky_precip_probability_1
    entity_pop_2: sensor.dark_sky_precip_probability_2
    entity_pop_3: sensor.dark_sky_precip_probability_3
    entity_pop_4: sensor.dark_sky_precip_probability_4
    entity_pop_5: sensor.dark_sky_precip_probability_5
    entity_current_text: sensor.dark_sky_current_text
    locale: en
    static_icons: false
    tooltip_bg_color: 'rgb( 75,155,239)'
    tooltip_border_color: orange
    tooltip_border_width: 3
    tooltip_caret_size: 10
    tooltip_fg_color: '#fff'
    tooltip_left_offset: -12
    tooltip_width: 100
    tooltips: true
    old_daily_format: false
    time_format: 24
    show_beaufort: true

This is actually progress because after a reboot, now it says Iā€™m missing entity_daytime_high
Here is the debug console error:

dark-sky-weather-card.js?v=7.1.2:98 Uncaught (in promise) TypeError: Cannot read property 'state' of undefined
    at HTMLElement.slotValue (dark-sky-weather-card.js?v=7.1.2:98)
    at HTMLElement.get slots [as slots] (dark-sky-weather-card.js?v=7.1.2:80)
    at HTMLElement.render (dark-sky-weather-card.js?v=7.1.2:44)
    at HTMLElement.update (app-19bfb9ea.js:1191)
    at HTMLElement._validate (app-19bfb9ea.js:1167)
    at HTMLElement._invalidate (app-19bfb9ea.js:1167)

and sure enough when I check states, I see sensor.dark_sky_daytime_high_temperature_1 through 5 but not 0. Any thoughts?

Thank you for the help. (I feel really silly that I canā€™t get it to work!)
Bart

can you post your darksky sensor configā€¦

Sure:
- platform: darksky
api_key: xxxxxxxxxxxxxxxxxxxxxxx
forecast:
- 1
- 2
- 3
- 4
- 5
monitored_conditions:
- icon
- summary
- nearest_storm_distance
- nearest_storm_bearing
- humidity
- temperature
- temperature_high
- temperature_low
- apparent_temperature
- apparent_temperature_high
- apparent_temperature_low
- wind_speed
- wind_bearing
- precip_type
- precip_probability
- precip_accumulation
- precip_intensity
- precip_intensity_max
- uv_index
- daily_summary
- pressure
- visibility
update_interval:
minutes: 10

# Weather convert wind speed
  - platform: template
sensors:
  wind_speed_mph:
    unit_of_measurement: "mph"
    value_template: "{{(states('sensor.weather_wind_speed')| float * 2.23694) | round(1) }}"
#      temp_deg_f:
#        unit_of_measurement: "ĀŗF"
#        value_template: "{{((states('sensor.weather_temperature')| float * 1.8) + 32) | round(1) }}"
  weather_pressure_inhg:
    friendly_name: "Weather Pressure"
    unit_of_measurement: "inHg"
    value_template: "{{(states('sensor.weather_pressure')|float / 33.76895 ) | round(2) }}"
  weather_precipitation_in:
    friendly_name: "Weather Precipitation"
    unit_of_measurement: "in"
    value_template: "{{(states('sensor.weather_precipitation')|float / 25.4 ) | round(1) }}"
  friendly_wind_direction:
    friendly_name: 'Wind Direction'
    value_template: >-
      {%if states.sensor.weather_wind_direction.state | float<=11 %}N
      {% elif states.sensor.weather_wind_direction.state | float>348 %}N
      {% elif states.sensor.weather_wind_direction.state | float<=34 | float>11 %}NNE
      {% elif states.sensor.weather_wind_direction.state | float<=56 | float>34 %}NE
      {% elif states.sensor.weather_wind_direction.state | float<=79 | float>56 %}ENE
      {% elif states.sensor.weather_wind_direction.state | float<=101 | float>79 %}E
      {% elif states.sensor.weather_wind_direction.state | float<=124 | float>101 %}ESE
      {% elif states.sensor.weather_wind_direction.state | float<=146 | float>124 %}SE
      {% elif states.sensor.weather_wind_direction.state | float<=169 | float>146 %}SSE
      {% elif states.sensor.weather_wind_direction.state | float<=191 | float>169 %}S
      {% elif states.sensor.weather_wind_direction.state | float<=214 | float>191 %}SSW
      {% elif states.sensor.weather_wind_direction.state | float<=236 | float>214 %}SW
      {% elif states.sensor.weather_wind_direction.state | float<=259 | float>236 %}WSW
      {% elif states.sensor.weather_wind_direction.state | float<=281 | float>259 %}W
      {% elif states.sensor.weather_wind_direction.state | float<=304 | float>281 %}WNW
      {% elif states.sensor.weather_wind_direction.state | float<=326 | float>304 %}NW
      {% elif states.sensor.weather_wind_direction.state | float<=348 | float>326 %}NNW
      {%- endif %}
  dark_sky_current_text:
    value_template: >-
      '{% if is_state("sensor.dark_sky_icon","clear-day") %} Clear 
       {% elif is_state("sensor.dark_sky_icon","clear-night") %} Clear 
       {% elif is_state("sensor.dark_sky_icon","rain") %} Rain
       {% elif is_state("sensor.dark_sky_icon","snow") %} Snowy
       {% elif is_state("sensor.dark_sky_icon","fog") %} Foggy
       {% elif is_state("sensor.dark_sky_icon","sleet") %} Sleet
       {% elif is_state("sensor.dark_sky_icon","wind") %} Windy
       {% elif is_state("sensor.dark_sky_icon","cloudy") %} Cloudy
       {% elif is_state("sensor.dark_sky_icon","partly-cloudy-day") %} Partly Cloudy
       {% elif is_state("sensor.dark_sky_icon","partly-cloudy-night") %} Partly Cloudy
       {% elif is_state("sensor.dark_sky_icon","hail") %} Hailing
       {% elif is_state("sensor.dark_sky_icon","lightning") %} Lightning
       {% elif is_state("sensor.dark_sky_icon","thunderstorm") %} Thunderstorm

I would say based on what you are showing and saying that the config you are changing isnā€™t the config for the card in question. I donā€™t known how that is possible but with entity_sun commented out the card has no way to provide sunset information. It replaces the html with `` (an empty string).

Add forecast day 0 to your config and restart HAā€¦

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

Finally Success!
Thanks for your help and patience. Iā€™m embarrassed to say I spent 5 days on and off and to get here feels great.

Thanks very much m.p. This is a nice piece of work and I learned about all sorts of things in HA trying to figure out how to make it work.

Bart

Awesome!, Glad you finally got it working .

thought it to be a cache issue maybe, so cleared the cache, updated the version number, restartedā€¦
still showing the sun icons ?!?

of course it i the config of my dark-sky-weather-cards.js, and it is a module isnt it? just like the ;oldā€™ card?
Im stumpedā€¦

wouldnā€™t it be a nice feature if we could conditionally set the colour of the big temp based on the temp.

I use this customization for my regular sensors icons to give you an idea of what I am looking for. Can we set the styles to use a template?:

sensor.dark_sky_*temperature*:
  templates:
    icon_color: >
      if (state < -5) return 'rgb(30, 255, 255)';
      if (state < 0) return 'rgb(30, 144, 255)';
      if (state < 10) return 'rgb(255, 255, 0)';
      if (state < 15) return 'rgb(255, 211, 30)';
      if (state < 20) return 'rgb(0, 128, 0)';
      return 'rgb(255, 165, 0)';

tried something like this, bt it wonā€™t work obviously:

  var tempIconColor = this.hass.states[this.config.entity_temperature].state <= -5 ? 'rgb(30, 255, 255)':
                      this.hass.states[this.config.entity_temperature].state <= 0 ? 'rgb(30, 144, 255)':
                      this.hass.states[this.config.entity_temperature].state <= 10 ? 'rgb(255, 255, 0)':
                      this.hass.states[this.config.entity_temperature].state <= 15 ? 'rgb(255, 211, 30)':
                      this.hass.states[this.config.entity_temperature].state <= 20 ? 'rgb(0, 128, 0)': 'rgb(255, 165, 0)';

or with this.current.temperatureā€¦

and set that in the style .temp
please consider?

Hi. Iā€™m on 0.84.6. Iā€™ve had the card working for a while. Allof a sudden it stopped working. I see this in the console.

Access to script at ā€˜https://unpkg-gcp.firebaseapp.com/@polymer/[email protected]/lit-element.js?moduleā€™ from origin ā€˜https://xxxxxxxxx.duckdns.orgā€™ has been blocked by CORS policy: No ā€˜Access-Control-Allow-Originā€™ header is present on the requested resource.

I havenā€™t changed anything witht the card. I had upgraded the first line in the .js file to this and it had been working consistently.

import { LitElement, html, } from ā€˜https://unpkg-gcp.firebaseapp.com/@polymer/[email protected]/lit-element.js?moduleā€™;

I assume this is a unpkg issue again? Should I just be patient or is it dead? I wasnā€™t planning on upgrading to 0.86 yet but would that fix the issue?