How to put the printer supply level in some items

Hi folks,

I need your suggestion how to have some items where I can see the ink level of my supplies inside my Canon printer.

Idea is to create a Think with the command

ink -b bjnp://IP_of_your_printer

then create 6 items for each toner, adding the right additional args:

| awk ‘/Black:/ { print $NF }’
| awk ‘/Photoblack:/ { print $NF }’
| awk ‘/Yellow:/ { print $NF }’
| awk ‘/Magenta:/ { print $NF }’
| awk ‘/Cyan:/ { print $NF }’
| awk ‘/Photogrey:/ { print $NF }’

Is this the right approach in OH2?

I can try to figure out how to create the Thing:

Thing exec:command:printertonlev [command="/usr/bin/ink -b bjnp://IP_of_your_printer %2$s", interval=15, timeout=5]

But now? is it possible to add additional args without a rule, directly in the item definition?

thanks
Andrea

Another option is to create 6 Things, one for each toner.

But I would like to understand what is the best approach considering I’m now in OH2.

thanks :slight_smile:
Andrea

See the Input channel in the docs https://docs.openhab.org/addons/bindings/exec/readme.html#channels

%2$s will be replaced with the contents of the Item linked to the Input channel. Sending a command to the Item linked to the Input channel will cause the script to execute.

Why not use the SNMP binding?
See Monitor printer ink level with Openhab using SNMP

Works perfect for me

Because it seem my printer is not snmp enabled (no snmpwalk output, and no snmp configuration). Canon MG8150.

Creating the thing:

Thing exec:command:mg8150toner [command="/usr/bin/ink -b bjnp://192.168.10.3 %2$s", interval=15, timeout=5]

I see this error:

2018-03-30 02:17:37.223 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : ‘Format specifier ‘%2$s’’

maybe usual issue with openhab user permissions?

@rlkoshak any suggestion?

thanks
Andrea

In the meantime I’ve left exec binding for OH2 and I’ve used a simple rule:

(example for Black ink)

rule MG8150toner
when
Time cron “* 0/15 * * * ?” // this one cycles every 15 minutes.
then
val black = executeCommandLine(“sh /etc/openhab2/myscripts/CanonMG8150_SupplyLev_Black.sh”, 5000)
CanonMG8150_SupplyLev_Black.postUpdate(black)
end

and just one item (Number!!!)

Number CanonMG8150_SupplyLev_Black “Black Level [%d %%]” (gFF_Library, gMaintenance)

cheers
Andrea

Team,

how can say in the rule “if the printer is off, stop the rule”?

this will prevent some errors in my logs.

Any idea?

thanks
Andrea

You can use the CUPS binding (https://www.openhab.org/addons/bindings/cups1/) for that:

if (Printer.state==OFF) {