Add a whitespace to the sensor output value in Mushroom Chip

Hey!

Guys I’ve a illuminance sensor: this way {{ states('sensor.balcony_light_sensor_illuminance_lux') }} return value like this: 9809. But, in original sensor value in HA looks like this: 9 809 or 28 756 and etc. If I add template sensor of this value, I don’t have a whitespace and only raw value, how to add a whitespace after the first digit or first two digits like in original sensor via template?

On the left is a template sensor - on the right is the original sensor:
image

Check this setting:

Also why are you duplicating the sensor?

Is that left one a template chip?

I’m not duplicating, I just added this sensor to mushroom template chip, and get raw value, and don’t know how to fix that.

Yep, this is the template chip.

That was vital missing information. I have moved your post to the correct category.

It’s what i did:

                - type: template
                  entity: sensor.balcony_light_sensor_illuminance_lux
                  content: "{% if states('sensor.balcony_light_sensor_illuminance_lux') | int > 0 %}{{ states('sensor.balcony_light_sensor_illuminance_lux') | int }} lx{% else %}Night{% endif %}"

Yes, sorry. I don’t make a template sensor, probably I need to ask in mushroom topic…

The actual state is like you get from your template. The frontend formats numeric values from sensors based on your profile settings.

If you use a template it will return the actual state, without the formatting. If you want a space as thousands separator, you need to do that formatting in your template

I tried a few tips, but without a result. :melting_face:

Okay, I had trying something like this:

{{ '{0:_.0f}'.format(states('sensor.balcony_light_sensor_illuminance_lux') | int).replace('_', ' ') }}

Hope it’s correctly. :+1:

That should work

- type: template
  entity: sensor.balcony_light_sensor_illuminance_lux
  content: >
    {% set lx = states(entity) | int(0) %}
    {% set lx_format = '{0:_.0f}'.format(lx) | replace('_', ' ') ~ ' lx' %}
    {{ lx_format if lx > 0 else 'Night' }}
1 Like