Custom Component for printer ink levels

How can I install ink within Home Assistant (non hassio)?

I run HA in a docker container on a Synology, I’ve connected to the container and ran the above command but ink is not found.

Any ideas?

EDIT: Managed to install the ink dependency but turns out my HP Envy isn’t supported :frowning:

My printer is not printing well. i think that it printer ink issue. It doesn’t prints black while i use black color ink. Other than this it also skips some letters or we can say that missing colors. I tried many methods to solve this issue but nothing happens. Should i have to visit canon printer offline for the suggestion.

I am trying to install Printer drivers for HP Printer, it gives Error 5 again and again. looking for more posts for resolving the same issue. Dell Printer Support

For HP Envy you can try the HPLIP, i’m using this and 2 command lines to get the inkt level and put then into a txt file. It runs like every 2 hours to update the txt file. Using a TXT file with the level to make sure there is a value after restarting without polling the printer 100 times a day, it is not that fast and gives time-out quickly. It is a quick and dirty solution but you could try:

sudo apt-get install hplip

Setup your printer: (IP of printer)

$ hp-setup -i 192.168.1.2

Run HP-info to see if it gives the ink levels

$ hp-info

Or use this to only get the ink level (change the agent to get both black / color / …

hp-info 2>&1 | grep -oP “(?<=agent1-level\s{18})(.*\S)” | tr “\n” ” “

1 Like

Many thanks for letting me know, I’ll give it a try.

Edit: could you not use the Command line Sensor to poll the data too? You can adjust the poll interval.

Having issue setting this up, managed to install the package but failing on hp-setup due to the following:

error: No PPD found for model envy_4520 using old algorithm.
error: Unable to find an appropriate PPD file.

Any ideas?

EDIT: Ok I found the locate of the PPD but its only listing compressed fax version:

/usr/share/ppd/hplip/HP/
HP-Fax-hpcups.ppd.gz  HP-Fax2-hpcups.ppd.gz  HP-Fax3-hpcups.ppd.gz  HP-Fax4-hpcups.ppd.gz

I decided to unpack one and adding it to the setup path but still no joy.

EDIT 2: Managed to location the correct PPD by downloading the hplip locally, extracting and then copying the correct PPD across to the docker using docker cp. Now getting the following error after running hp-info:

warning: No display found.
error: hp-info -u/--gui requires Qt4 GUI support. Entering interactive mode.
error: No device found that support this feature.

Exists a way to install your component in the HassOS?

i have a officejet 5740 which is support http://libinklevel.sourceforge.net/
whenever i run the command to test it im not getting back levels

ink -b bjnp://10.3.1.5
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.

I faced the same issue in the printer that is canon printer offline. Kindly give the resolution on it.

I have hassio in Docker on UbuntuServer and on ubuntu server I see printer.image But how to install that in hassio?

Thanks for this information, In case of renewal of geek squad protection plan contact us

How would i go about installing this in a docker image on unraid?

Thanks.

Inside the docker image i ran pip install ink
and that has installed the ink addon i think.

My printer is a HP Laserjet M451dn, and after waiting 15 minutes or so, I still have no levels.-

I have just seen above that only ink printers are supported, not laserjets. :sob:

Been using ink for some time.

I’ve already moved ink to its own directory as a result of 0.91, to /custom_components/ink . But, just updated to 0.92 and ink as a custom component is now broken.

Read the recent migration brief https://developers.home-assistant.io/blog/2019/04/12/new-integration-structure.html , is there anything I should do to make this work?

Solved!

Just add a manifest.json file with contents per the instructions provided below in your directory /custom_components/ink

2 Likes

I really liked the idea of your custom component, but as I use hassio I dont think it will work since ink needs to be installed in the homeassistant docker container.

So instead I took the approach to create a hassio addon that will run ink periodically, parse the output into JSON and sent it to HA via MQTT.

Its very much a hack job (esp the shell script that calls ink and mosquitto client for MQTT) but it works great for my Canon Pixma 5300, and supports HA MQTT autodiscovery - albeit in a very hard coded way :wink:

You can find it in my hassio addons repo:

To get other printers working you will probably need to edit the ink2mqtt.sh script.

Here is my lovelace card to show ink levels using the superb custom cards bar-card and vertical-stack-in-card:

image

type: 'custom:vertical-stack-in-card'
title: Canon MG5300 Printer Ink
cards:
  - type: 'custom:bar-card'
    columns: 5
    direction: up
    entities:
      - color: MediumTurquoise
        entity: sensor.canon_mg5300_cyan_ink_level
      - color: MediumOrchid
        entity: sensor.canon_mg5300_magenta_ink_level
      - color: Gold
        entity: sensor.canon_mg5300_yellow_ink_level
      - color: Black
        entity: sensor.canon_mg5300_black_ink_level
      - color: Black
        entity: sensor.canon_mg5300_photoblack_ink_level
    height: 200px
    max: 100
    min: 0
    padding: 2px
    target: 20
    title_position: bottom
    icon_position: inside
    unit_of_measurement: '%'
    width: 100%

Hope it helps someone…

8 Likes

Thank you!

It tried this but after starting the addon, I see this in the log:

/bin/ash: /ink2mqtt.sh: not found

It is not clear to me what I need to edit in the /config/ink2mqtt/ink2mqtt.sh file?
Actually, you have commented out the MQTT-code in the sh-file, so how is this supposed to work?

Hi @bouwew
Sorry for the delay to reply - Ive been away on vacation.
Looks like I screwed up when copying the addon from my local addons dir to github.
I have updated the ink2mqtt.sh file in the repo now. Please d/l the file and copy it to \config\ink2mqtt\ink2mqtt.sh

Thanks! Unfortunately, it is still not working.
I wonder whether the installation of the add-on is executed correctly on my system (hassio)?
For instance, the file /ink2mqtt.sh is not there after it placed the ink2mqtt.sh file from the repo in \config\ink2mqtt\ink2mqtt.sh and reinstalled the add-on. I also wonder whether ink is installed?
When I issue the command “ink” at the command-line, it says: “-bash: ink: command not found”.

Hi @bouwew
The ink executable is in the hassio addon’s container.
When you install the addon it runs all the commands in the dockerfile to download the source code for libinklevel and ink and then compile them.
(This is why it takes a long time to install the addon vs than with the precompiled images like most addons have)

I only tested the addon on x86 since my hassio is running on an intel architecture VM.

The install procedure should be:

  1. Install the addon from my repo
  2. Download/copy the ink2mqtt.sh file from the repo to /config/ink2mqtt (subfolder in the hassio config dir that you will need to make)

When the addon starts it will copy the ink2mqtt.sh from the config folder into the container. If you see in the dockerfile this is the final line.

With one of my other addons (rtl433tomqtt) that works in the same way - by coying the control script from config dir - users reported issues if they created the .sh file via samba.

What do you get in the hassio system log when you install the addon?
What do you get in the addon log when you (try to) start the addon?

1 Like