Hey everyone, I’m trying to set up a command line sensor to monitor the ink levels on my printer. It’s been a fun little project, but I’m hitting a bit of a snag. Let me walk you through what I’ve done so far and where I’m stuck.
So, I’ve got this printer that serves up an XML file with some details about its consumables. I’m using xml_grep to pull out the ink levels. The command I’m running is xml_grep 'dd:ConsumableRawPercentageLevelRemaining' <http://192.168.10.43:80/DevMgmt/ProductUsageDyn.xml> --text_only, and it returns two values separated by a space, like 86 30. The first number is the black ink level, and the second is the color ink level. Pretty cool so far!
Now, here’s where I’m running into trouble. I want to split these two values into separate sensors so I can monitor each ink level individually. I tried using a value_template like {{ states.sensor.printer.state.split(' ')[0] }} to grab the first value, but it doesn’t seem to be working. I’ve been messing around with different variations, but nothing’s clicked yet.
I’m determined to figure this out, though! Maybe I’m missing something simple. I’ve heard that splitting strings in templates can be a bit tricky, so I’m hoping someone here has some tips or tricks up their sleeve. If you’ve tackled something similar before, I’d love to hear how you approached it. Let’s see if we can crack this together!
Once I get this sorted, I’m planning to set up some automations to notify me when the ink levels get low. It would be awesome to have that kind of proactive monitoring in my setup. Fingers crossed, I’ll have it all working smoothly soon!