HP Printer Ink Levels

I got inspired by this tweet but it seems scraping from the webpage is not possible for HP printers. I created this small script which I run with cron on another Raspberry Pi to get my printer ink levels using cups and hplip.

3 Likes

Great post and set this up in a Debian docker but having issues getting hplip to find the relevant PPD for my printer (HP Envy 4520).

Do you have any advice for PPD files?

Not sure, if I recall correctly I did not come in touch with these files. Maybe you can receive that file through the CUPS server of your printer?

1 Like

I fixed it. Although I installed CUPS I didn’t start the service so it hplip couldn’t communicate with it.

Might be worth adding to the instructions to start both CUPS and CRON :slight_smile:

Would you mind to share your docker file?
I would like to reuse it in my unRaid docker setup

1 Like

As it took a while for to work out what I was doing wrong based on @thibmaek ‘s instructions it’s in a bit of a mess. I’ll hopefully be able to clean things up and share at some point. I have it running on a Synology 918+

1 Like

Aha, this was not necessary for my model since I never had to do this.
Could you tell me how to activate them so I can update the README, or feel free to make a PR!

I’d be happy to do a write up from a docker point of view in the future but once all the dependancies are installed I used service cups start and service cron start at the command line to bring them up. I’ve yet to set this up to start at boot however so currently you’ll need to do this if restarting the docker container.

Once CUPS was up I could the run hp-setup -i xxxxxxx to successfully setup the printer. Hope this helps.

Looking at your code and the output from hp-info there seems to be a wealth of information that can be harvested from a printer (software version, paper etc) would be interesting to add all this information as an array that can be pulled out as aributes within HA, thoughts?

Yeah, sounds like a good idea. I’d have to check what extra info could be processed next weekend.

1 Like

Indeed there is a lot of info with hp-info tool. Im using this for some time now and use a cron to extract the ink levels and write them to a file. Then use a sensor to read the contents of the txt file.

Did note this on ky github wiki some time ago.

1 Like

Did you manage to take a look at this? if not I may make a pull request and take a look.

Feel free to, I’ll take a look.
Just checked the complete hp-info output but didn’t find anything worth collecting for my setup.

I am running HassIO 0.92.2 on Rpi3B. Am not really very well versed in CLI to be able to follow this guide.

I have an HP deskjet 5500 series, for which I would like to have a sensor card to show ink levels.

Is there some guidance for a newbie like myself to be able to install the script/addons from the OP to HassIO without causing any breakage of the current setup.

Thanks for your replies.

Hi thibmaek,

I set up everithing and I can execute get-hp-ink-levels.sh succesfully. My Mosquito Broker inside HA gets the messages.
But the problem is that MQTT integration doesn’t get the sensors.
Do you have any idea?
Declaring the platform mqtt as a sensor is not an option anymore with HA 0.92, so I don’t understand how to get this sensors.

Thank for any help

Hmm not sure. Haven’t really used these sensor that much lately.
Normally if the broker is receiving published topics correctly, setting an MQTT sensor should suffice.

I didn’t manage to get this to work.

Not sure if this will work for your printer but this works on my HP Photosmart.

Thanks to @123 for steering me in the right direction.

I used snmpwalk to find all the iods for my printer

snmpwalk -v 1 -c public 192.168.1.xx

There’s lots more info available this way, IP, MAC Host name etc but I just use these:

    - platform: snmp
      name: 'Printer Pages'
      host: 192.168.1.xx
      baseoid: 1.3.6.1.2.1.43.10.2.1.4.1.1
      accept_errors: true
      scan_interval: 3600

    - platform: snmp
      name: 'Printer Ink - Black'
      host: 192.168.1.xx
      baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.1
      accept_errors: true
      scan_interval: 86400
      unit_of_measurement: '%'

    - platform: snmp
      name: 'Printer Ink - Yellow'
      host: 192.168.1.xx
      baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.2
      accept_errors: true
      scan_interval: 86400
      unit_of_measurement: '%'

    - platform: snmp
      name: 'Printer Ink - Cyan'
      host: 192.168.1.xx
      baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.3
      accept_errors: true
      scan_interval: 86400
      unit_of_measurement: '%'

    - platform: snmp
      name: 'Printer Ink - Magenta'
      host: 192.168.1.xx
      baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.4
      accept_errors: true
      scan_interval: 86400
      unit_of_measurement: '%'
