Custom Component for printer ink levels

This is what I use for my HP printer:
It may work for yours.

Got it from:

- platform: snmp
  name: 'Printer Ink - Black'
  host: 192.168.1.135
  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.135
  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.135
  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.135
  baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.4
  accept_errors: true
  scan_interval: 86400
  unit_of_measurement: '%'

Do you have a laser or inktjet?

I have an inkjet

Cool, gonna try it out after holiday :wink:
Also an envy model?

No it’s a photosmart, if it doesn’t work I’ll run through how you find the baseoids for your printer (if it supports SNMP)

I have an hp envy as well. I can see ink levels change when I print a diagnostic report but I can’t see those numbers in the SNMP query. Whole bunch of stuff but not those numbers. The numbers that are close are not changing

mine look identical as yours, even the values, also hp eny owner here…

I have a Canon MX922 printer and when I tried the steps above, I am getting a:

Timeout - No response for 192.168.1.xx.

When executing the the command:

snmpwalk -v2c -c public 192.168.1.xx

Am I doing something wrong?

Just finished setting up the OP’s version of the Ink Custom Component on Home Assistant 0.98.5 and figured I’d provide an updated set of installation instructions. I am running HA in a venv on an Ubuntu 18.04 VM in ESXi 6.0. My printer is a Canon MX922

Please note, these steps are NOT for HASSIO. They also assume you have a basic understanding of working with linux and linux file permissions.

  1. SSH into your HA instance
  2. Install the Ink command
    sudo apt install ink -Y
  3. Navigate to /<your-ha-root-directory/custom_components/ (Note: For a venv, the default root folder location for HA is /home/homeassistant/.homeassistant/)
  4. Create a 0.92 compatible folder for the Ink component.
    sudo mkdir ink/
  5. Download the Custom Component from the OP’s github. The link below is the correct link to the raw version of the file.
    sudo wget https://raw.githubusercontent.com/nalipaz/home-assistant-config/master/custom_components/sensor/ink.py
  6. Rename ink.py to sensor.py. (Note: This was the only way I could get the Ink component to load in my environment.)
    sudo mv ink.py sensor.py
  7. Create and edit manifest.json
    sudo touch manifest.json
    sudo nano manifest.json
  8. Copy/Paste the following into manifest.json exactly as shown. Spacing is important!
{
    "domain": "ink",
    "name": "Ink",
    "documentation": "https://github.com/nalipaz/home-assistant-config/blob/cc688694f96e60783917197613a9e24224eb05ae/custom_components/sensor/ink.py",
    "dependencies": [],
    "codeowners": ["@nalipaz"],
    "requirements": []
  }
  1. Save the file and exit.
    Control+X, then Y, then Enter/Return
  2. Verify that the ink subfolder, and the manifest.json and sensor.py files are owned by the home assistant user/service account.
    image
  3. Tail (i.e. watch) the home-assistant.log file to ensure the component loads correctly when executing step 12.
    tail -f /<your HA directory>/home-assistant.log | grep ink
  4. Restart Home Assistant via the Home Assistant UI

If you see messages similar to the following, you know you’ve set up the Custom Component correctly.

2019-09-09 10:43:02 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for ink which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-09-09 10:43:03 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.ink

The next step is to configure your printer in sensor.yaml as outlined in the first post of this thread. Be aware that if you have logging (i.e. logger:) enabled in your configuration.yaml, you will flood home-assistant.log with an error for each and every color listed under resources: that is not supported by your printer. These errors will repeat at every scan interval. In this case, you will want to cull your list of supported colors quickly to avoid crashing HA.

For those of you with a Canon MX922, here is the sensor.yaml config that worked for me.

  - platform: ink
    host: <your-ip-here>
    scan_interval: 120
    resources:
     - black
     - cyan
     - magenta
     - yellow
     - photoblack

Once you’ve added the entry in sensor.yaml, Check your Config via the HA UI, then Restart HA once more if everything checks out. Once the reboot is complete, you should see new sensor entries in your entities list similar to the ones in the screenshot below.

image

Hopefully this will helps others. Let me know if you encounter any errors with these instructions.

And a Big Thanks to @curt7000 for pointing out the new manifest.json requirement that was added in 0.92.0.

1 Like

Hi @nalipaz

need some help here, i’m putting the file like written, please look below:

in configuration.yaml
image

when i check the configuration file, i get the error below:

what am i missing?

Thank you for your help

Not using it myself but think the folder that ink.py is in should be ink and not sensor

tried, same error

See @daphatty’s post above, think you need to rename ink.py to sensor.py and add a manifest file

tried, same error

You are restarting after you changed it ?

After the installation of the add-on how do you show the levels on the GUI ?

See post 36 in this thread.

I don’t get the sensor levels only the log on the Hassio add-on

Judging by your screenshot, it looks like you are missing the manifest.json file.

i’ve managed to solve the issue, my printer doesn’t work, i get the following trying to query snmp,

my model is officejet 3830, so i cant get the percentage of the ink levels.
This is from the web server