#Customize Badge State Text

1 messages · Page 1 of 1 (latest)

mental cradle
#

It's looking like the answer is no ☹️ but is there any way to customize how the state_content is rendered in badges (or other built-in cards, for that matter)?

As an example, I'm including the last_triggered state on this badge, but it ends up taking up a lot more space by writing out 19 hours ago when it'd be great if I could use a template to render this as 19h, or even make this count down down instead (since the action triggers something after a delay). There seems to be state_filter that can let you build relatively complex logic for whether the badge shows up or not, but seemingly nothing to customize how it actually shows up when it does.

From what I can tell online, it seems like the general solution is to create template sensors for everything and do the customizing there, but having two entries for every entity and wiring up the actions etc. gets gross pretty fast. 😬

halcyon pulsar
#

Just use jinja 🙂 {{ (as_timestamp(now()) - as_timestamp(state.last_triggered)) / 3600 | round(0) }}h

#

I also highly recommend asking chatgpt as it will literally code for you

mental cradle
#

Where do you put this though?

#

To clarify: state_content does not accept an arbitrary string to display. It takes an array of keys like name, state, last_updated attempting to give it this template or even just a string results in it falling back to just showing the on/off state

clear echo
#

You cannot use jinja here.

#

Not ready yet but it appears to be making progress.

mental cradle
#

That's a great improvement! Although while we're making changes in there, it'd be great if there was also an option to customize it however you like

clear echo
#

How would you customize it "however you like?"

mental cradle
#

By letting you pass in a jinja templated string instead of picking from a hardcoded set of keys or time formats

clear echo
#

If you notice there is nearly zero jinja usage anywhere in the frontend. So I doubt that is going to happen.

mental cradle
#

Maybe I'm misunderstanding how it works, but when I edit the badge, and choose the code editor, it's a YAML format. Is that YAML being parsed and evaluated on the frontend? I thought that configured what data the "backend" passes to the badge component to render. My hope is in addition to or instead of this list of keys passed to pick what to show (state_content), I could have some sort of templated text that can consume any of those values and render it how I like, similar to what I'm doing for this notification message. That template could be evaluated whenever those values change and get "pushed" to the frontend with the same mechanism that the state or update time etc. get passed

clear echo
#

I would think if you want custom text the way to achieve that is just make a template sensor.