openHAB and HP printer
Recent openHAB versions come with a new HP Printer Binding, which is a big improvement over the more general IPP Binding for printers.
The new binding reads the data from two files which are provided by the printer:
- http://<printer>/DevMgmt/ProductUsageDyn.xml
- http://<printer>/DevMgmt/ProductStatusDyn.xml
Let's install that ...
First the binding must be installed, I use an Ansible Playbook which can do that for me:
- name: Get list of available and installed extensions
uri:
url: "http://{{ ansible_host }}:8080/rest/extensions"
register: oh2_extensions
changed_when: false
- name: Install extensions
uri:
url: "http://{{ ansible_host }}:8080/rest/extensions/{{ item }}/install"
method: POST
when: "not (oh2_extensions.json|byattr('id', item))[0].installed"
with_items:
- binding-hpprinter
register: oh2_install_extensions
$ansible_host holds my IP address for the Raspberry Pi running the openHAB system. The two Tasks first fetch existing and installed extensions, and then install any missing extension from the list (here it's only one extension for this case).
After that's done, one can either use the Paper UI to configure the binding - or deploy Things and Items again using Ansible. Which has the advantage that I can reinstall the entire system at any time.
First things first, the "printers.things" file:
Thing hpprinter:printer:laserjet_pro "HP Color LaserJet" @ "Office" [ ipAddress="<ip>", usageInterval="30", statusInterval="4" ]
"laserjet_pro" can be changed to any name, the only requirement is that the same name must be used for the Items later on. And replace "<ip>" with the IP-address of the printer.
Then the "printers.items" file:
String HPLJStatus "Status" { channel="pprinter:printer:laserjet_pro:status#status" }
Switch HPLJTrayOpen "Tray Open" { channel="pprinter:printer:laserjet_pro:status#trayEmptyOrOpen" }
Switch HPLJScannerStatus "Scanner Status" { channel="pprinter:printer:laserjet_pro:status#scannerStatus" }
Switch HPLJADFLoaded "ADF Loaded" { channel="pprinter:printer:laserjet_pro:status#scannerAdfLoaded" }
Number:Dimensionless HPLJBlackLevel "Black Level" { channel="hpprinter:printer:laserjet_pro:ink#blackLevel" }
Number:Dimensionless HPLJColorLevel "Color Level" { channel="hpprinter:printer:laserjet_pro:ink#colorLevel" }
Number:Dimensionless HPLJCyanLevel "Cyan Level" { channel="hpprinter:printer:laserjet_pro:ink#cyanLevel" }
Number:Dimensionless HPLJMagentaLevel "Magenta Level" { channel="hpprinter:printer:laserjet_pro:ink#magentaLevel" }
Number:Dimensionless HPLJYellowLevel "Yellow Level" { channel="hpprinter:printer:laserjet_pro:ink#yellowLevel" }
Number HPLJTotalPages "Total Pages" { channel="hpprinter:printer:laserjet_pro:usage#totalCount" }
...
The documentation for the Binding lists a number of additional channels, but not every of them will work for every printer.
The channel name must include the same name chosen for the Thing in printers.things. After sending everything to the openHAB installation, the event.log will show that the available channels come online and can be used.
Comments
Display comments as Linear | Threaded