šŸ“ 100% Templatable Lovelace Configurations

You can also use toLocalDateString() to test whether it is your definition of options that is the problem. Could also be that your string isnā€™t a valid date time string?

Itā€™s a valid datestring 100%.

While Iā€™m trying to crack the magic sauce for using it in the template card, I created a template sensor from that attribute and set class as timestamp and I can display it however I like by changing the format:

              entities:
                - entity: sensor.abbupdate
                  name: "${'Last Updated '}"
                  icon: mdi:clock
                  format: relative

Can you edit my above code with the toLocalDateString() in it to show me please?
Do you mean:

                - entity: sensor.abb_usage
                  name: "${'Last Updated ' + '\xa0'.repeat(2) + toLocalDateString(vars[5])}"
                  icon: mdi:clock

Do you have an aversion to posting the actual code I should try? (Needless to say it doesnā€™t work)

I would try

- entity: sensor.abb_usage
  name: "${'Last Updated ' + '\xa0'.repeat(2) + new Date(datetimestring).toLocaleDateString()}"

I was copy pasting your code before. Iā€™m just noticing the local vs locale.

1 Like

Okā€¦ now Iā€™m getting a result.
3/25/2019 - and no timeā€¦ but I think I can get there from here nowā€¦

new Date(vars[5]).toLocaleDateString('en-AU', {weekday:'long'})}"
That gives me Monday

