Custom Component - HP Printer

Hi all,

I created an intergration to HP Printer,
Component is calling printers API to extract data,
In the initail version, it creates 2 type of sensors:

  • Printer - state is number of printed pages, attributes describes the number of pages printed as color / monochrome, jam events and cancelled job
  • Per ink head - state is remaining level of ink left, attributes describes the color, head type, station

I’m planning to add more sensor in the near future - scanner, copy, app usage.


   host: hostname
   name: printer name #Optional

Issues resolving:
Since I could check it with all models and the prasing the XML is being done dynamically,
In case there is an issue, please post the XML from:

you can add it to HACS by adding repository elad-bar/ha-hpprinter or get it directly from GitHub:

I’m using HP7740 at home and tested with it.



Added the scanner sensor:
State - # of pages scanned
attributes: ADF usage, ADF Duplex usage, Flatbed, Jams and mispick

Works great, thanks! Using this instead of the CUPS integration which I couldn’t get working with my printer for some reason. Using an HP Photosmart D110.

error when trying it.
i have laser printer hp 277

Error doing job: Future exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.7/concurrent/futures/", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/hpprinter/", line 29, in refresh_data self.update() File "/config/custom_components/hpprinter/", line 63, in update self.create_printer_sensor(printer_data) File "/config/custom_components/hpprinter/", line 84, in create_printer_sensor total_printed_pages = total_printed.get("#text", 0) AttributeError: 'str' object has no attribute 'get'

hi, thnx fot this

are you also using this code for your component? does it also sypport the tricolor cartridge?

No - was just parsing the XML files with a simple Python script. This looks a lot more interesting! :slight_smile:

How does this code works then? How is able to retrieve ink if it’s not based on snmp or xml ?

Just interested

I’ve just installed it and it looks/works well. Works with my 3830.

Looks like it’s doing the same thing, pulling from the XML files exposed.

The component is agnostic for colors, it runs over the entire XML dynamically, convert to json and from that point it just mapping the json to what we would like to present.

Over GitHub I received an example of XML for laser printer, I will adjust the mapping and will release an update (hopefully) later today

New release with fix available in GitHub, it was much simpler

i now have one sensor with:
Color: 668
Monochrome: 299
Jams: 0
Cancelled: 0
unit_of_measurement: pages
friendly_name: HP Printer Printer

ccan i see status for each tuner?

You should have per toner an additional sensor, please look for sensor.hp_printer_ (if you set the name to something else, replace the hp_printer with that name (slugified)

i only have sensor.hp_printer_printer

I’ll give a little feedback doing a quick try…

  • xmltodict is not installed in my environment so got an error. From my understanding, this is a requirement that should be listed in the manifest. So I added
    "requirements": ["xmltodict==0.4"]
    Once I removed this component from the config, and then readded it, HA must have picked up the requirement and installed xmltodict as I no longer get an error.

  • multicastDNS doesn’t seem to work. On a Chrome http://hp8285b4-envy.local works. But specifying host: hp8285b4-envy.local (with or without quotes) doesn’t work. Not a big issue, as using an IP address works fine.

  • For my HP Envy, I get the following log error:
    Failed to extract from array PECounter of [OrderedDict([('@PEID', '5000'), ('#text', '984')]), OrderedDict([('@PEID', '5088'), ('#text', '52')]), OrderedDict([('@PEID', '5033'), ('#text', '0')]), '0', OrderedDict([('@PEID', '5031'), ('#text', '43')]), OrderedDict([('@PEID', '5032'), ('#text', '0')]), OrderedDict([('@PEID', '5037'), ('#text', '944')]), OrderedDict([('@PEID', '5011'), ('#text', '0')]), OrderedDict([('@PEID', '3001'), ('#text', '22')])], Error: string indices must be integers, Line: 121
    Not positive, but seems only to affect ‘station’ as it shows “unknown”, everything else seems OK

Nice work, Thank you for sharing this.
It is working good for me after the update today.

This is awesome… I just a few days ago wasted my time making snmp sensors for all this… :roll_eyes:. Any chance you can add the drum life? (Or does it come up?) I have the OID for it but not sure how it’s listed in the XML…

Forgot to add the dependency… will add,
As for the PECounter, can you please upload an example of your XML so I’ll be able to fix and test it?



Planning to collect data from other endpoints such as end of life / serial number and other details, but first I would like to stabilize it to support all HP printers.

By the way, integration and parsing 3 endpoints already available in the code, there is that access them, so anyone who would like to promote it feel free to assist.

Are you using / docker with network not host? if yes, it cannot get to that host, you can try it using SSH to the HA machine and from there try to ping that host.


Once you will send the file, I’ll be able to fix it

Thanks for this, works great for HP Photosmart 8110, was using SNMP sensors

Couple of errors in the attributes, probably don’t exist on my printer:


Color { "@PEID": "NULL", "#text": "0" }
Monochrome { "@PEID": "NULL", "#text": "0" }
Jams 0
Cancelled 197

Duplex 0
Flatbed 509
Jams { "@PEID": "NULL", "#text": "0" }
Mispick { "@PEID": "NULL", "#text": "0" }