Epson WF-3540 ink level monitoring

thanks it worked after i replaced “’” ‘ to “'” ’

working config:

- platform: command_line
  name: Epson ink level Black
  command: /usr/bin/curl -k https://192.168.1.131/PRESENTATION/HTML/TOP/PRTINFO.HTML | awk -F"'" '/Ink_K.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }' | head -1
  unit_of_measurement: '%'
  scan_interval: 14400
- platform: command_line
  name: EEpson Ink Level Magenta
  command: /usr/bin/curl -k https://192.168.1.131/PRESENTATION/HTML/TOP/PRTINFO.HTML | awk -F"'" '/Ink_M.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
  unit_of_measurement: '%'
  scan_interval: 14400
- platform: command_line
  name: Epson Ink Level Yellow
  command: /usr/bin/curl -k https://192.168.1.131/PRESENTATION/HTML/TOP/PRTINFO.HTML | awk -F"'" '/Ink_Y.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
  unit_of_measurement: '%'
  scan_interval: 14400
- platform: command_line
  name: Epson Ink Level Cyan
  command: /usr/bin/curl -k https://192.168.1.131/PRESENTATION/HTML/TOP/PRTINFO.HTML | awk -F"'" '/Ink_C.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
  unit_of_measurement: '%'
  scan_interval: 14400
- platform: command_line
  name: Epson ink level Photo Black
  command: /usr/bin/curl -k https://192.168.1.131/PRESENTATION/HTML/TOP/PRTINFO.HTML | awk -F"'" '/Ink_K.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }' | tail -1
  unit_of_measurement: '%'
  scan_interval: 14400
1 Like

Hoping someone can help here…

I have an Epson Artisan 730, and the data presentation appears to be a bit different than what I see above:

<div class='tank' style="left: 28px;"></div>
<div class='color' style="left: 28px; top: 315px;"><img class='color' src="[../../IMAGE/Ink_C.PNG](http://192.168.86.65/PRESENTATION/IMAGE/Ink_C.PNG)" height='34'></div>
<div class='clrname' style="left :28px">C</div>
<div class='tank' style="left: 60px;"></div>
<div class='color' style="left: 60px; top: 301px;"><img class='color' src="[../../IMAGE/Ink_Y.PNG](http://192.168.86.65/PRESENTATION/IMAGE/Ink_Y.PNG)" height='48'></div>
<div class='clrname' style="left :60px">Y</div>
<div class='tank' style="left: 92px;"></div>
<div class='color' style="left: 92px; top: 302px;"><img class='color' src="[../../IMAGE/Ink_LC.PNG](http://192.168.86.65/PRESENTATION/IMAGE/Ink_LC.PNG)" height='47'></div>
<div class='clrname' style="left :92px">LC</div>
<div class='color2' style="left: 124px;"><img class='color2' src="[../../IMAGE/Ink_K.PNG](http://192.168.86.65/PRESENTATION/IMAGE/Ink_K.PNG)" height='45'></div>
<div class='tank' style="left: 124px; height: 45px;"></div>
<div class='clrname' style="left :124px">BK</div>
<div class='tank' style="left: 156px;"></div>
<div class='color' style="left: 156px; top: 304px;"><img class='color' src="[../../IMAGE/Ink_M.PNG](http://192.168.86.65/PRESENTATION/IMAGE/Ink_M.PNG)" height='45'></div>
<div class='clrname' style="left :156px">M</div>
<div class='tank' style="left: 188px;"></div>
<div class='color' style="left: 188px; top: 305px;"><img class='color' src="[../../IMAGE/Ink_LM.PNG](http://192.168.86.65/PRESENTATION/IMAGE/Ink_LM.PNG)" height='44'></div>
<div class='clrname' style="left :188px">LM</div>
<div class='msgback'></div>

I believe the values I need to divide against are the height numbers divided by 50, as those percentages appear to match what I have in the visual display, but I cannot figure out how to parse the text with awk. I’ve tried re-engineering the code and searching out on Google on how to use awk parameters, but am at a loss. Any pointers?

Thanks!

Hi!

I save the excerpt you shared in the forum in a text file and this is what I achieved:

$ cat kk.txt  | awk -F"'" '/Ink_K.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
90
$ cat kk.txt  | awk -F"'" '/Ink_C.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
68
$ cat kk.txt  | awk -F"'" '/Ink_M.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
90
$ cat kk.txt  | awk -F"'" '/Ink_Y.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
96
$ cat kk.txt  | awk -F"'" '/Ink_LM.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
88
$ cat kk.txt  | awk -F"'" '/Ink_LC.PNG/ && $6+0 == $6 { printf "%.0f\n", $6 / 50 * 100 }'
94

Are those values similar to the ink level in your printer right now?

timeseebeck -
Thank you so much for the code. That’s exactly what I was looking for. I can’t tell what is different in your code than in my many iterations, but regardless - it’s working :slight_smile:

