SNMP protocol from printer

Hello
I’m trying to retrieve information from a printer through the SNMP protocol and has got the values that intended.
A printer returns the levels of consumables in two parts, the total (counted in units, eg 2000) and the rest (counted in units, eg 940)
What I needed now was that I present the current value in percentage, like 2000/940 * 100 to give me 47%.
How can I make this conversion for an item show me the value in habpanel?
Thanks

Retrieve both values and use a rule (triggered by changing either of the values) to calculate the desired value. Then postUpdate the calculated value to an item.

Thanks for the information.
Did you happen to be able to share the rule for doing the operation?
I know it has to be with a rule, I don’t know how to create it.

appreciate your attention

hi,
assuming you are running oh2.x this could be an example:

rule "calculatePercentage"

when
item totalItem changed
item restItem changed
then

var totalval = (totalItem.state as DecimalType).intValue
var restval = (restItem.state as DecimalType).intValue

if (totalval > 0) {
	postUpdate(percentageItem, restval*100/totalval)
}
else
	postUpdate(percentageItem, 0)

end

where
totalItem is the item from which you get the totals
restItem is the item from which you get the rest
percentageItem is the calculated percentage.

hope this helps.
Roberto

2 Likes

Thanks for listening.
Unfortunately, I am using openhab 3.
I tried to put the rule but it didn’t work. But I also don’t know what could be wrong.

That should work with OH3 in the same way. What happens? Can you provide logs?