This works too
new Date(vars[5]).toLocaleDateString('en-AU', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric'}) + '\xa0' + new Date(vars[5]).toLocaleTimeString('en-AU')
image

This (new Date().getTime() - new Date(vars[5])) is returning the number of seconds between now and var 5. But I donā€™t seem to be able to show that in minutes?
866109 is not 14 minutes thoughā€¦ I think I need to convert the NOW time to localā€¦

Actually dividing by 60000 did wondersā€¦
name: "${'Last Updated ' + '\_'.repeat(2) + ((new Date().getTime() - new Date(vars[5]))/60000)}"
But how do I get it as an integer?

ahā€¦ finallyā€¦
Number.parseInt

Any direction on making the custom weather sensor?

@iantrich I notice that the template isnā€™t being re-evaluated unless the underlying ā€˜dataā€™ changesā€¦ so if Iā€™m using a time (now) it can get 15 minutes behind - is there any way to force a refresh?

Iā€™m not sure I follow what you mean by custom weather sensor. I have been using the stock weather forecast card using a custom component for the weather platform using US NWS data. I wanted to add the text forecast to it, which iantrichs card somewhat solves for me for now. I will probably post the custom component (or is it platform, or integration? Iā€™m not sure anymore) for testing soon before I submit a PR.

I have modified the stock card to have a day/night forecast mode and display % precipitation, but these were somewhat simple extensions of existing card functionalities.

Almost thereā€¦ My ISP totally changed the usage information today, new informationā€¦ sighā€¦

I am trying to calculate the rollover date:

"${'Rollover Date' + '\xa0'.repeat(3) + (new Date(vars[7] + vars[6])).toLocaleDateString('en-AU', {weekday: 'short', year: 'numeric', month: 'short', day: 'numeric'})}"

Var[7] is the ISO format date and vars[6] is an integer number of days to add.

I just get invalid dateā€¦ how can I add a date?

Having some trouble using this card. I get an invalid configuration error. Not sure what iā€™m doing wrong here.

Config:

title: Main
icon: mdi:home-outline
cards:
  - type: 'custom:config-template-card'
    variables:
      - states['device_tracker.life360_mike_davis'].attributes['battery']
    card:
      - type: 'custom:hui-entities-card'
        title: Phones and Tablets
        show_header_toggle: false
        entities:
          - entity: device_tracker.life360_mike_davis
            type: "custom:secondaryinfo-entity-row"
            secondary_info: "Battery: ${ vars[0] }"

Error:
2019-03-26_7-48-57

Try this:

secondary_info: "${ 'Battery: ' + vars[0] }"

Thanks. Same issue though. The error message just changed to reflect the update to that piece.

EDIT: Figured it out.

Changed:

card:
  - type: 'custom:hui-entities-card'
    title: Phones and Tablets
    show_header_toggle: false
    entities:
      - entity: device_tracker.life360_mike_davis
        type: "custom:secondaryinfo-entity-row"
        secondary_info: "Battery: ${ vars[0] }"

to

card:
  type: custom:hui-entities-card  <---Removed the dash in front of type
  title: Phones and Tablets
  show_header_toggle: false
  entities:
    - entity: device_tracker.life360_mike_davis
      type: "custom:secondaryinfo-entity-row"
      secondary_info: "${ 'Battery: ' + vars[0] }"

Yep, card is singular, not a list

Ahh, i see. Thanks for the info.

I tracked the error back to this snippet of code, ā€œ!config.card.typeā€ made me think to change the type there. I had no idea why. But thatā€™s usually how I roll, just fumble through stuff until it works. lol. I do learn along the way though.

let ConfigTemplateCard = class ConfigTemplateCard extends LitElement {
    setConfig(config) {
        if (!config || !config.card || !config.card.type) {
            throw new Error("Invalid configuration");

What does this have to do with the config-template-card?

sorry, i posted in the wrong thread, now I will remove it

Iā€™m using the config-template-card to support choosing the desired Fire TV with the custom:button-card as the ā€œcard:ā€

Unfortunately, the ā€œstyle:ā€ for the button-card is also being applied to the parent config-template-card so I have double borders. Also, the square outline of the config-template-card is visible.
Any thoughts?
button

          - type: custom:config-template-card
            variables:
              - states['input_select.firetv_choices'].state
            entities:
              - input_select.firetv_choices'
            card:
              type: custom:button-card
              entity: "${vars[0] === 'FireTV Living Room' ? 'media_player.firetv_living_room' : 'media_player.firetv_bedroom'}"
              style:
                - background-color: rgba(56,60,69,1)
                - border-radius: 20px
                - border: solid 3px rgba(118,185,0,1)
                - box-shadow: 3px 3px rgba(0,0,0,0.4)
              action: service
              icon: mdi:plex
              name: LIVETV
              service:
                domain: script
                action: set_plex_to_livetv
                data:
                  entity: "${vars[0] === 'FireTV Living Room' ? 'media_player.firetv_living_room' : 'media_player.firetv_bedroom'}"

There is no parent card, itā€™s just a pass through. Are you sure you donā€™t have something strange surrounding this card or itā€™s on a picture-elements where it is somehow overlapped? What youā€™re showing is not plausible.

Not sure. I moved the button config to the top, still the same. Hereā€™s the beginning of the lovelace view including the button as the first entity. When the view loads, the inner and outer borders are almost aligned. Upon selecting the button, the inner border collapses to the boundaries I showed in the prior post.

  - title: FireStick
    id: firestick_lr
    type: custom:layout-card
    layout: vertical
    cards:
      - type: horizontal-stack
        cards:
          - type: custom:config-template-card
            variables:
              - states['input_select.firetv_choices'].state
            entities:
              - input_select.firetv_choices
            card:
              type: custom:button-card
              entity: "${vars[0] === 'FireTV Living Room' ? 'media_player.firetv_living_room' : 'media_player.firetv_bedroom'}"
              style:
                - background-color: rgba(56,60,69,1)
                - border-radius: 20px
                - border: solid 3px rgba(118,185,0,1)
                - box-shadow: 3px 3px rgba(0,0,0,0.4)
              action: service
              icon: mdi:plex
              name: LIVETV
              service:
                domain: script
                action: set_plex_to_livetv
                data:
                  entity: "${vars[0] === 'FireTV Living Room' ? 'media_player.firetv_living_room' : 'media_player.firetv_bedroom'}"

In the morning Iā€™ll try a card-modder and an entity-button card within the config-template-card to define the button and its style and maybe confine the borders to the button