Really appreciate the help!

1 Like

Nice work, I use Hassio on RPi B3+, so I think I can’t install curl, is there a way to obtain ink levels from an Epson XP-215 printer using Hassio? My printer have the web page with the ink levels and using curl from shell command installed on windows, I obtain the data of the height of icons, the same html page, so the way is right, but I cannot use it in Hassio maybe…I searched but did not found anything.

Any chance to get a look at you home assistant configs? Running into issues getting the status of printer using curl. I see you show status in one of your screen shots.

hi, can you share the code for the update sensor? I managed to have my ink levels showed but don’t know how to send commands creating an executable refresh

sure, but since its all a bit tied together and I don’t know what you do and don’t have, I’ll give you my full package. might help @Charles_Brown too, sorry, missed your post.

##########################################################################################
# Package Printers
# inspired by https://community.home-assistant.io/t/epson-wf-3540-ink-level-monitoring/21813/20
# by @mariusthvdb https://community.home-assistant.io/u/Mariusthvdb/summary
##########################################################################################
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';
    sensor.epson_ink_level_cyan:
      templates:
        entity_picture: >
          if (state > entities['input_number.ink_level'].state ) return '/local/devices/epson/ink_c.png';
          return '/local/devices/epson/ink_c_alert.png';
    sensor.epson_ink_level_magenta:
      templates:
        entity_picture: >
          if (state > entities['input_number.ink_level'].state ) return '/local/devices/epson/ink_m.png';
          return '/local/devices/epson/ink_m_alert.png';
    sensor.epson_ink_level_yellow:
      templates:
        entity_picture: >
          if (state > entities['input_number.ink_level'].state ) return '/local/devices/epson/ink_y.png';
          return '/local/devices/epson/ink_y_alert.png';
    sensor.epson_ink_level_waste:
      templates:
        entity_picture: >
          if (state > entities['input_number.ink_level'].state ) return '/local/devices/epson/ink_waste.png';
          return '/local/devices/epson/ink_waste_alert.png';

    automation.printer_ink_alert:
      show_last_changed: true
      templates:
        icon: >
          if (state === 'on') return 'mdi:printer-alert';
          return 'mdi:printer-settings';
        icon_color: >
          if (state === 'on') return 'rgb(251, 210, 41)';
          return 'rgb(54, 95, 140)';

    device_tracker.epson_printer:
      show_last_changed: true
      templates:
        theme: >
          if (state === 'home') return 'green';
          return 'grey';
        _stateDisplay: >
          if (state === 'home') return 'Online';
          return 'Offline';

    device_tracker.hp_printer:
      show_last_changed: true
      templates:
        theme: >
          if (state === 'home') return 'green';
          return 'grey';
        _stateDisplay: >
          if (state === 'home') return 'Online';
          return 'Offline';

    script.update_epson_cartridge_sensors:
      action_name: Update
      icon: mdi:printer-wireless

##########################################################################################
#  Sensors
##########################################################################################

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

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

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

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

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

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)}}
      ink_level_magenta_threshold:
        friendly_name: 'Ink level magenta threshold'
        value_template: >
          {{(states('sensor.epson_ink_level_magenta') | float) <
            (states('input_number.ink_level') | float)}}
      ink_level_yellow_threshold:
        friendly_name: 'Ink level yellow threshold'
        value_template: >
          {{(states('sensor.epson_ink_level_yellow') | float) <
            (states('input_number.ink_level') | float)}}
      ink_level_cyan_threshold:
        friendly_name: 'Ink level cyan threshold'
        value_template: >
          {{(states('sensor.epson_ink_level_cyan') | float) <
            (states('input_number.ink_level') | float)}}
      ink_level_waste_threshold:
        friendly_name: 'Ink level waste threshold'
        value_template: >
          {{(states('sensor.epson_ink_level_waste') | float) <
            (states('input_number.ink_level') | float)}}
##########################################################################################
#  Inputs
##########################################################################################

input_number:
  ink_level:
    name: Ink level
    icon: mdi:printer-settings
    min: 0
    max: 100
    step: 5

##########################################################################################
#  Groups
##########################################################################################

group:
  epson_printer:
    name: Epson office ink status
    control: hidden
    entities:
      - device_tracker.epson_printer
      - script.update_epson_cartridge_sensors

      - sensor.epson_ink_level_black
      - sensor.epson_ink_level_cyan
      - sensor.epson_ink_level_magenta
      - sensor.epson_ink_level_yellow
      - sensor.epson_ink_level_waste
      - automation.printer_ink_alert

      - input_number.ink_level
      - 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

##########################################################################################
#  Scripts
##########################################################################################

script:
  update_epson_cartridge_sensors:
    alias: Update Cartridge sensors
    sequence:
      - service: homeassistant.update_entity
        entity_id: sensor.epson_ink_level_black
      - service: homeassistant.update_entity
        entity_id: sensor.epson_ink_level_cyan
      - service: homeassistant.update_entity
        entity_id: sensor.epson_ink_level_magenta
      - service: homeassistant.update_entity
        entity_id: sensor.epson_ink_level_yellow
      - service: homeassistant.update_entity
        entity_id: sensor.epson_ink_level_waste

