Brother HL-L2340DW printer integration [AppDaemon]

I wrote the AppDaemon application that adds four sensors to HA with data from Brother network printer WWW interface. Tested only with HL-L2340DW model.

printer

Arguments:

  • host - hostname or IP address of the printer (required)
  • status_interval - interval scanning for status page, default 10 sec., status and toner sensors (optional)
  • info_interval - interval scanning for information page, default 300 sec., printer counter and drum usage sensors (optional)
  • use_mqtt - use mqtt or add entites by AppDaemon (optional), default false
  • mac - printer MAC address to generate unique_id for MQTT Discovery (optional)
  • retain - retain true or false for MQTT, default false

Configuration example:

brother_printer_status:
  module: brother_printer_status
  class: BrotherPrinterStatus
  host: !secret brother_hostname
  status_interval: 5
  info_interval: 600
  use_mqtt: true
  mac: 00:11:22:33:44:55
  retain: true

Download: https://github.com/bieniu/home-assistant-config/blob/master/apps/brother_printer_status.py

6 Likes

I was able to start it for HL-L2350DW series ( HL-L2352DW ) without much effort.

As my toner level is low and there is additional formatting added at the status page, I had to replace regex for status. The information page (with drum information) has to look much different in those two printers as I had to take other approach.

Solution (it’s not “clean”, but does the job):
Step 1
Replace line:
regex_res = self.regex(r"<dd>.*>(\w+\s?\w+)\s+<.*</dd>", page)
with
regex_res = self.regex(r"<dd><div id=\"moni_data\">(?:<span class=\"moni moniWarning\">)?(?:<span class=\"moni moniOk\">)?([a-zA-Z\s]*)(?:</span>)?</div></dd>", page)

Step 2
Replace line:
regex_res = self.regex(r"\((\d+\.\d+)%\)", page)
with
regex_res = self.regex(r"<dt>Drum&#32;Unit\*</dt><dd>(\d+)%</dd>", page)

Step 3
There is no step 3 - voilà! :slight_smile:

Thanks @Bieniu for sharing this script. It worked great with almost no efforts on my Brother DCP-L2540DW. Only thing I had to put in initialize method was to set namespace of my hass plugin: self.set_namespace("ns_hass") (I use multiple plugins in appdaemon). All sensors popped up right on HA UI :slight_smile:

1 Like

Can you please elaborate where did you get that value from? :slight_smile:

     self.MAX_IMAGE_HEIGHT = 56

I was just writing simple script using curl to get level of the toner (I’m not using AppDaemon, so wanted something for simple sensor) and was curious why printer’s status shows huge level of toner while value in HTML source is just 44.

So how did you figure out that equation? :slight_smile:
I’m just curious…

toner = round(int(regex_res) / self.MAX_IMAGE_HEIGHT * 100)

In WWW panel there is image (black bar). When toner cartridge is full height of this image is 56 pixels.

Ha! Sounds obvious. But I would have to start scripting when toner was full. Thanks!

I put the brother_printer status.py in folder \HASSIO\config\custom_components\brother_printer_status

then put settings in my config.yaml. However when I check I get the error. Configuration validation

Validate your configuration if you recently made some changes to your configuration and want to make sure that it is all valid

Configuration invalidCHECK CONFIG

Integration not found: brother_printer_status"

There is information in OP that this is AppDaemon application, not custom component.

I moved to \HASSIO\config\appdaemon\apps

Am I missing something more?

AppDaemon installation?

I have appdeamon installed. I just never installed a app like this sorry.

image

Move brother_printer_status.py file to apps folder and add app configuration to config\apps\apps.yaml file.

1 Like

Got it. Thank you for your time and help!

1 Like