Monitor HP number of printed pages with node-red

image
This shows the number of prints on my HP envy photo 6200 printer (in danish).

To pull this off, I use the integration IPP https://www.home-assistant.io/integrations/ipp/ to get inklevels, and I use node-red Home Assistant Community Add-on: Node-RED. The last thing is https://github.com/zachowj/hass-node-red installed in HACS.

I first discovered that my printer has it’s own webserver where it shows how many prints I’ve made. I instantly presser F12 to open Chromes developer tool. In the network tab I looked through the calls and found http://hpenvy.local/DevMgmt/ProductUsageDyn.xml. hpenvy.local is the url for my printer. This page contains xml and somewhere in there is the number of printed pages.

With this xml url I went back to node-red and implemented the sensor:
image

[{"id":"79f89519.7e1ecc","type":"www-request","z":"81ba4efe.a2ed4","name":"","method":"GET","ret":"txt","url":"http://hpenvy.local/DevMgmt/ProductUsageDyn.xml","follow-redirects":true,"persistent-http":true,"tls":"","x":270,"y":920,"wires":[["6a3c9b00.2be004"]]},{"id":"6a3c9b00.2be004","type":"xml","z":"81ba4efe.a2ed4","name":"","property":"payload","attr":"","chr":"","x":410,"y":920,"wires":[["484ed0db.ebd6d"]]},{"id":"484ed0db.ebd6d","type":"ha-entity","z":"81ba4efe.a2ed4","name":"","server":"decbc6c0.b92a98","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"udskrifter"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:newspaper-variant-outline"},{"property":"unit_of_measurement","value":"sider"}],"state":"payload[\"pudyn:ProductUsageDyn\"][\"pudyn:PrinterSubunit\"][0][\"dd:TotalImpressions\"][0]._","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":550,"y":920,"wires":[[]]},{"id":"2e7880d6.016af","type":"poll-state","z":"81ba4efe.a2ed4","name":"Printer tændt","server":"decbc6c0.b92a98","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"5","updateIntervalUnits":"minutes","outputinitially":false,"outputonchanged":true,"entity_id":"sensor.hp_envy_photo_6200_series_black_ink","state_type":"num","halt_if":"0","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"x":90,"y":920,"wires":[["79f89519.7e1ecc"],[]]},{"id":"decbc6c0.b92a98","type":"server","name":"Home Assistant","addon":true}]

Import the above code in node-red to get an easy start. The first node is polling the printer every 5 minutes (but only if it reports an ink level = is turned on). The next node fetches the xml, and the third parses it.
When you get here, attach a debug node and to see where your number exists and press “Copy value”:

This makes it easy to get the long path, which you simply paste in to the last node’s state.

Good luck :slight_smile:

1 Like