šŸ“ 100% Templatable Lovelace Configurations

No worry, thatā€™s what I suspected, not about your javascript at all :slight_smile:

card object is for a single card declaration. If you had your cards in a stack, you could put config-template-card outside the stack and reuse variables for everything inside the stackā€¦but that could potentially get pretty messy

So I have a card showing a time but not friendlyā€¦ itā€™s an attributeā€¦

image

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

Where var[5] is states[ā€˜sensor.abb_usageā€™].attributes[ā€˜lastupdatedā€™]
How can I get it to show as a normal timestamp like this:
image

ā€˜toLocaleDateString(vars[5])ā€™ doesnā€™t work with ot without the ā€˜ā€™

Try this:
name: "${'Last Updated ' +'\xa0'.repeat(2) + moment(vars[5]).format('MMMM Do YYYY, h:mm a')}"

thanks but it wonā€™t accept that - whole card disappears
new Intl.DateTimeFormat(ā€˜en-AUā€™, options).format(vars[5])
doesnā€™t work either

I tested with this, works fine.
Is your ā€˜lastupdatedā€™ UTC datetime?

  - type: custom:config-template-card
    variables:
      - states['automation.tts_door_sensor'].attributes['last_triggered']
    config:          
      type: custom:hui-entities-card
      title: "${'Last Updated ' +'\xa0'.repeat(2) + moment(vars[0]).format('MMMM Do YYYY, h:mm a')}"

image

                  name: "${'Last Updated ' +'\xa0'.repeat(2) + moment(vars[5]).format('MMMM Do YYYY, h:mm a')}"

kills the cardā€¦ no idea why

I got into this mess in the first place because my iPad (not my PC) was treating the data as UTC not local. So I spent the day screwing around with reading the XML from my ISP and converting it to JSON and then publishing that to MQTT to create the sensorā€¦ so I did discover that I was getting an invalid date when I added the TZ as +1100 (but only on iPad) and discovered it needs +11:00ā€¦
But itā€™s showing this as a nasty stringā€¦

Again, sorry if Im missing something, this is literally the second piece of javascript Ive ever written. I used the Date object differently, which worked for me above.

You have:

toLocaleDateString(vars[5])

Whereas I have something like:

Date(vars[5]).toLocaleDateString('en-US', options)

Are there any methods to inject a more-info spec into a card? For example, it would be nice for my weather forecast card to only show today and tomorrow, but have the entire week in a more-info.

So, it looks like I have a problem using this card with switch and input_number entities.

When I have the input_number entity, and the switch is on, the render is 'jittery.

This is my config :

- type: custom:config-template-card              
       variables:
                   - states['media_player.mpd'].attributes['media_artist']                                             
                   - states['media_player.mpd'].attributes['media_title']
                   - states['media_player.mpd'].state     
        card: 
                    type: 'custom:hui-entities-card'
                    title: Interrupteurs
                    show_header_toggle: false
                    entities:
                      - type: section
                        label : Lumieres
                      - type: entity
                        icon: mdi:lightbulb
                        entity : switch.sonoff_t1_relay
                        name: Plafond Chambre
                      - type: section
                        label : Radio
                      - type: entity
                        entity: input_boolean.switch_walter
                      - type: entity
                        entity: input_number.music_volume
                      - type: entity
                        entity: media_player.mpd
                        name: "${vars[2] === 'off' || vars[2] === 'unavailable'  ? 'Music Daemon' : vars[0]+' '+ vars[1]}"

And this is the result :

jittery

When i delete the input_number entity, everythings fine :

not_jittery

Can somebody explain if iā€™m doing something wrong ?

Have you tried adding these entities as a list to the custom card itself along with type, card, and variables, i.e. in addition to the entities being in the csrd?

Thanks for the pointer.

It solved the problem !

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

And the whole card disappearsā€¦

You need to define options first, see my example above for just day of week. I think you also need a new in front of Date, note Capitalization.

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

kills cardā€¦
I donā€™t see how to include options in this code above

Still havenā€™t defined options. Look at my card above

as I saidā€¦ I donā€™t see how to define that in my code. Your example is much more complicated and I donā€™t understand how to adapt itā€¦

Try this at the beginning

var options={ weekday:'long'};
                - entity: sensor.abb_usage
                  name: "${var options={ weekday:'long'};'Last Updated ' + '\xa0'.repeat(2) + new Date(vars[5]).toLocalDateString('en-US', options)}"
                  icon: mdi:clock

dead