MQTT Sensor, add thousand separator to value

Hi there,

I’m getting SQL data with Node-Red and published to HA via MQTT.

  - name: "Test Fall23"
    state_topic: "homeassistant/uretim/toplam/siparis-fall23"

This gave me this type of data:

181345

But I want to convert as

181.345

How can I add value_template for adding thousand seperator?

thanks in advance

Convert it to a number and divide by 1000:

value_template: {{ (value_json | float(0)) / 1000 }}}

That’s a botch, using the fact that the “standard” decimal point looks like the EU thousands separator, and doesn’t work over six digits.

Why do you want to do that? The standard dashboard will already render numbers like that — the state of the entity shown below is 296281, and I’m in the UK with comma separators:

image

If you force the separators into the state, HA will stop recognising it as a number via filters like float and int — you’ll lose the ability to see it in graphs, use it as a trigger etc.

If you really must do this, I’d recommend using a template sensor for when you need the separators, like this:

template:
  - sensor:
      - name: Test Fall23 Sep
        state: "{{ '{:,}'.format(states('sensor.test_fall23')|int(0)).replace(',','.') }}"

…which adds comma separators, which we then replace with dots. If your input isn’t an integer, it’ll need a bit more work.

Yes, dividing is not a solution, doesnt work with 6 digits.

I’m not using standard dashboard elements. there are a few custom elements like charts, bars etc. I think the problem is custom elements. they are not render correctly.

let me check another option to get SQL data.

Thank you again.

Oops yes, I misread the OP’s question and assumed it needed to be divided once I saw the “.” and hadn’t noted he asked to update the thousands separator (as where I live that would be “,”).

I agree that you wouldn’t want to turn it into a string by putting a separator in there.