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.
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.
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
Maybe someone has an idea, how to get both cartridges separately?
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.
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:
homeassistant@hassbian:~ $ 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
homeassistant@hassbian:~ $ 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
homeassistant@hassbian:~ $ 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
homeassistant@hassbian:~ $ 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
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?
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.
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.
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 ;-(((