Giter Site home page Giter Site logo

unixorn / ha-franklin Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 201 KB

Monitor cupsd print queues and present the information to Home Assistant via MQTT

Shell 2.97% Dockerfile 3.92% Makefile 6.07% Python 87.04%
cups home-assistant lpq mqtt cupsd printing

ha-franklin's Introduction

ha-franklin

License Code style: black GitHub last commit (branch) Downloads

Table of Contents

Background

I wanted a non-toy test example of using the ha-mqtt-discoverable module.

ha-franklin will monitor CUPSD print queues, and present a binary sensor to Home Assistant over MQTT showing whether the printer is printing.

I use this to turn the smart switch for the HP 4050N in the basement on and off so that by the time I walk downstairs from my office after printing something, Home Assistant has turned on the power to the printer and the job has at least started printing.

Usage

Configuration

Create a config file (yaml) with a list of dictionaries in it. Each dictionary should have the following keys:

  • mqtt_server: DNS name or a raw IP.
  • mqtt_user: the_mqtt_user
  • mqtt_password: the_mqtt_password
  • name: Franklin@cupsd
  • unique_id: printername-cupsd
  • cupsd_queue_name: Queue_name_on_cupsd_server
  • cupsd_server: cupsd.example.com
  • check_interval: 10

The easiest way to create a configuration file is to start by copying config/config-example.yaml and editing it to fit.

Running the Monitor

I recommend using docker, nerdctl or podman to run the tooling in a container.

docker run -v "$(pwd)/config":/config --rm unixorn/ha-franklin ha-cupsd-monitor-queues --settings-file /config/config.yaml

Home Assistant

The container will create a set of MQTT topics using Home Assistant's MQTT discoverability protocol so that your print queue's printing status shows up in Home Assistant.

I set up two automations - one to turn on the peanut plug my HP 4050N is plugged into when jobs appear in the cupsd queue when the sensor turns to on, and a second that turns it off once the sensor switches back to off for ten minutes.

I give it ten minutes for a couple of reasons:

First, because CUPSD will report the queue as done printing when all the postscript has been spooled to the printer. Depending on the complexity of the print job, it may take a minute or two to print the last few pages of the job, even though cupsd considers it complete. If the power gets turned off too soon, you can lose the last page or two of the job, and more annoyingly, cause a printer jam if the power cuts off while a page is moving through the paper path.

Secondly, because although I print rarely, when I do, I typically print several things within a few minutes and I'd prefer to not toggle the printer on and off more than is strictly necessary.

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.