Issue with SNMP sensor converting response value

I want to track througput of my VP connection on Draytek router using SNMP. There is VPN specific OID available on the router and when using MIB Browser I can read proper response:

Name/OID: .1.3.6.1.4.1.7367.2.1.5.1; Value (IpAddress): 37.120.156.36

Unfortunatelly SNMP sensor does some conversion of IP to string containing strange characters

Here is the code for this sensor:

  - platform: snmp
    name: snmp_VPN_IP
    host: 192.168.52.1
    baseoid: 1.3.6.1.4.1.7367.2.1.5.1
    scan_interval: 10
    # below lines added in desperate attempt to keep response as a string, but did not helped
    value_template: >
      {{ value | string }}

Is it bug or am I doing something wrong?

What is a true example value in the mib browser?

As posted above - real IP of VPN interface… Here is the screenshot from MIB Browser:

It is not a but, but how SNMP present values.
37.120.156.36in your example can also be written as the integer 628661284.

How does the output look without the string conversion?

Which output? SNMP from router is exactly IP, as MIB browser presents. What is the format of this output when it send from router to HA I do not know, but HA sensor state is already converted to string… I checked ASCII codes (decimal) corresponding to IP address sections and this gives exactly 5 characters that HA presents as sensor state: 37 - %, 120 - x, 156 - œ, 36 - $. So HA takes each number from the strig and converts it to ASCII, omitting dots as these are apparently treated as separators.
Yet data containing alphanumerical characters (digits and dots) I’d expect to be treated literaly as string, not string with strange encoding.
Anyhow is there any way to get this properly represented as IP address in sensor state?

Solved by proper templating of SNMP output. here is working sensor code:

  - platform: snmp
    name: snmp_VPN_IP
    host: 192.168.52.1
    baseoid: 1.3.6.1.4.1.7367.2.1.5.1
    scan_interval: 10
    value_template: >
      {% set x = value %}
      {% set x = x[0] | ord | string + '.' +  x[1] | ord | string + '.' + x[2] | ord | string + '.' + x[3] | ord | string %}
      {{ x }}

And now I get proper IP as state:

Good work.
SNMP can be a bit tricky to work with in that way, but it works with an incredible mount of different devices, where other methods are lacking.