Percentage of two SNMP values

I’ve spent some time trying to figure out how to do this on my own and don’t think I can do it by myself.

I have two SMNP integers that I want to calculate into a percentage. I have found some examples on the forums but cannot get it to work.

- platform: snmp
  name: 'ESXi Total RAM'
  host: 192.168.1.201
  baseoid: 1.3.6.1.2.1.25.2.3.1.5.6
  community: !secret esxi_community
  accept_errors: true
  
- platform: snmp
  name: 'ESXi Used RAM'
  host: 192.168.1.201
  baseoid: 1.3.6.1.2.1.25.2.3.1.6.6
  community: !secret esxi_community
  accept_errors: true
  
- platform: template
  sensors:
  esxi_memory_used:
  friendly_name: "ESXi Memory Usage"
  unit_of_measurement: '%'
  value_template: '{{ states('sensor.esxi_used_ram') | float / states('sensor.esxi_total_ram') | float * 100) | round(2) }}'

Trying to divide both sensor outputs to get a percentage, what am I doing wrong?

The templates developer tab is your friend when working on these. In the left sidebar click on the icon that looks like a piece of paper with the corner folded down and the <> symbol in the middle.

file-xml

Erase all the content and then add your existing template. It will automatically return the result.

A quick look at this shows you are missing a ‘)’ You have one after ‘float*100’ but no pair for it.

Thank you for the quick reply.

I figured it out. For some reason I used a single quotation mark instead of a double, I thought they were interchangeable but apparently not.

I also had to put brackets around the divide equation, then round.

    - platform: template
      sensors:
      esxi_memory_used:
       friendly_name: "ESXi Memory Usage"
       unit_of_measurement: '%'
       value_template: "{{(states('sensor.esxi_used_ram') | float / states('sensor.esxi_total_ram') | float * 100) | round }}"