Brother HL-L2340DW and MFC-J5320DW 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 and MFC-J5320DW.



  • 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:

  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



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)
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)
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 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.


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


Got it. Thank you for your time and help!

1 Like

Hey @Bieniu I just wanted to try out your script, but it’s not available anymore. Is there a reason for that? Is it found somewhere else? Am I missing something?
Thanks in advance :slight_smile:

Updated path

1 Like

Thank you very much!

I just updated OP. There is a link for repo.

Hey @Bieniu. I’m using a color inkjet printer. Is it possible, that you add support for those as well?
I’d do it myself but currently, I know too less to modify your code.

The status page html code, where you get the toner status from, looks like this:

<table id="inkLevel" summary="ink level"><tbody><tr><th></th><th></th><th></th><th></th></tr><tr><td><img src="../common/images/magenta.gif" alt="Magenta" class="tonerremain" height="55"></td><td><img src="../common/images/cyan.gif" alt="Cyan" class="tonerremain" height="55"></td><td><img src="../common/images/yellow.gif" alt="Yellow" class="tonerremain" height="40"></td><td><img src="../common/images/black.gif" alt="Black" class="tonerremain" height="54"></td></tr><tr><th>M</th><th>C</th><th>Y</th><th>BK</th></tr></tbody></table>


If you could help me with this, that would be great!

Thanks in advance :slight_smile:

Update: Got the modified script working, now I see all four colors and the page status and created a pull request.

1 Like

Thanks, PR merged.