Adding a label to a custom Lovelace card

I finally got the dark sky card to work. I had two cities defined and that caused me all kinds of grief.

But it works great and Id like to add a label to each card so I know what city I’m looking at. Do I need to do this in the dark-sky-weather-card.js javascript file? I’m assuming yes. I’m NOT a js programmer so any help here much appreciated.

This is what I’d like it to look like (thanks PhotoShop)

Images would be even better:

// #####
// ##### Get the LitElement and HTML classes from an already defined HA Lovelace class
// #####
var LitElement = LitElement || Object.getPrototypeOf(customElements.get("home-assistant-main"));
var html = LitElement.prototype.html;

// #####
// ##### Custom Card Definition begins
// #####

class DarkSkyWeatherCard extends LitElement {

// #####
// ##### Define Render Template
// #####

  render() {
//  Handle Configuration Flags 
//    var icons = this.config.static_icons ? "static" : "animated";
    var currentText = this.config.entity_current_text ? html`<span class="currentText" id="current-text">${this._hass.states[this.config.entity_current_text].state}</span>` : ``;
    var apparentTemp = this.config.entity_apparent_temp ? html`<span class="apparent">${this.localeText.feelsLike} <span id="apparent-text">${this.current.apparent}</span> ${this.getUOM("temperature")}</span>` : ``;
    var summary = this.config.entity_daily_summary ? html`<br><span class="unit" id="daily-summary-text">${this._hass.states[this.config.entity_daily_summary].state}</span></br>` : ``;
    var separator = this.config.show_separator ? html`<hr class=line>` : ``;
    
    
    
// Build HTML    
    return html`
      <style>
      ${this.style()}
      </style>
      <ha-card class = "card">  
        <span class="icon bigger" id="icon-bigger" style="background: none, url(/local/icons/weather_icons/${this.config.static_icons ? "static" : "animated"}/${this.weatherIcons[this.current.conditions]}.svg) no-repeat; background-size: contain;">${this.current.conditions}</span>
        <span class="temp" id="temperature-text">${this.current.temperature}</span><span class="tempc">${this.getUOM('temperature')}</span>
        ${currentText}
        ${apparentTemp}
        ${separator}
        <span>
          <ul class="variations">
            <li>
              ${this.getSlot().l1} 
              ${this.getSlot().l2}
              ${this.getSlot().l3}
              ${this.getSlot().l4}
            </li>
            <li>
              ${this.getSlot().r1}
              ${this.getSlot().r2}
              ${this.getSlot().r3}
              ${this.getSlot().r4}
            </li>
          </ul>
        </span>
            <div class="forecast clear">
              ${this.forecast.map(daily => html`
                <div class="day fcasttooltip">
                  <span class="dayname" id="fcast-dayName-${daily.dayIndex}">${(daily.date).toLocaleDateString(this.config.locale,{weekday: 'short'})}</span>
                  <br><i class="icon" id="fcast-icon-${daily.dayIndex}" style="background: none, url(/local/icons/weather_icons/${this.config.static_icons ? "static" : "animated"}/${this.weatherIcons[this._hass.states[daily.condition].state]}.svg) no-repeat; background-size: contain;"></i>
                  ${this.config.old_daily_format ? html`<br><span class="highTemp" id="fcast-high-${daily.dayIndex}">${Math.round(this._hass.states[daily.temphigh].state)}${this.getUOM("temperature")}</span>
                                                        <br><span class="lowTemp" id="fcast-low-${daily.dayIndex}">${Math.round(this._hass.states[daily.templow].state)}${this.getUOM("temperature")}</span>` : 
                                                   html`<br><span class="lowTemp" id="fcast-low-${daily.dayIndex}">${Math.round(this._hass.states[daily.templow].state)}</span> / <span class="highTemp" id="fcast-high-${daily.dayIndex}">${Math.round(this._hass.states[daily.temphigh].state)}${this.getUOM("temperature")}</span>`}
                  ${this.config.entity_pop_1 && this.config.entity_pop_2 && this.config.entity_pop_3 && this.config.entity_pop_4 && this.config.entity_pop_5 ? html`<br><span class="pop" id="fcast-pop-${daily.dayIndex}">${Math.round(this._hass.states[daily.pop].state)} %</span>` : ``}
                  <div class="fcasttooltiptext" id="fcast-summary-${daily.dayIndex}">${ this.config.tooltips ? this._hass.states[daily.summary].state : ""}</div>
                </div>`)}
              </div>
        ${summary}
      </ha-card>
    `;
  }


Jeff

I wonder if it could be as simple as adding an image as a background, without modifying the source code using card-mod?

Ok, I’ll bite. How?

In the example below I positioned a Home Assistant logo in the top center, 20 pixels from the top.

- type: custom:weather-card
  style: |
    ha-card {
      background-image: url(/local/ui/hass.png);
      background-repeat: no-repeat;
      background-attachment: fixed;
      background-position: center 20px;
    }
  entity: weather.dark_sky

image

Edit: This requires https://github.com/thomasloven/lovelace-card-mod

hmm… I added this thru HACS and get no errors but my image doesnt show up.
I’m sure its a path problem as I get this error

GET https://rc2o77cp1gdll61vz9yjzvjd63kt5fab.ui.nabu.casa/local/icons/sr.jpg 404 
(Not Found) Failed to load resource: 
the server responded with a status of 404 (Not Found)

EDIT - I figured it out. I didnt have the file extension correctly spelled… jpg is not jpeg.
my config:

resources:
  - type: module
    url: /local/custom_ui/dark-sky-weather-card.js?v=7.1
  - url: /community_plugin/lovelace-card-mod/card-mod.js
    type: module
    panel: false
    path: default_view
    theme: material_dark_red
    title: Home
- badges: []
    cards:
      - type: 'custom:dark-sky-weather-card'
        style: |
          ha-card {
            background-image: url(/local/icons/sr.jpg);
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: center 20px;
           }
        entity: weather.dark_sky

what is the /local in relation to? /config or /config/www, or something else? my icons are in /config/www/icons

You are correct sir. I’ve never looked into the reasoning for referencing that folder with a different name… but, it works so I don’t worry about it. :slight_smile:

The space between the top of the image and the top of the widget is set in background-position: center 20px;. 20px = 20 pixels you can play with that number until you are happy with the spacing. If you want to dig into this further, search for “CSS” and “background-position”.

Anyone know of a way to add a link to the entire weather card? I have multiple card and if I click one of them I’d like a new tab to open with a link to a more detailed forecast like this:

https://forecast.weather.gov/MapClick.php?textField1=38.4404674&textField2=-122.71443139999997#.Vz96jfkrKUk

Somewhere here?


style: |
          ha-card {
            background-image: url(/local/icons/sr.jpg);
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: center 20px;
           }

I found this, but it’s not quite what I need - how do you get the link there in Lovelace?