Modify MQTT Sensor Decimal Point Location

I have a new MQTT sensor defined which reading as a 3 digit number such as 721. I need this to become a % such as 72%. I’ve tried a few value templates and can get it to work under developer tools but does not work in the configuration.yaml.

mqtt:
  sensor:
    - name: "Victron State of Charge"
      unique_id: "Victron State of Charge"
      state_topic: "SMARTBMS/SOC"
      value_template: "{{value}}"
      unit_of_measurement: "%"
      device_class: "battery"

Under Dev Tools Value Template I have this and I get a good result, just not in the configuration file for the sensor:

>-
          {% set percent = ((states('sensor.victron_state_of_charge') | float(0) / 1000))%}
          {{ percent * 100|round(0)}}

Output 72.1

Any assistance would be greatly appreciated.

In your dev tools, your 100 is getting rounded then multiplied. Use parens.

{{ (percent * 100) | round(0) }}

Do the same in your sensor.

Once if have this in the configuration.yaml, it becomes a 0 for output. No errors.

The only time I get the value from the mqtt sensor is with this config.

    - name: "Victron State of Charge"
      unique_id: "Victron State of Charge"
      state_topic: "SMARTBMS/SOC"
      value_template: "{{value}}"
      unit_of_measurement: "%"
      device_class: "battery"

the number off the raw sensor is 721 which needs to be 72.1%.

Oh, do math on it in the value_template output then.

New to this, researching as much as I can before I ask but this one escapes me. How is that achieved?

May have this now:

>-
          {% set percent = ((states('sensor.victron_state_of_charge') | float(0)))%}
          {{ (percent * 0.1)|round(0) }}

Nevermind, doesn’t output anything when it’s in the sensor section of the config.