Epson WF-3540 ink level monitoring

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

been ‘inspecting’ the html page of the above cartridge-status page, but it seems there’s no mentioning of any percentages. Might that explain the output-less outcome of the above scripts?

Does anyone of you see any percentages in the epson driver page at all? I only have these cartridge icons, and no reference in the underlying code…

Cheers,
Marius

can’t get this to working on my XP-900 and i have an extra PBK cartridge.
can anyone help me ?

Hello,
could some of you help me to get this running for my WF-5690?

Following is my html (https://192.168.0.101/PRESENTATION/ADVANCED/INFO_PRTINFO/TOP):

image

Thanks in advance

Edit: curl -k (ignore selfsigned cert) solved my problem :slight_smile:

@rpitera Thanks for the great icons! Could you also create one for the ink waste container?

Icon in WebGui: image

Thanks in advance

patrone

i’ve editet @rpitera graphic to this one for my interface. hope it helps

2 Likes

Thank you!

hi community,

trying to get this right for once, I can’t use any of the posted curl commands, or better, they wont give any useful feedback.

I have a wf 5710 printer, and the page is on https://192.168.1.42/PRESENTATION/HTML/TOP/PRTINFO.HTML

If i insect that page this is the result, I can see all cartridges with a ‘height’ which I take it is the ink level?

please help me creating the correct curl command, cause i really dont understand what awk -f does or the rest of the lines that follow that command…

—edit----

yess!! getting there:


had to use this:

sensor:
  - platform: command_line
    name: Epson ink level Black
    command: /usr/bin/curl -k https://192.168.1.42/PRESENTATION/HTML/TOP/PRTINFO.HTML | awk -F"'" '/Ink_K.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
    unit_of_measurement: '%'
    scan_interval: 14400

created binary_sensors, to be able to use the slider in an automation:

binary_sensor:
  - platform: template
    sensors:
      ink_level_black_threshold:
        friendly_name: 'Ink level black threshold'
        value_template: >
          {{(states('sensor.epson_ink_level_black') | float) <
            (states('input_number.ink_level') | float)}} 

automation:
  - alias: 'Printer Ink Alert'
    trigger:
      platform: state
      entity_id:
        - binary_sensor.ink_level_black_threshold
        - binary_sensor.ink_level_magenta_threshold
        - binary_sensor.ink_level_yellow_threshold
        - binary_sensor.ink_level_cyan_threshold
        - binary_sensor.ink_level_waste_threshold
      to: 'on'
    condition:
      condition: template
      value_template: >
        {{ is_state('input_boolean.notify_system', 'on')}}
    action:
      - service: notify.notify
        data_template:
          title: 'Low ink'
          message: >
            {% set color = trigger.entity_id[24:-10] %}
            {{ trigger.to_state.attributes.friendly_name }} is low at 
            {{states('sensor.epson_ink_level_' + color)}}
      - condition: template
        value_template: >
          {{ is_state('input_boolean.persistent_notification_create', 'on')}}
      - service: persistent_notification.create
        data_template:
          title: 'Low ink'
          message: >
            {{ trigger.to_state.attributes.friendly_name }} is low
          notification_id: low-printer-ink-level-alert

customized the sensors to show a red_flag icon:

homeassistant:
  customize:
    sensor.epson_ink_level_black:
      templates:
        entity_picture: >
          if (state > entities['input_number.ink_level'].state ) return '/local/devices/epson/ink_k.png';
          return '/local/devices/epson/ink_k_alert.png';

have fun!

HI
edited @cheese’ s and @rpitera’s images to all transparent, with and without flags

to show up as nicely without the white background, in the frontend:

48

here they are if you can use them:

ink_c
ink_k
ink_m
ink_c_alert
patrone
ink_waste_alert
ink_m_alert
ink_k_alert
ink_y_alert
ink_y

4 Likes

How do I set these icons in lovelace? using the png as icon does not give me an error but it show up blank.

you can set .png files as entity_picture (either in known_devices, in templates when using template sensors, or by using customize.
Icons are only useable with the mdi: icons

Just came across this. Thanks for the icons. I have a HP printer and was needing some nice icons for the ink, and I should be able to adapt some of this for my printer.

thought I’d post the relevant cartridge icons for my new WF printer:

ink_c ink_k ink_m ink_waste ink_y

48

1 Like

how do i fix this for my black and photo black ?
printer epson XP-900


home assistant:

the numbers of the black and photo black are behind eachother.

Hi @tarbax , I don’t own an Epson XP-900 so what I’m going to suggest has not been tested. It seems that black and photo black information cannot be properly split because Ink_K.PNG appears twice so I would suggest to modify the command a little bit: using head and tail commands. What about this?

/usr/bin/curl -k https://myprintersipadress/PRESENTATION/HTML/TOP/PRTINFO.HTML | grep Ink_K.PNG | head -1 | awk -F"’" ‘/Ink_K.PNG/ && $6+0 == $6 { printf “%.0f\n”, $6 / 50 * 100 }’

and this?

/usr/bin/curl -k https://myprintersipadress/PRESENTATION/HTML/TOP/PRTINFO.HTML | grep Ink_K.PNG | tail -1 | awk -F"’" ‘/Ink_K.PNG/ && $6+0 == $6 { printf “%.0f\n”, $6 / 50 * 100 }’

Good luck!