3 Likes

Can someone tel me if this is possible with the Canon TS5050 too I’ll try and try but I can’t get it work.
I use Hassio on a Rpi3 I run snmpwalk -v 1 -c public 192.168.1.xx
and see a lot but what shout I use for ink levels? all I get = integer -2 on all my ink levels when i use the baseoid’s from the example like beneath

    - platform: snmp
      name: 'Printer Ink - Magenta'
      host: 192.168.1.xx
      baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.4

Any help is welcome

Can you post the output from snmpwalk ?

iso.3.6.1.2.1.1.1.0 = Hex-STRING: 43 61 6E 6F 6E 20 54 53 35 30 30 30 20 73 65 72 
69 65 73 20 2F 50 00 
iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.1602.4.7
iso.3.6.1.2.1.1.3.0 = Timeticks: (187809000) 21 days, 17:41:30.00
iso.3.6.1.2.1.1.4.0 = ""
iso.3.6.1.2.1.1.5.0 = STRING: "TS5000 series"
iso.3.6.1.2.1.1.6.0 = ""
iso.3.6.1.2.1.2.2.1.6.1 = Hex-STRING: 9C 32 CE 8A C9 D5 
iso.3.6.1.2.1.4.21.1.7.0.0.0.0 = IpAddress: 192.168.1.1
iso.3.6.1.2.1.25.2.2.0 = INTEGER: 0
iso.3.6.1.2.1.25.3.2.1.2.1 = OID: iso.3.6.1.2.1.25.3.1.5
iso.3.6.1.2.1.25.3.2.1.3.1 = Hex-STRING: 43 61 6E 6F 6E 20 54 53 35 30 30 30 20 73 65 72 
69 65 73 20 31 2E 31 36 30 00 
iso.3.6.1.2.1.25.3.2.1.5.1 = INTEGER: 2
iso.3.6.1.2.1.25.3.5.1.1.1 = INTEGER: 3
iso.3.6.1.2.1.25.3.5.1.2.1 = Hex-STRING: 00 
iso.3.6.1.2.1.43.5.1.1.1.1 = Counter32: 0
iso.3.6.1.2.1.43.5.1.1.2.1 = INTEGER: 1
iso.3.6.1.2.1.43.5.1.1.3.1 = INTEGER: 3
iso.3.6.1.2.1.43.5.1.1.4.1 = ""
iso.3.6.1.2.1.43.5.1.1.5.1 = ""
iso.3.6.1.2.1.43.5.1.1.10.1 = INTEGER: 2
iso.3.6.1.2.1.43.5.1.1.11.1 = INTEGER: 0
iso.3.6.1.2.1.43.5.1.1.12.1 = INTEGER: 0
iso.3.6.1.2.1.43.5.1.1.13.1 = INTEGER: 3
iso.3.6.1.2.1.43.7.1.1.3.1.1 = STRING: "  "
iso.3.6.1.2.1.43.7.1.1.4.1.1 = INTEGER: 106
iso.3.6.1.2.1.43.8.2.1.2.1.1 = INTEGER: 4
iso.3.6.1.2.1.43.8.2.1.3.1.1 = INTEGER: 4
iso.3.6.1.2.1.43.8.2.1.4.1.1 = INTEGER: 210000
iso.3.6.1.2.1.43.8.2.1.5.1.1 = INTEGER: 297000
iso.3.6.1.2.1.43.8.2.1.6.1.1 = INTEGER: 210000
iso.3.6.1.2.1.43.8.2.1.7.1.1 = INTEGER: 297000
iso.3.6.1.2.1.43.8.2.1.8.1.1 = INTEGER: 8
iso.3.6.1.2.1.43.8.2.1.9.1.1 = INTEGER: 100
iso.3.6.1.2.1.43.8.2.1.10.1.1 = INTEGER: -3
iso.3.6.1.2.1.43.8.2.1.11.1.1 = INTEGER: 0
iso.3.6.1.2.1.43.8.2.1.12.1.1 = STRING: "MediaName"
iso.3.6.1.2.1.43.8.2.1.13.1.1 = STRING: "Drawer 1"
iso.3.6.1.2.1.43.8.2.1.14.1.1 = STRING: "Canon"
iso.3.6.1.2.1.43.8.2.1.15.1.1 = ""
iso.3.6.1.2.1.43.8.2.1.16.1.1 = ""
iso.3.6.1.2.1.43.8.2.1.17.1.1 = ""
iso.3.6.1.2.1.43.8.2.1.18.1.1 = ""
iso.3.6.1.2.1.43.8.2.1.21.1.1 = ""
iso.3.6.1.2.1.43.9.2.1.3.1.1 = INTEGER: 8
iso.3.6.1.2.1.43.9.2.1.4.1.1 = INTEGER: 50
iso.3.6.1.2.1.43.9.2.1.5.1.1 = INTEGER: -2
iso.3.6.1.2.1.43.9.2.1.7.1.1 = STRING: "Tray"
iso.3.6.1.2.1.43.10.2.1.3.1.1 = INTEGER: 7
iso.3.6.1.2.1.43.10.2.1.4.1.1 = Counter32: 0
iso.3.6.1.2.1.43.10.2.1.5.1.1 = Counter32: 0
iso.3.6.1.2.1.43.11.1.1.2.1.1 = INTEGER: 1
iso.3.6.1.2.1.43.11.1.1.2.1.2 = INTEGER: 1
iso.3.6.1.2.1.43.11.1.1.2.1.3 = INTEGER: 1
iso.3.6.1.2.1.43.11.1.1.2.1.4 = INTEGER: 1
iso.3.6.1.2.1.43.11.1.1.2.1.5 = INTEGER: 1
iso.3.6.1.2.1.43.11.1.1.3.1.1 = INTEGER: 1
iso.3.6.1.2.1.43.11.1.1.3.1.2 = INTEGER: 2
iso.3.6.1.2.1.43.11.1.1.3.1.3 = INTEGER: 3
iso.3.6.1.2.1.43.11.1.1.3.1.4 = INTEGER: 4
iso.3.6.1.2.1.43.11.1.1.3.1.5 = INTEGER: 5
iso.3.6.1.2.1.43.11.1.1.4.1.1 = INTEGER: 3
iso.3.6.1.2.1.43.11.1.1.4.1.2 = INTEGER: 3
iso.3.6.1.2.1.43.11.1.1.4.1.3 = INTEGER: 3
iso.3.6.1.2.1.43.11.1.1.4.1.4 = INTEGER: 3
iso.3.6.1.2.1.43.11.1.1.4.1.5 = INTEGER: 3
iso.3.6.1.2.1.43.11.1.1.5.1.1 = INTEGER: 6
iso.3.6.1.2.1.43.11.1.1.5.1.2 = INTEGER: 6
iso.3.6.1.2.1.43.11.1.1.5.1.3 = INTEGER: 6
iso.3.6.1.2.1.43.11.1.1.5.1.4 = INTEGER: 6
iso.3.6.1.2.1.43.11.1.1.5.1.5 = INTEGER: 6
iso.3.6.1.2.1.43.11.1.1.6.1.1 = STRING: "Canon Black Ink Tank"
iso.3.6.1.2.1.43.11.1.1.6.1.2 = STRING: "Canon Cyan Ink Tank"
iso.3.6.1.2.1.43.11.1.1.6.1.3 = STRING: "Canon Magenta Ink Tank"
iso.3.6.1.2.1.43.11.1.1.6.1.4 = STRING: "Canon Yellow Ink Tank"
iso.3.6.1.2.1.43.11.1.1.6.1.5 = STRING: "Canon Pgbk Ink Tank"
iso.3.6.1.2.1.43.11.1.1.7.1.1 = INTEGER: 19
iso.3.6.1.2.1.43.11.1.1.7.1.2 = INTEGER: 19
iso.3.6.1.2.1.43.11.1.1.7.1.3 = INTEGER: 19
iso.3.6.1.2.1.43.11.1.1.7.1.4 = INTEGER: 19
iso.3.6.1.2.1.43.11.1.1.7.1.5 = INTEGER: 19
iso.3.6.1.2.1.43.11.1.1.8.1.1 = INTEGER: 100
iso.3.6.1.2.1.43.11.1.1.8.1.2 = INTEGER: 100
iso.3.6.1.2.1.43.11.1.1.8.1.3 = INTEGER: 100
iso.3.6.1.2.1.43.11.1.1.8.1.4 = INTEGER: 100
iso.3.6.1.2.1.43.11.1.1.8.1.5 = INTEGER: 100
iso.3.6.1.2.1.43.11.1.1.9.1.1 = INTEGER: -2
iso.3.6.1.2.1.43.11.1.1.9.1.2 = INTEGER: -2
iso.3.6.1.2.1.43.11.1.1.9.1.3 = INTEGER: -2
iso.3.6.1.2.1.43.11.1.1.9.1.4 = INTEGER: -2
iso.3.6.1.2.1.43.11.1.1.9.1.5 = INTEGER: -2
iso.3.6.1.2.1.43.12.1.1.2.1.1 = INTEGER: 1
iso.3.6.1.2.1.43.12.1.1.2.1.2 = INTEGER: 1
iso.3.6.1.2.1.43.12.1.1.2.1.3 = INTEGER: 1
iso.3.6.1.2.1.43.12.1.1.2.1.4 = INTEGER: 1
iso.3.6.1.2.1.43.12.1.1.2.1.5 = INTEGER: 1
iso.3.6.1.2.1.43.12.1.1.4.1.1 = STRING: "black"
iso.3.6.1.2.1.43.12.1.1.4.1.2 = STRING: "cyan"
iso.3.6.1.2.1.43.12.1.1.4.1.3 = STRING: "magenta"
iso.3.6.1.2.1.43.12.1.1.4.1.4 = STRING: "yellow"
iso.3.6.1.2.1.43.12.1.1.4.1.5 = STRING: "pgbk"
iso.3.6.1.2.1.43.13.4.1.2.1.1 = INTEGER: 8
iso.3.6.1.2.1.43.13.4.1.4.1.1 = INTEGER: -1
iso.3.6.1.2.1.43.13.4.1.9.1.1 = INTEGER: 5
iso.3.6.1.2.1.43.13.4.1.10.1.1 = STRING: "SIMPLEX ASF"
iso.3.6.1.2.1.43.15.1.1.2.1.1 = INTEGER: 1
iso.3.6.1.2.1.43.15.1.1.3.1.1 = ""
iso.3.6.1.2.1.43.15.1.1.5.1.1 = ""
iso.3.6.1.2.1.43.16.5.1.2.1.1 = ""
iso.3.6.1.2.1.43.17.6.1.2.1.1 = INTEGER: 1000
iso.3.6.1.2.1.43.17.6.1.3.1.1 = INTEGER: 0
iso.3.6.1.2.1.43.17.6.1.5.1.1 = STRING: "power"
iso.3.6.1.2.1.43.18.1.1.2.1.8 = INTEGER: 4