Custom Component - HP Printer

HP Printer integration for Home Assistant


Configuration support multiple HP Printer devices through Configuration -> Integrations


How to set it up:

Look for “HP Printers Integration” and install


  • HP Printer supporting XML API

Basic configuration

  • Configuration should be done via Configuration -> Integrations.
  • In case you are already using that integration with YAML Configuration - please remove it
  • Integration supports multiple devices
  • In the setup form, the following details are mandatory:
    • Name - Unique
    • Host (or IP)
  • Upon submitting the form of creating an integration, a request to the printer will take place and will cause failure in case:
    • Unsupported API
    • Invalid server details - when cannot reach host

Settings for Monitoring interfaces, devices, tracked devices and update interval

Configuration -> Integrations -> {Integration} -> Options

Update Interval: Textbox, number of seconds to update entities, default=60
Log level: Drop-down list, change component's log level (more details below), default=Default
Should store responses?: Check-box, saves XML and JSON files for debuging purpose, default=False
Log Level’s drop-down

New feature to set the log level for the component without need to set log_level in customization: and restart or call manually logger.set_level and loose it after restart.

Upon startup or integration’s option update, based on the value chosen, the component will make a service call to logger.set_level for that component with the desired value,

In case Default option is chosen, flow will skip calling the service, after changing from any other option to Default, it will not take place automatically, only after restart

Store responses

Stores the XML and JSON of each request and final JSON to files, Path in CONFIG_PATH/*,
Files that will be generated (Prefix to the file is name of the integration):

  • ProductUsageDyn.XML - Raw XML from HP Printer of Usage Details
  • ProductUsageDyn.json - JSON based on the Raw XML of Usage Details after transformed by the component
  • ConsumableConfigDyn.XML - Raw XML from HP Printer of consumable details
  • ConsumableConfigDyn.json - JSON based on the Raw XML of consumable details after transformed by the component
  • ProductConfigDyn.XML - Raw XML from HP Printer of Config Details
  • ProductConfigDyn.json - JSON based on the Raw XML of Config Details after transformed by the component
  • Final.json - JSON based on the 2 JSONs above, merged into simpler data structure for the HA to create sensor based on


Device status - Binary Sensor

State: connected?

Printer details - Sensor

State: # of pages printed
    Color - # of printed documents using color cartridges
    Monochrome - # of printed documents using black cartridges
    Jams - # of print jobs jammed
    Cancelled - # of print jobs that were cancelled

Scanner details - Sensor (For AIO only)

State: # of pages scanned
    ADF - # of scanned documents from the ADF
    Duplex - # of scanned documents from the ADF using duplex mode
    Flatbed - # of scanned documents from the flatbed
    Jams - # of scanned jammed
    Mispick - # of scanned documents failed to take the document from the feeder

Cartridges details - Sensor (Per cartridge)

State: Remaining level %
    Type - Ink / Toner / Print head
    Station - Position of the cartridge
    Product Number
    Serial Number
    Manufactured By
    Manufactured At
    Warranty Expiration Date
    Installed At

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

1 Like

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

1 Like

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" }