##########################################################################################
#  Automations
##########################################################################################

automation:
  - alias: 'Printer Ink Alert'
    id: 'Printer Ink Alert'
    initial_state: 'on'
    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'
#      - platform: state
#        entity_id: device_tracker.epson_printer
#        to: 'home'
    condition:
      - condition: template
        value_template: >
          {{ is_state('device_tracker.epson_printer', 'home')}}
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_utility', 'on')}}
    action:
      - service: notify.system
        data_template:
          title: 'Ha main: Low ink'
          message: >
            {% set color = trigger.entity_id.split('.')[-1].split('_')[2] %}
            {% set basesensor = 'sensor.epson_ink_level_{}'.format(color) %}
            {{ trigger.to_state.attributes.friendly_name }} is low at {{ states(basesensor) }}
#            {% 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
1 Like

thank you so much, I have partial configuration and the part about the refresh of the sensors is very usefull for me because I use my printer occasionally so with 1 click I can see immediatly the values, even if I also can lower the scan_interval, have a good day!

Thank you will make the changes for my device. You my friend are awesome.

Got package working. Having issues with the ink color images not changing.

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

I know the image works with the file location. I used it without the template sensor.
The template doesn’t show the image of the ink color.

Did you manage to get this to work, I don’t see the image and it looks like the same issue when I read you’re message

all I can add is they work in my setup, so the templates are correct. What happens when you enter the templates in dev-template? (have to rewrite them for ninja of course)

also: the is a custom-ui template, so be sure to have custom-ui installed?

Thanks for your reply.

I’m quite new to home assistant. All the sensors seem to work but I don’t see the images.
I don’t have anything like custom-ui installed I think.

When I change

sensor.epson_ink_level_black:
  templates:
    entity_picture: >
      if (state > entities['input_number.ink_level'].state ) return '/local/images/devices/epson/ink_black.png';
      return '/local/images/devices/epson/ink_black_alert.png';

to

sensor.epson_ink_level_black:
     entity_picture: '/local/images/devices/epson/ink_black.png'

The image becomes visable but there is no state change off course.

correct, but that’s not a template so no customzation going on.

Its like this: if you can template things according to the docs (see template sensor eg) you do it in the regular entity definition. If that is not an option, like icon_template, you can still do it, but need ti install and use custom-ui.

regular HA uses jinja templates, check on dev-template,and are evaluated server side, custom-ui uses javascript templates which use an other syntax altogether, and are evaluated in browser.

  templates:
    entity_picture: >
      if (state > entities['input_number.ink_level'].state ) return '/local/images/devices/epson/ink_black.png';
      return '/local/images/devices/epson/ink_black_alert.png';

is custom-ui javascript, so needs that custom0ui installed.

this would be the jinja equivalent:


{% if states('sensor.epson_ink_level_black') >= states('input_number.ink_level') %} /local/images/devices/epson/ink_black.png
{% else %} /local/images/devices/epson/ink_black_alert.png
{% endif %}

and you can test that in your dev-template

Ok, thanks for now. I’ll try if I can get it to work.

ok the dev templates works it returns
/local/images/devices/epson/ink_black.png

So I can’t use jinja for an entity_picture?

Thanks for the code :). I done some modication because i have a photo printer with more cartridges (SC-P600 Series) :P.

Customize :

sensor.epson_ink_level_y:
  friendly_name: Yellow
  entity_picture: /local/epson/Y.png   
sensor.epson_ink_level_lm:
  friendly_name: Light Magenta
  entity_picture: /local/epson/LM.png  
sensor.epson_ink_level_lc:
  friendly_name: Light Cyan
  entity_picture: /local/epson/LC.png  
sensor.epson_ink_level_m:
  friendly_name: Magenta
  entity_picture: /local/epson/M.png  
sensor.epson_ink_level_c:
  friendly_name: Cyan
  entity_picture: /local/epson/C.png  
sensor.epson_ink_level_llk:
  friendly_name: Light Light Gray
  entity_picture: /local/epson/LLK.png
sensor.epson_ink_level_lk:
  friendly_name: Light Gray
  entity_picture: /local/epson/LK.png
sensor.epson_ink_level_k:
 friendly_name: Black
 entity_picture: /local/epson/K.png  

Configuration :

And the pictures :

C LC LK LLK PK VLM VM Y

its like this:
you can use jinja in a template sensor or any other HA template component to set an entity_picture.

Since these are not template sensors but command_line sensors, (and they don’t have that option) you need to customize these sensors.

If you check Customizing entities - Home Assistant you’ll notice no templates are availabe/allowed.
Next and only option then is custom-ui. Install that and use the JS template I provided…