Valve_template to insert missing decimal

Hi,
I have an SNMP sensor that provides a voltage reading with four digits and no decimal. Example, the value passed is 1270, but it really should be 127.0. I search the internet and can’t figure out how to reformat or insert the decimal point using jinja. I found tons of info on adding and formatting for decimal values, but nothing about reformatting a number to insert a decimal. Can anyone please help?

Thanks, JBunch

Multiply by 0.1 or divide by 10 ?

1 Like

Paste this into the Template Editor and experiment with it:

{% set x = '1270' %}

a) {{x}}
b) {{ x | float }}
c) {{ (x | float) / 10 }}

I don’t know how you didn’t find any examples. There are many just in the snmp documentation

  - platform: snmp
    name: 'Printer uptime'
    host: 192.168.2.21
    baseoid: 1.3.6.1.2.1.1.3.0
    accept_errors: true
    unit_of_measurement: 'voltage'
    value_template: '{{ (value | int) / 10) }}'

Well, I feel dumb. I don’t know python/jinja and I was over thinking it. Thought I needed to do something fancy, so that’s what I was searching for. Thanks for the light all!