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.
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
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)
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
Can you please elaborate where did you get that value from?
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?
I’m just curious…
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
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: