Preventing extra spaces in text being removed in sensor state (where text is used)

I’m creating a sensor and setting it’s state as Text as a means of displaying dynamic text. Works well, however if I’m spacing out text I’m noting any spaces >1 in a row are removed, so you only ever have 1 space, which prevents me formating the text.

Any ideas how to prevent a Dashboard item, widget_type = sensor, to behave so it doesn’t do this for text used…

e.g.

power_notes:
  widget_type: sensor
  entity: sensor.dashboard_notes_power
  widget_style:  "font-family: Courier New; font-size: 140%; text-align: left;" # background: black;"

.

  def _dashboard_clearcost_update(self, power_usage, solar_generation):
    def justify(myInt):
      return str(int(myInt)).rjust(5, '·')
    available_power = solar_generation - power_usage
    available_power = 0 if available_power < 0 else available_power
    self._gc_set_state(
      DASHBOARD_NOTES_POWER, 
      state = "Solar: %s W<BR/>Power: %s W<BR/><HR/>Avail: %s W" % (justify(solar_generation), justify(power_usage), justify(available_power))
    )

It looks like you’re already using html markup.
&nbsp; is the code for “non-breaking space” and might solve your problem?

HTML just ignores extra spaces unless you find a way to force it to show them.
so its not a dashboard but an HTML issue.

the answer from @lolouk44 could be the answer.
if that doesnt work you could google for “HTML multiple spaces”

i had a simular problem when i created a webpage with sensor values, and i solved it by using underscores.

1 Like

thanks guys - the " " worked!

(should have thought of this myself, especially since I’d tried the
days earlier and got the line break working) :slight_smile:

1 Like