Custom Component - HP Printer

Hi all,

Additional features available in latest version,
Updated version has breaking changes.

New features:

  • Support for multiple devices
  • Support printhead and not just toner / ink cartridges
  • More information on each of the cartridge’s sensors
    • Product Number
    • Serial Number
    • Manufactured By
    • Manufactured At
    • Warranty Expiration Date
    • Installed At
  • Store debug files service - Stores the XML and JSON of each request and final JSON to files, Path in CONFIG_PATH/*

Configuration changes:

Instead of:

hpprinter:
   host: hostname / IP
   name: printer name (Optional - Default - HP Printer)

Use:

hpprinter:
    devices:
        - host: hostname / IP
          name: printer name (Optional - Default - HP Printer)

All the information available in the README file,
Feel free to share feedbacks.

In case you encountered an issue, please try to provide the data from the store debug file service.

1 Like

Works great! just use devices instead of “devies” or the integration will fail.

Just gave it a try.
Seems my second printer, HP Photosmart C4700 series, doesn’t support the DevMgmt/ProductUsageDyn.xml (get a 404) even though it has a web server.
Oh well :frowning: Thanks for your work on this anyway!

Thanks! corrected the readme

C4700 is working with HP PrintOS which is another API

Is that a cloud only API?

Don’t know exactly, but in HP developer community there’s java integraion that need to reverse engineer it,
It works with authentication and access token and from that point you can access the information,
Since I don’t have that printer I cannot try doing that…

With the new version I am getting this error:

Failed to set printer consumable data (HP LaserJet M175nw @192.168.1.2), Error: 'OPC', Line: 220

Everything does seem to be working though…

found the potential cause for that error,
the error caused by unmapped color acronym into colors which is being represented differently in the 2 endpoints the component collects the information from the printer (one is working with acronym while the other with full name),
In the previous version I added just the mappings I were familiar with and didn’t protect the code too much when unknown color is being processed.

the “fix” I applied was to handle it better and log with warnning message if there is unmapped color,
I guess you will see a warnning message know, if you do, please post the warnning message and I will map that color as well.
On top of the color, I added the head type to the message, the reason - OPC (Organic Photo Conductor) maybe falls on another head type and needed to be treated diffrently than ink / toner.

Message will look like:
Head type {head_type} color mapping for {consumable_label_code} not available

Current color mapping:

HP_INK_MAPPING = {
    "C": "Cyan",
    "Y": "Yellow",
    "M": "Magenta",
    "K": "Black",
    "CMY": "CyanMagentaYellow"
}

I have this in my Log when Printer is Off.

Log Details (ERROR)
Mon Nov 18 2019 17:59:35 GMT+0100 (Mitteleuropäische Normalzeit)
Failed to update data (ProductUsageDyn) and parse it, Error: 'NoneType' object is not iterable, Line: 33

Added new binary sensor for device’s status,
In case the printer is not available, binary sensor will be off and will not try to throw the error

1 Like

I have been following this topic, but am confused.
Can someone explain the steps to install this and what yaml files and such go where.
Thank you
carltonb

Are you using HACS?

Yes using HACS. Looked at it but did not find the “plugin/integration” to use.
What is it called?
Thanks
carltonb

You have to add it manually in the settings tabs using the github URL and integration as type

1 Like

Thank you. I now understand.
carltonb

Got it up and working but am having some difficulty understanding how the following is used.

State: # of pages scanned
Attributes:
    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

Thanks
carltonb

that is the description of the sensor that being created, what the state and attributes represents,
Not sure I understand your question.

I still have the error in the log, despite updating the latest version

2019-11-27 19:23:07 ERROR (SyncWorker_5) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ProductUsageDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ProductUsageDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1ded0e1450>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70
2019-11-27 19:23:11 ERROR (SyncWorker_5) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ConsumableConfigDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ConsumableConfigDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1deb7e78d0>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70
2019-11-27 19:34:18 ERROR (SyncWorker_0) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ProductUsageDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ProductUsageDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1deb6eec50>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70
2019-11-27 19:34:21 ERROR (SyncWorker_0) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ConsumableConfigDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ConsumableConfigDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1deb7a5d10>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70
2019-11-27 20:34:19 ERROR (SyncWorker_0) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ProductUsageDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ProductUsageDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1deb04e1d0>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70
2019-11-27 20:34:22 ERROR (SyncWorker_0) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ConsumableConfigDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ConsumableConfigDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1dedef4890>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70
2019-11-27 20:44:59 ERROR (MainThread) [homeassistant.components.homeassistant] homeassistant/turn_on cannot be called without entity_id
2019-11-27 21:34:20 ERROR (SyncWorker_15) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ProductUsageDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ProductUsageDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1deafb5a90>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70
2019-11-27 21:34:23 ERROR (SyncWorker_15) [custom_components.hpprinter.HPPrinterData] Failed to retrieve data (ConsumableConfigDyn) from printer, Error: HTTPConnectionPool(host='192.168.1.121', port=80): Max retries exceeded with url: /DevMgmt/ConsumableConfigDyn.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1ded9d4990>: Failed to establish a new connection: [Errno 113] Host is unreachable')), Line: 70

when the Printer is offline

I never never seen the attributes listed like this, so I was unsure what to do with this code. Do I have to place it in a yaml file or is this part of the json files included in the HACS setup.

So if I wanted some output lets say for my ADF how would I complete the following in pa part of the line of code.

sensor.hp_8600_printer.attributes.ADF

Thanks
carltonb