Based on this instruction I tried to setup a similar command line sensor to query the ink level of my HP printer and also the printer status. I’ve tried to run the commands in terminal via SSH and it returns the value I expected (see screenshot).
Some fiddling around and I find something about ‘end of line’ character in Unix, and so I tried running ‘sed’ in terminal to clean the code. The resulting code is like this :
- platform: command_line
name: HP 3835 Color Ink Level
unit_of_measurement: "%"
scan_interval: 60
command: hp-info 2>&1 | grep -oP "(?<=agent1-level\\s{18})(.*\\S)"
- platform: command_line
name: HP 3835 Black Ink Level
unit_of_measurement: "%"
scan_interval: 60
command: hp-info 2>&1 | grep -oP "(?<=agent2-level\\s{18})(.*\\S)"
- platform: command_line
name: HP 3835 Status
scan_interval: 60
command: hp-info 2>&1 | grep -oP "(?<=status-desc\\s{18})(.*\\S)"
However it still gives ‘unknown’ result in entity state page. A look in the HA log shows like this (debug mode) :