Giter Site home page Giter Site logo

thibmaek / homeassistant-hp-ink-levels Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 2.0 91 KB

๐Ÿ–จ Get ink levels from a HP printer and broadcast them as MQTT sensors to Home Assistant

Shell 100.00%
hplip cups hp-printer printer home-assistant mqtt home-assistant-sensor bash

homeassistant-hp-ink-levels's Introduction

Home Assistant HP printer ink levels

๐Ÿ–จ Get ink levels from a HP printer and broadcast them as MQTT sensors to Home Assistant

screenshot of the ink levels in Home Assistant

Prerequirements

All these packages are required and available via apt:

  • cups
  • hplip
  • bash, probably already installed
  • mosquitto, mosquitto-clients
  • cron (or systemd if that works for you), probably already installed

Setup

Add your printer to hplip:

# hplip tries to launch a GUI, when you are running headless/lite add the -i flag to enter interactive mode
$ hp-setup -i hp5510.local

Download the script to a location and make it executable if not already:

$ wget https://raw.githubusercontent.com/thibmaek/homeassistant-hp-ink-levels/master/get-hp-ink-levels.sh -P /home/pi
$ chmod +x /home/pi/get-hp-ink-levels.sh

Edit the lines where it says MQTT_USER= and MQTT_PASS= in the script. You can also edit the host and port if needed. As an alternative, exposing an env var in your shell with the same keys should also work.

Install it as a cron service:

# This will add the script located at /home/pi to the cron service, which will run every 5 minutes
$ (crontab -l 2>/dev/null; echo "*/5 * * * * bash /home/pi/get-hp-ink-levels.sh") | crontab -

Ink levels will now be published to topic: homeassistant/sensor/hp-printer/color-#. Subscribe to this topic to see the changes or add the sensors directly in Home Assistant as a MQTT sensor:

sensor:
  ...
  - platform: mqtt
    name: printer_ink_level_cyan
    state_topic: homeassistant/sensor/hp-printer/color-cyan
    friendly_name: "Ink level (Cyan)"
    icon: mdi:alpha-c-box
    unit_of_measurement: '%'
  ...

Troubleshooting

  • Printer ink levels can only be retrieved when your printer is turned on. They will reflect latest known state in Home Assistant though.
  • If colors and levels mismatch, make sure to check the order that gets returned from hplip matches the order of the array in the script. I've found that my HP5510 returned something different than a 5520. Run hp-info -i and check the order of agent1, agent2, agent3, agent4 and their color. Match that to the order of the array and it should be fine. If you're using 'counterfeit' (cheaper, non HP properietary shit) cartridges, those might get bumped to the beginning of the list.
  • If you're getting 0 as the level on a cartridge you know is full, it's because HP blocks them since they are 'counterfeit'.
  • You might need to start the services for cron and cups manually: sudo systemctl start cups; sudo systemctl start cron;

homeassistant-hp-ink-levels's People

Contributors

gerard33 avatar thibmaek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.