MQTT percentage

Dear hive mind.
I have a MQTT topic that when i listen for it I get the following response:

Message 0 received on automower/mower/battery/charge at 12:38:
100 %

My YAML is in my config is:

mqtt:
 sensor:
    - state_topic: "automower/mower/battery/charge"
      name: "mower_name Battery"
      device_class: battery
      unit_of_measurement: "%"

But the sensor value always gets presented as unknown. If I remove the unit of measurement I get no difference i.e. unknown. Do i need another value_template line to define the outcome?

Any tips?

Try this version. It removes the last two characters of the received payload (i.e. the “ %” in “100 %”).

mqtt:
 sensor:
    - state_topic: "automower/mower/battery/charge"
      name: "mower_name Battery"
      device_class: battery
      unit_of_measurement: "%"
      value_template: "{{ value[:-2] }}"

Be advised that it will report unknown until it receives a payload.

i removed the unit of measurement line because still unknown and now I get a value - 99 in this case. Which works for me. Thanks.