Entity is non-numeric when state is 'unknown' using built in Gauge card

Hi, still getting to grips with HA with no prior coding experience so please bear with me. I will try to explain the issue that I am seeing as clearly as possible.
I am using the built in ‘Gauge Card’ in Lovelace to display the current electricity cost in GBP for the day so far. The data for the gauge is coming form sensor.electric_cost_today which is an entity provided by an installed integration of ha-hildebrandglow-dcc which uses the data provided form my smart meter.
My gauge card configuration is as follows:

type: gauge
entity: sensor.electric_cost_today
min: 0
severity:
  green: 0
  yellow: 2
  red: 4
needle: true
max: 10

The Gauge Card works fine, until I reboot Home Assistant. While rebooting, where this Gauge Card normally displays, there is an error message saying ‘Entity is non-numeric: sensor.electric_cost_today’

I have checked the state of the entity during a HA restart, and the state shows as ‘unknown’

state unknown

When the sensor does start returning a numeric value for the state which the Gauge Card can display, it starts working again.
If possible I would like to handle this error message gracefully, so that perhaps the words ‘Waiting for Data’ or similar are displayed until the correct value can be returned.

I have found a handful of other forum posts about this state unknown error, such as this one:

and have tried to implement a fix, however i’m as yet a little out of my depth until I can do some more reading and learn more about sensors and templates!

What I have tried to do is to add the following to my config.yaml file

sensor:
   - platform: hildebrandglow_dcc
     name: 'electric cost today'
     unit_of_measurement: 'GBP'
     value_template: >
     '{% if is_state(': sensor.electric_cost_today', 'unknown', 'Unknown', 'none', 'None') %}
     Waiting for Data...
     {% else %}
     {{ states('sensor.electric_cost_today') }}
     {% endif %}

However the error still displays upon restart.
Can I achieve what I want, or do I need to look at an alternative workaround such as either just not displaying the Gauge Card until the value can be delivered successfully, or showing zero until such time? These options look to be possible using either a conditional display setting or adding in a ‘float’ but again I’m unfamiliar with all of this as yet.

Thanks for any help!

Add this to your configuration.yaml file and use the new sensor this creates, sensor.electric_cost, in your gauge card:

template:
  - sensor:
      - name: "Electric Cost"
        unit_of_measurement: "$"
        icon: "mdi:flash"
        state:  "{{ states('sensor.electric_cost_today')|float(0) }}"

The way this template works is it attempts to convert the state of your electric cost today sensor to a floating point number. If it can’t, because the state is a word like ‘unknown’ it will use the default ‘0’ instead.

Thanks very much Tom. With your code in place in my config.yaml file, I do still see the ‘Entity is non-numeric’ message while HA restarts, while other integrations like ZHA are displaying ‘Home Assistant is starting, not everything may be available yet’

Starting2

Then once ZHA finishes loading the entities, the Gauge Card with the new sensor does start to show ‘0’ after this point, for around a minute until it starts displaying actual values.

So this is definitely better - however is there any way this Gauge Card can display the same message as the other items (ZHA) while it is loading? If not, is it possible, adjusting your config you kindly provided, to display ‘Waiting for Data…’ instead of displaying the ‘0’?
Finally, is it possible to have the £ sign (unit_of_measurement) appear BEFORE the data value in the Gauge, so it would appear as £0 instead of 0£?

Thanks

No, none of that is possible.

Thanks Tom, that’s a shame. It looks like a custom card would be required if I want the £ to be displayed before the value rather than after it - unless the built in card is updated in future.