Change how an attribute is displayed

Hey guys,

Hoping someone could help as my searched are drawing a blank (maybe it’s not possible)…

I’ve been working on an energy dashboard for a little while now and finally have it working.

I have a binary sensor showing an attribute in an entity card to display the cheapest period of electricity at varying blocks throughout the day, however it’s quite visually unpleasing to me.

Does anyone know how I could edit this attirbute so it displays as time only, XX:XX… or add a new attribute which will display as this. I don’t need to know the day as it’s always “today”, and I don’t need the seconds either.

Maybe being a bit pedantic, but quite precious over the look and feel of what I’m building.

Thanks

You can create a template sensor to manipulate and format the attribute in any way you want. You didn’t say what integration creates the binary sensor or provide any details about the nature of the attribute, but it doesn’t look to be a timestamp, perhaps just a string. Assuming the attribute is very reliably formatted this way, you could get it to look the way you want with something like

{{ state_attr("binary_sensor.your_sensor","your_attribute").split(" ")[4][0:5] }}

The integration is octopus energy. I’ve created target sensors which are binary sensors for finding 1, 2 and 4h consecutive blocks of the cheapest energy prices throughout the day. The attribute within these is “next_price” which displays the time each of these blocks start.

Then I want to be able to display them, so I can see eg - cheapest 1h block is 1pm, 2h block is 1pm, 4h block is 3pm.

I’d settle for the above, as is displays the info I want but it’s just messy.

Would what you mentioned be suitable for my situation?