Custom Component for printer ink levels

I have created a custom component which checks ink levels using the ink command in linux. sudo apt-get install ink under debian-based distros.

Currently I have not created dedicated repo for custom components. You can get the code here: https://github.com/nalipaz/home-assistant-config/blob/master/custom_components/sensor/ink.py

Just drop that into yourconfigpath/custom_components/sensor/ink.py then add the needed config documented in the comments.

sensor:
  - platform: ink
    host: IP_ADDRESS
    scan_interval: 120
    resources:
     - not_present
     - black
     - color
     - photo
     - cyan
     - magenta
     - yellow
     - photoblack
     - photocyan
     - photomagenta
     - photoyellow
     - red
     - green
     - blue
     - light_black
     - light_cyan
     - light_magenta
     - light_light_black
     - matte_black
     - gloss_optimizer
     - unknown
     - light_cyan_light_magenta_photoblack
     - 2x_grey_and_black
     - black_cyan_magenta_yellow
     - photocyan_and_photomagenta
     - yellow_and_magenta
     - cyan_and_black
     - light_grey_and_photoblack
     - light_grey
     - medium_grey
     - photogrey
     - white

You really only want it to create sensors for the colors you have so after you add that you can remove the sensors that don’t provide any values.

7 Likes

Looks like not all printers are supported.

pi@hassbian:~ $ sudo ink -b bjnp://192.168.200.7

CRIT: udp_command: no data received (recv)CRIT: udp_command: no data received (recv)CRIT: udp_command: no data received (recv)Could not read from printer.
Could not get ink level.

Any idea how I may be able to get this to work, printer info is accessible from Remote UI in web browser after login.
image

I too had a similar issue when I first install ink. I restarted my pi and restarted the printer then I started getting values. However you might want to look into the supported devices for ink. If that doesn’t work you might be able to access some other way, but I wouldn’t be familiar.

Also, do realize there is by default a 120 second delay in obtaining colors. That is true upon startup of hass sometimes as well.

Been playing around with it for over an hour, so time isn’t an issue.

I tried setting up another printer which is reachable, but no info in HA.

 pi@hassbian:~ $ sudo ink -b bjnp://192.168.200.126

ink 0.5.2 © 2015 Markus Heinz

Canon MG3500 series

Black: 70%
Color: 0%

That info looks good. Curious why you aren’t getting sensors in hass. Can you show me the config for the working printer?

- platform: ink
  name: '2FL Canon MG3500'
  host: 192.168.200.126
  scan_interval: 120
  colors:
   - black
   - color

damn, bad documentation from myself. should be:

- platform: ink
  host: 192.168.200.126
  scan_interval: 120
  resources:
   - black
   - color

:+1::+1::+1: Works for the MG3500, but not for the MF8380Cdw.

Thanks.

Good to hear. For supported printers you can check out the list on libinklevel’s sourceforge page:
http://libinklevel.sourceforge.net/

Oh and looks like the developer of libinklevel does take information from users like you who might know how to retrieve info from a certain printer. Then he incorporates it, read through the aforementioned page for details on that.

Will do, Cheers!

@nalipaz can i use this on hass.io?

@Rodolfo_Vieira not without an addon to provide the ink command. I currently don’t use hass.io at my house, but it is possible I might be interested in doing an addon for this if I change to hass.io in the future. I do use hass.io for a rental property and have made one addon for that already. But as of right now, sorry no.

2 Likes

FYI: Reply from Developer.

“Libinklevel only supports ink jet printers.”

1 Like

I went using the drivers from HP for my HP printer. It gives a tonne of info besides ink for your HP printer via command line, so I just made command line sensors for the 4 different inks.

Obviously this only works with HP printers. Not sure if other manufactures do the same.

@cjsimmons you could fairly easily convert that to a custom component if you wanted. That is all my component does, converts command line output to a bunch of sensors.

That’s pretty much what I did. I have 4 sensors for each ink cartridge, and 1 for the printer status.

placed ink.py in custom_components\sensors, but getting error:
Unable to find component sensor.ink

EDIT: you made a typo:
“Just drop that into yourconfigpath/custom_components/sensors/ink.py” need to be “sensor/ink.py”

@Martinvdm thanks for finding the issue and glad you figured it out. Corrected the initial post