Since very nice HP Printer component available as HACS integration works only with devices exposing their status via shared .xml files (which is case for only selected models), I started investigation on how HP laser printers can be monitored from home assistant. I found quite a bit of relevant information about monitoring printers paramenter via SMNP on Solar Winds web page:
https://documentation.solarwindsmsp.com/N-central/documentation/Content/Services/Printer/Services_PrinterTonerLevel.html
I used this as a starting point to investigate a bit more in depth how can I monitor my HP Color LaserJet CP1515n printer and finally I come to something that satisfied me. Since it looks that my printer configuration page is similar to what other members shared for their printers, I thought it might also work for them, being somehow reusableā¦
So here is the end result:
To come up with these results I had to create set of SNMP sensors:
##########################################################
## Printer information via SNMP
##########################################################
# Printer status
- platform: snmp
name: 'cp1515n_total_pages_printed'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.10.2.1.4.1.1
accept_errors: true
scan_interval: 60
unit_of_measurement: 'total pages printed'
- platform: snmp
name: 'cp1515n_color_pages_printed'
host: 192.168.52.42
baseoid: 1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.2.7.0
accept_errors: true
scan_interval: 60
unit_of_measurement: 'color pages printed'
- platform: snmp
name: 'cp1515n_printer_status_code'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.25.3.5.1.1.1
accept_errors: true
scan_interval: 5
- platform: snmp
name: 'cp1515n_printer_error_code'
host: 192.168.52.42
baseoid: 1.3.6.1.4.1.11.2.3.9.4.2.1.4.1.2.22.0
accept_errors: true
scan_interval: 5
- platform: snmp
name: 'cp1515n_uptime'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.1.3.0
accept_errors: true
scan_interval: 1
- platform: template
sensors:
cp1515n_bw_pages_printed:
friendly_name: "B&W pages printed"
unit_of_measurement: 'B&W pages printed'
value_template: "{{ (states('sensor.cp1515n_total_pages_printed')|float - states('sensor.cp1515n_color_pages_printed')|float) | round(0) }}"
cp1515n_printer_error:
friendly_name: "Printer Error"
value_template: >-
{% if is_state('sensor.cp1515n_printer_error_code', '0') %}
Low supply of paper
{% elif is_state('sensor.cp1515n_printer_error_code', '1') %}
No paper available
{% elif is_state('sensor.cp1515n_printer_error_code', '2') %}
Low supply of toner
{% elif is_state('sensor.cp1515n_printer_error_code', '3') %}
No toner available
{% elif is_state('sensor.cp1515n_printer_error_code', '4') %}
A door on the printer is open
{% elif is_state('sensor.cp1515n_printer_error_code', '5') %}
The printer is jammed
{% elif is_state('sensor.cp1515n_printer_error_code', '6') %}
The printer is offline
{% elif is_state('sensor.cp1515n_printer_error_code', '7') %}
Technical service is requested for the printer
{% elif is_state('sensor.cp1515n_printer_error_code', '8') %}
The input tray is missing or not installed properly
{% elif is_state('sensor.cp1515n_printer_error_code', '9') %}
The output tray is missing or not installed properly
{% elif is_state('sensor.cp1515n_printer_error_code', '10') %}
The marker supply is missing or not installed properly
{% elif is_state('sensor.cp1515n_printer_error_code', '11') %}
The output tray is nearly full
{% elif is_state('sensor.cp1515n_printer_error_code', '12') %}
The output tray is full
{% elif is_state('sensor.cp1515n_printer_error_code', '13') %}
The input tray is empty
{% elif is_state('sensor.cp1515n_printer_error_code', '14') %}
The printer is overdue for preventative maintenance
{% else %}
Unknown
{% endif %}
cp1515n_printer_status:
friendly_name: "Printer Status"
value_template: >-
{% if is_state('sensor.cp1515n_printer_status_code', '1') %}
Other
{% elif is_state('sensor.cp1515n_printer_status_code', '2') %}
Unknown
{% elif is_state('sensor.cp1515n_printer_status_code', '3') %}
Idle
{% elif is_state('sensor.cp1515n_printer_status_code', '4') %}
Printing
{% elif is_state('sensor.cp1515n_printer_status_code', '5') %}
Warming Up
{% else %}
Unknown
{% endif %}
cp1515n_printer_uptime:
friendly_name: "Printer Uptime"
value_template: >-
{% set t = states('sensor.cp1515n_uptime') | int %}
{% set t = (t/10) | int %}
{{ '{:d}d {:02d}h {:02d}m {:02d}s'.format(t // 86400, (t // 3600) % 24, (t % 3600) // 60, (t % 3600) % 60) }}
# Black toner
- platform: snmp
name: 'cp1515n_black_capacity'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.8.1.1
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: snmp
name: 'cp1515n_black_remainig'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.1
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: template
sensors:
cp1515n_black_level:
friendly_name: "Black Tomer Level"
unit_of_measurement: '%'
value_template: "{{ (states('sensor.cp1515n_black_remainig')|float / states('sensor.cp1515n_black_capacity')|float * 100) | round(0) }}"
# Cyan tomer
- platform: snmp
name: 'cp1515n_cyan_capacity'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.8.1.2
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: snmp
name: 'cp1515n_cyan_remainig'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.2
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: template
sensors:
cp1515n_cyan_level:
friendly_name: "Cyan Tomer Level"
unit_of_measurement: '%'
value_template: "{{ (states('sensor.cp1515n_cyan_remainig')|float / states('sensor.cp1515n_cyan_capacity')|float * 100) | round(0) }}"
# Magenta tomer
- platform: snmp
name: 'cp1515n_magenta_capacity'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.8.1.3
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: snmp
name: 'cp1515n_magenta_remainig'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.3
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: template
sensors:
cp1515n_magenta_level:
friendly_name: "Magenta Tomer Level"
unit_of_measurement: '%'
value_template: "{{ (states('sensor.cp1515n_magenta_remainig')|float / states('sensor.cp1515n_magenta_capacity')|float * 100) | round(0) }}"
# Yellow toner
- platform: snmp
name: 'cp1515n_yellow_capacity'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.8.1.4
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: snmp
name: 'cp1515n_yellow_remainig'
host: 192.168.52.42
baseoid: 1.3.6.1.2.1.43.11.1.1.9.1.4
accept_errors: true
scan_interval: 3600
#unit_of_measurement: '%'
- platform: template
sensors:
cp1515n_yellow_level:
friendly_name: "Yellow Tomer Level"
unit_of_measurement: '%'
value_template: "{{ (states('sensor.cp1515n_yellow_remainig')|float / states('sensor.cp1515n_yellow_capacity')|float * 100) | round(0) }}"
To make it usable obviously you need to change IP address in all of the sensors to one of your printer (perhaps Iāll improve this one day to have it parametrized :-)). Iāll also dig bit further, perhaps Iāll find some more usefull information available via SNMP formore sensors.
And here is the code for Lovelace card on screenshot above:
cards:
- content: |
## <ha-icon icon="mdi:printer"></ha-icon> HP Color LaserJet CP1515n
type: markdown
- type: divider
- content: >
### <ha-icon icon="mdi:information-variant"></ha-icon> Printer status: {{
states('sensor.cp1515n_printer_status') }}
### <ha-icon icon="mdi:alert-outline"></ha-icon> Printer error: {{
states('sensor.cp1515n_printer_error') }}
### <ha-icon icon="mdi:clock-check-outline"></ha-icon> Printer uptime: {{
states('sensor.cp1515n_printer_uptime') }}
type: markdown
- type: divider
- content: >
### <ha-icon icon="mdi:counter"></ha-icon> Total pages printed: {{
states('sensor.cp1515n_total_pages_printed') }}
### <ha-icon icon="mdi:counter"></ha-icon> Color pages printed: {{
states('sensor.cp1515n_color_pages_printed') }}
### <ha-icon icon="mdi:counter"></ha-icon> B&W pages printed: {{
states('sensor.cp1515n_bw_pages_printed') }}
type: markdown
- type: divider
- content: |
## <ha-icon icon="mdi:invert-colors"></ha-icon> Toner levels:
type: markdown
- cards:
- align: center
animation: auto
animiation: 'on'
attribute: false
background_style: false
card_style: false
charge_entity: false
color: '#222222'
decimal: false
delay: 5000
direction: up
entities:
- entity: sensor.cp1515n_black_level
entity: sensor.cp1515n_black_level
height: 150px
icon: false
icon_position: 'off'
icon_style: false
indicator: auto
limit_value: false
max: 100
min: 0
minmax_style: false
padding: 4px
rounding: 3px
saturation: 100%
severity: false
show_minmax: false
show_value: true
speed: 1000
tap_action: info
target: 10
title: Black
title_position: bottom
title_style: false
type: 'custom:bar-card'
unit_of_measurement: false
value_style: false
visibility: false
width: 75%
- align: center
animation: auto
animiation: 'on'
attribute: false
background_style: false
card_style: false
charge_entity: false
color: '#00ffff'
decimal: false
delay: 5000
direction: up
entities:
- entity: sensor.cp1515n_cyan_level
entity: sensor.cp1515n_cyan_level
height: 150px
icon: false
icon_position: 'off'
icon_style: false
indicator: auto
limit_value: false
max: 100
min: 0
minmax_style: false
padding: 4px
rounding: 3px
saturation: 100%
severity: false
show_minmax: false
show_value: true
speed: 1000
tap_action: info
target: 10
title: Cyan
title_position: bottom
title_style: false
type: 'custom:bar-card'
unit_of_measurement: false
value_style: false
visibility: false
width: 75%
- align: center
animation: auto
animiation: 'on'
attribute: false
background_style: false
card_style: false
charge_entity: false
color: '#ff00ff'
decimal: false
delay: 5000
direction: up
entities:
- entity: sensor.cp1515n_magenta_level
entity: sensor.cp1515n_magenta_level
height: 150px
icon: false
icon_position: 'off'
icon_style: false
indicator: auto
limit_value: false
max: 100
min: 0
minmax_style: false
padding: 4px
rounding: 3px
saturation: 100%
severity: false
show_minmax: false
show_value: true
speed: 1000
tap_action: info
target: 10
title: Magenta
title_position: bottom
title_style: false
type: 'custom:bar-card'
unit_of_measurement: false
value_style: false
visibility: false
width: 75%
- align: center
animation: auto
animiation: 'on'
attribute: false
background_style: false
card_style: false
charge_entity: false
color: '#ffff00'
decimal: false
delay: 5000
direction: up
entities:
- entity: sensor.cp1515n_yellow_level
entity: sensor.cp1515n_yellow_level
height: 150px
icon: false
icon_position: 'off'
icon_style: false
indicator: auto
limit_value: false
max: 100
min: 0
minmax_style: false
padding: 4px
rounding: 3px
saturation: 100%
severity: false
show_minmax: false
show_value: true
speed: 1000
tap_action: info
target: 10
title: Yellow
title_position: bottom
title_style: false
type: 'custom:bar-card'
unit_of_measurement: false
value_style: false
visibility: false
width: 75%
type: horizontal-stack
type: 'custom:vertical-stack-in-card'
Please note that it uses custome verrtical-stack-in-card and bar-card. Hope at least some of you will enjoy it!