you changed IP addresses in that .py file?
Yes I did you can see that in the error message also.
Ok,
So stepping back a bit - are you running a Hassio instance of Home Assistant, or something else?
Also - from a quick skim using Google - are you experiencing any network issues on your network?
Do you have Wireless Isolation set on your router? Does that make a difference?
Regards,
James.
Home Assistant in a Venv
All on same network/router
And no network issues that I’m aware of… here is a screenshot from my HA machine opening that url directly from browser. Excuse the mobile screenshot I’m at work…
Messing around a little last night I get a curl command to return the xml file so i thought maybe urllib was out of date but I updated it with no change to result
Yeah - regarding the URLLib bit - that’s where my head was at, but you are on Python 3.7 - so assumed you were up to date.
I originally wrote a script which used Curl & xmllint and then used bash to pull it all together. But when I ran it through HA, it couldn’t find the Curl / xmllint at run time - so I moved it to Python instead.
So I suppose that could be another way of doing it?
Also… I’ve noticed that the namespaces you have for the XML file are subtly different, so the script would need to be updated as well. But, I don’t think that error message (which is on the urlopen) would cause that problem.
This is when I tried using scrape and command line with XML and failed:
Thats what I got, which forced my hand to switch to Python.
I got this working in the latest HA docker image which is based on Alpine. No official ink package for apk.
bash-5.0# apk add ink
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
ink (missing):
required by: world[ink]
So what that means is you have to either build the package yourself or build from source.
This will require you to compose your own docker image.
You can download the latest source tar’s here… Put these in a location that you will copy over into the building of the image.
For me I used a /tmp folder in my HA configuration directory.
wget http://downloads.sourceforge.net/ink/ink-0.5.3.tar.gz
wget http://downloads.sourceforge.net/libinklevel/libinklevel-0.9.3.tar.gz
In your docker-compose file…
ENV LOCAL_HOMEASSISTANT_TMP=/config/tmp
COPY ink-0.5.3.tar.gz $LOCAL_HOMEASSISTANT_TMP
COPY libinklevel-0.9.3.tar.gz $LOCAL_HOMEASSISTANT_TMP
RUN set -e && \
apk update && \
apk upgrade && \
apk add --no-cache libusb-dev coreutils perl alpine-sdk imagemagick openssh-client curl vim jq && \
This will install a dependency that is needed ‘libusb-dev’. It also adds in basic development tools as well as some other stuff I use. Remove whatever packages you do not need.
You cannot compile the source files during image build. At least I have not found a way. So unfortunately you will have to do this manually after the image is up.
This is done via two shell scripts. You can do it in one but I split it up to be organized.
libinklevel.sh
#!/bin/bash
cd /docker/homeassistant/tmp
tar xzf libinklevel-0.9.3.tar.gz
cd libinklevel-0.9.3
./configure
make
make install
And
ink.sh
#!/bin/bash
cd /docker/homeassistant/tmp
tar xzf ink-0.5.3.tar.gz
cd ink-0.5.3
./configure
make
make install
I put each of these into a folder under the HA config directory called /bash_scripts. Make sure to make each of those scripts executable. chmod +x script.sh
Once the container is up and running do this…
sudo docker exec <container_name> /bin/bash /config/bash_scripts/libinklevel.sh
sudo docker exec <container_name> /bin/bash /config/bash_scripts/ink.sh
That should get you ink working on the latest alpine based HA image.
Working, Thank you men.
Got it working, although, had to change
output = “”
` to
output = “{”
on line 16 of the python script.
Thanks a lot.
The Hassio Addon ( https://github.com/james-fry/hassio-addons ) is working fine with my Canon MG6400 series Inkjet.
Thanks everybody - this has helped me pluck up the courage to delve into MQTT and Lovelace custom addons which have been dark arts to me so far!!
Great jg.balcombe! But why don’t we just grab it with a command_line sensor?
sensor:
- platform: command_line
name: printer_color
scan_interval: 21600
command: curl -s http://192.168.0.23/DevMgmt/ConsumableConfigDyn.xml | grep -m1 'dd:ConsumablePercentageLevelRemaining' | sed 's/\s*<.*>\(.*\)<.*>/\1/'
- platform: command_line
name: printer_black
scan_interval: 21600
command: curl -s http://192.168.0.23/DevMgmt/ConsumableConfigDyn.xml | grep "dd:ConsumablePercentageLevelRemaining" | sed 's/\s*<.*>\(.*\)<.*>/\1/' | tail +2
- platform: command_line
name: printer_status
scan_interval: 10
command: curl -s http://192.168.0.23/DevMgmt/ProductStatusDyn.xml | grep "pscat:StatusCategory" | sed 's/\s*<.*>\(.*\)<.*>/\1/' | tail +2
- platform: template
sensors:
printer_status_template:
value_template: >-
{% if is_state("sensor.printer_status", "ready") %}
On
{% elif is_state("sensor.printer_status", "inPowerSave") %}
Idle
{% elif is_state("sensor.printer_status", "processing") %}
Printing
{% elif is_state("sensor.printer_status", "") %}
Off
{% else %}
{{ states.sensor.printer_status.state }}
{% endif %}
And it seems like even the printers web server fetches from the xml file
Hi - perfectly fine. At the start of this, I mentioned this was just a hack to get to the information - as previously people were trying to use SNMP to access the levels which weren’t showing.
Lots of good ways to do this, you’ve just shown another.
In fact there’s a thread about a HP Ink level component now, which seems to handle this printer (and others). I actually use that now - as it simplifies my config.
At the end of the day - it’s personal preference.
Regards,
James.
When I incorporated this I didn’t get the ink drop above the percent like was shown earlier in this thread. What makes that show or not? Do you have to define the icon on the entity itself?
With the newest bar-card you’ll need to update your lovelace card for the ink levels like so:
direction: up
entities:
- color: MediumTurquoise
entity: sensor.ink_cyan
- color: MediumOrchid
entity: sensor.ink_magenta
- color: Gold
entity: sensor.ink_yellow
- color: Black
entity: sensor.ink_black
- color: Black
entity: sensor.ink_photoblack
height: 200px
positions:
icon: inside
title: outside
max: 100
min: 0
padding: 2px
target: 20
type: 'custom:bar-card'
unit_of_measurement: '%'
stack: horizontal
title: Canon MX920 Printer Ink
style: |-
bar-card-title {
text-shadow: 1px 1px 5px black;
}
bar-card-value {
text-shadow: 1px 1px 5px black;
}
Sorry but no idea really
Maybe a ha update broke one of the custom cards? Check for updates for the cards
Read my post for the updated format.