How to divide by 100 a MQTT value?

Hi guys,

I get a Temperature from my Arduino via MQTT.
The temperature is with 2 digits. So before sending it, I multiply the float value by 100.
Then I get the proper value in HA (something like 2203) when I check in the developper tool tab.
But on the lovelace interface I have 2.203 and I can’t do anything from the interface.

I’ve tried to find out how to make a calculation using templates, but I think I don’t know good enough HA to understand where to search the suitable solution.

The entity is called “sensor.1wire_03” and my sensors.yaml look like that:

  - platform: mqtt
    name: "1Wire_03"
    state_topic: "home-assistant/sensor01/1Wire_03"
    unit_of_measurement: "°C"
    value_template: '{{ value | round(2) }}'
    #state: '{{ (states("sensor.1wire_03") | float / 100) | round(2) }}'

If you could help, it would be really appreciated :slight_smile:
Thanks in advance.
David

Try

value_template: {{ ((states('sensor.1wire_03')|float)/100)|round(2) }}
 - platform: mqtt
    name: "1Wire_03"
    state_topic: 'home-assistant/sensor01'
    value_template: "{{ value_json.1Wire_03 | float/100 |round(2) }}"

I think you might need to adjust whole mqtt

Hi mate,

I got it doing this :+1::

  - platform: mqtt
    name: "1Wire_10"
    state_topic: "home-assistant/sensor01/1Wire_10"
    unit_of_measurement: "°C"
    value_template: "{{ value | multiply(0.01) | round(2) }}" 
1 Like

Good. There’s nothing as satisfying as working it out yourself. :+1: