(Solved) SNMP Platform and unit of measurement

Hi All,

I can read my printer ink level. But HP have no % but max level is equal to 100%

platform: snmp
name: 'Printer Ink - Yellow'
baseoid: iso.
accept_errors: true
scan_interval: 86400

output is 15

full value is:
Black 674 (equal 100%)
cyan 240 (equal 100%)
yellow 226 (equal 100%)
magenta 241 (equal 100%)

how can I convert this into % instead of the value.

I know its value/674*100 = percent

but how do I get this in my HA?

Are those four ink levels state attributes of the printer entity? If so, you could create a template sensor to display this information in the UI.

And in the value_template the calculation?

Exactly. One sensor for each ink color.

:smiley: done… can you maybe help me with last part. How to keep the percent only with 2 decimals before ,

platform: template
    friendly_name: 'HP Magenta Ink Level'
    unit_of_measurement: '%'
    value_template: "{{ states('sensor.printer_ink_magenta')|float / 226 * 100 }}"

Output is something like: 42.274643837 %

Sure thing! Try this:

"{{ (states('sensor.printer_ink_magenta')|float / 226 * 100) | round(2) }}"

1 Like

great I saw this already in scripts I checked for some things. Now I know what it do! Thanks

“{{ (states(‘sensor.printer_ink_black’)|float / 674 * 100) | round(0) }}”

this was the correct line :slight_smile: