Epson WF-3540 ink level monitoring

I am using command line sensors to monitor my Epson WF-3540 ink levels.

The sensor uses curl and awk to parse the levels from the web GUI:

This should also work with other printers from the Epson Workforce series, which display their ink levels on the web GUI.

The ink levels are show in the GUI:


Thanks to @rpitera for the cool icons!

Next step will be to notify me when the levels drop under certain thresholds. But I first have to investigate how little the levels can be while still being able to print properly.

11 Likes

Nice! @turboc wrote a great AppDaemon app to do this and I’m using that but this is a great alternative for those who don’t run AD.

Thanks for sharing it!

BTW, I created these ink cart icons for the AD app, maybe you could use them here?

Thanks for sharing those! I tried to integrate them:

I wonder how I can include those icons in my panel without having HASS to show a zoomed version?

You can play with the sizing of the original images; I’ve always had to tweak things whenever I use a custom image for an icon. But I gave you some older icons by mistake - here’s the ones I am actually using and they fit perfect sorry for the error.

Even cooler! I updated my initial post. Thanks for those icons.

1 Like

This is exactly what I’ve been looking for! Thank you for sharing this!

1 Like

Awesome implementation and may thanks for sharing it here.

It worked immediately but my printer seems to be a little bit different? I have a PBK (Photo Black) cartridge beside the just black one. So my “black” status now shows ‘60 96 %’

Problem is, that it uses the same Ink_K.PNG image :frowning:

Maybe someone has an idea, how to get both cartridges separately?

Thanks,
Daniel

You could modify the awk command to extract based on the title of the ink level status.

The title is written after the PNG img tag:

<div class='clrname'>BK</div>
</li>

I sorted out the AWK commands for Photo Black if anyone needs it.

https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/packages/epson_printer.yaml

1 Like

This is great! Thank you very much! Below you’ll find the awk commands I had to tune for the Epson SX420W:

sensor:
  - platform: command_line
    name: Epson Ink Level Black
    command: /usr/bin/curl -X GET http://192.168.0.201 | awk -F "'" '/Ink_K.PNG/ { printf "%.0f\n", $6 / 50 * 100; exit }'
    unit_of_measurement: '%'
    scan_interval: 14400

  - platform: command_line
    name: Epson Ink Level Magenta
    command: /usr/bin/curl -X GET http://192.168.0.201 | awk -F "'" '/Ink_M.PNG/ { printf "%.0f\n", $6 / 50 * 100; exit }'
    unit_of_measurement: '%'
    scan_interval: 14400

  - platform: command_line
    name: Epson Ink Level Yellow
    command: /usr/bin/curl -X GET http://192.168.0.201 | awk -F " " '/Ink_Y.PNG/ { getline; print $6; exit}' | awk -F "px" '{ printf "%.0f\n", (50 - $1) / 50 * 100; exit}'
    unit_of_measurement: '%'
    scan_interval: 14400

  - platform: command_line
    name: Epson Ink Level Cyan
    command: /usr/bin/curl -X GET http://192.168.0.201 | awk -F " " '/Ink_C.PNG/ { getline; print $6; exit}' | awk -F "px" '{ printf "%.0f\n", (50 - $1) / 50 * 100; exit}'
    unit_of_measurement: '%'
    scan_interval: 14400

and a screenshot (yep, I need to change the Cyan!):

ink

I have an Epson Workforce 845. The scripts are awesome except, at least in my printer, they don’t seem to report correctly if ink level is below I think 20%. I think the original scripts use the value of “height” field divided by 50. This is okay until ink level falls below I think 20%. At that point, the HTML uses a new style (Color 2) and using the value as is is incorrect. The formula from @timseebeck seems to be correct for when the ink level is below 20%. Some conditionals are needed to use both formula’s as needed. I would do it but this is beyond my expertise.

Can someone confirm if if the original script is working for you and your ink level is below 20% for a color?

Oh, thank you! That would explain why I had to change the expression for yellow and cyan in my case. I thought it was different depending on colors and not on level. I will keep an eye on it and provide some feedback.

Looking at my epson 845 printer, it seems that any ink level 50% or above uses the color class. Ink level below 50% uses the color2 class. Using this hypothesis, I crafted a shell script that figures out the class type and then uses the correct formula. This needs some additional testing. Do you mind testing this to see what you get, especially if you recently changed your Cyan cartridge. Here is the script file (assuming you store it in a scripts folder:

get-ink-level.sh
    curl $1 | awk -F"'" $2 |
    awk '{
       x = index($2, "color2")
       if (x==0) #ink is equal to or more than 50 percent as uses color style
       {
           value = substr ($9, 9, 2);
           printf "%.0f\n", value / 50 * 100;
           exit;
        } else #ink is less than 50% and uses color2 style
        {
           value = substr ($7, 9, 2);
           printf "%.0f\n", (50 - value) / 50 * 100;
           exit;
         }}'

This script is called once per color (example)

sh /.homeassistant/scripts/get-ink-level.sh 192.168.100.12/PRESENTATION/HTML/TOP/PRTINFO.HTML '/Ink_Y.PNG/'

Note: I’m not a shell script expert by any means so please let me know any optimizations. Please also let me know if anything does not work. Comparing to the visual diagram from my printer, the %s for the 4 colors seemed correct.

2 Likes

I’ve tried your script. It seems it works. I had to remove /PRESENTATION/HTML/TOP/PRTINFO.HTML from the URL address, though. Here’s the output:

[email protected]:~ $ sh /home/homeassistant/.homeassistant/includes/shell_scripts/get-ink-level.sh 192.168.0.202 '/Ink_Y.PNG/'
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100  6925  100  6925    0     0  82310      0 --:--:-- --:--:-- --:--:-- 84451
14
[email protected]:~ $ sh /home/homeassistant/.homeassistant/includes/shell_scripts/get-ink-level.sh 192.168.0.202 '/Ink_C.PNG/'
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100  6925  100  6925    0     0  71486      0 --:--:-- --:--:-- --:--:-- 72894
2
[email protected]:~ $ sh /home/homeassistant/.homeassistant/includes/shell_scripts/get-ink-level.sh 192.168.0.202 '/Ink_K.PNG/'
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100  6925  100  6925    0     0  98655      0 --:--:-- --:--:-- --:--:--   99k
70
[email protected]:~ $ sh /home/homeassistant/.homeassistant/includes/shell_scripts/get-ink-level.sh 192.168.0.202 '/Ink_M.PNG/'
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100  6925  100  6925    0     0  69900      0 --:--:-- --:--:-- --:--:-- 76944
100

14, 2, 70 and 100 are the current levels of yellow, cyan, black and magenta, respectively. Still not changed the cyan cartridge :sweat_smile:
Thanks for sharing!

Awesome - great it worked. I’m having issues getting this to work in my HASS instance. I think it has to do with me using SSL, Let’s Encrypt and DuckDns. It fails to execute the shell command when trying to hit my local epson IP. Really bizarre.

@timseebeck are you running ssl for your hass install?

I’m doing something similar but I’m using ipptool instead of curl:

  - platform: command_line
    name: EPSON Black Ink
    command: "ipptool -v -t ipp://workforce.webb.haus:631/ipp/print get-printer-attributes.test | grep marker-levels | sed -e 's/^.*\\=\\s//' | cut -d',' -f1"
    unit_of_measurement: '%'

  - platform: command_line
    name: EPSON Cyan Ink
    command: "ipptool -v -t ipp://workforce.webb.haus:631/ipp/print get-printer-attributes.test | grep marker-levels | sed -e 's/^.*\\=\\s//' | cut -d',' -f2"
    unit_of_measurement: '%'

  - platform: command_line
    name: EPSON Magenta Ink
    command: "ipptool -v -t ipp://workforce.webb.haus:631/ipp/print get-printer-attributes.test | grep marker-levels | sed -e 's/^.*\\=\\s//' | cut -d',' -f3"
    unit_of_measurement: '%'

  - platform: command_line
    name: EPSON Yellow Ink
    command: "ipptool -v -t ipp://workforce.webb.haus:631/ipp/print get-printer-attributes.test | grep marker-levels | sed -e 's/^.*\\=\\s//' | cut -d',' -f4"
    unit_of_measurement: '%'

In theory the ipptool method should work with any printer that speaks IPP, and possibly even non-network printers attached to CUPS servers, but I don’t have anything like that around to test the theory.

1 Like

Not right now. I used to in the past. Now I’m with plain http inside my LAN and from the outside I use TOR.

I got it to work when using https, but I had to scrap using a sh file. No idea why it did not work with a .sh file. Here are the changes:

 - platform: command_line
     name: Epson Ink Level Black
     unit_of_measurement: '%'
     scan_interval: '24:00'
     command: /usr/local/bin/curl 192.168.100.12/PRESENTATION/HTML/TOP/PRTINFO.HTML | awk -F"'" '/Ink_K.PNG/' | awk '{x = index($2, "color2"); if (x==0) { value = substr ($9, 9, 2); printf "%.0f\n", value / 50 * 100; exit;} else {value = substr ($7, 9, 2); printf "%.0f\n", (50 - value) / 50 * 100; exit;}}'

You would need to change the command for the other 3 inks. In my case I had to keep the /PRESENTATION/HTML/TOP/PRTINFO.HTML as on the epson 845 without that it takes you to a menu page.

I also updated the scan interval to be 1 day.

1 Like

HI

desperately trying to get this to work, but i cant seem to get the command right:

I’m still on Hassio .62.1

I get through the setup without errors , but no output yet. Please forgive my asking, but how could these 4 commands , while being identical except for the .png file, get 4 different results? Don’t they ‘command’ the same??

this is what i get right now. Looking fine, no info of use though ;-(((

19

latest command_line sensor efforts:

sensor:
  - platform: command_line
    name: Epson ink level Black
    command: /usr/bin/curl -X GET http://192.168.xxx.xxx | awk -F "'" '/Ink_K.PNG/ { printf "%.0f\n", $6 / 50 * 100; exit }'
    unit_of_measurement: '%'
    scan_interval: 14400

  - platform: command_line
    name: Epson ink level Magenta
    command: /usr/bin/curl -X GET http://192.168.xxx.xxx | awk -F "'" '/Ink_M.PNG/ { printf "%.0f\n", $6 / 50 * 100; exit }'
    unit_of_measurement: '%'
    scan_interval: 14400

  - platform: command_line
    name: Epson ink level Yellow
    command: /usr/bin/curl -X GET http://192.168.xxx.xxx | awk -F " " '/Ink_Y.PNG/ { getline; print $6; exit}' | awk -F "px" '{ printf "%.0f\n", (50 - $1) / 50 * 100; exit}'
    unit_of_measurement: '%'
    scan_interval: 14400

  - platform: command_line
    name: Epson ink level Cyan
    command: /usr/bin/curl -X GET http://192.168.xxx.xxx | awk -F " " '/Ink_C.PNG/ { getline; print $6; exit}' | awk -F "px" '{ printf "%.0f\n", (50 - $1) / 50 * 100; exit}'
    unit_of_measurement: '%'
    scan_interval: 14400

Please have a look?

btw the 3640 also has an Icn_Mb.PNG
for the Maintenance Box…


Marius