Seven segments can't read my UPS screen with different number of digits

Continuing from this post,

I have managed to do what I wanted and everything seems to be fine.
I have setup a usb camera to the raspberry and it points to my UPS screen. I now know the remaining battery through seven_segments component and with the right automation, I have notifications in my phone, informing me of the remaining battery percentage.

One problem I have now, is that seven_segments require a specific number of digits to read.
My UPS has 3 digits when full charged (100%) but only two when discharging (99%).
If I setup 3 digits in my seven_segments setup, then when the number changes, I get a message saying that only two of three digits found and it doesnt return the number.
It works if I set it up with 2 digits, but then when the battery is fully charged and the screen shows 100% then I get this error: Unable to detect value: found too many digits (3)

Sooo… I am trying to come up with a solution here… Anyone?

Use a template sensor.

I already have one. The thing is there is nothing read for the template sensor to work.
This comes straight from the component.
If you set it to read 2 digits and there are 3, then it just doesnt work. Same thing happens if you set it to read 3 digits and there are 2. The result is “unknown”
Here is what it looks like in my screen. I have set this view temporarily to be easier for me to debug.

What is shown in the states dev panel when it is on 100?

Also have you tried -d -1 as an argument to ssocr? The docs say

-d, --number-digits=#    number of digits in image (-1 for auto)

Or simply leave the home assistant config to the default of -1.

Oh my… I never saw that. It was in front of my eyes, yet somehow i passed it!
It is now showing the correct number. But I will test if it reads the correct digits when I get home tonight. I suppose it will work now!
Thank you a lot!

This was my setup

image_processing:
  - platform: seven_segments
    name: UPSBattery
    source:
      - entity_id: camera.laundrysensorcam
    x_position: 110
    y_position: 145
    height: 240
    width: 400
    threshold: 30
    digits : 2
    extra_arguments: dilation 4 -Dupsbat.png invert rotate 3

All I did was to remive the digits argument as the HA docs says it uses -1 by default.

Just to answer to your question the devs panel says “unknown”.
I have the “SevenSegment OCR laundrsensorcam” entity shown in the screenshot for convenience.

Hopefully it doesn’t matter now :slight_smile:

Picking up something from the dead here, but how do you get HA to show what the SSOCR is seeing in a Lovelace entity? IE the 100 in the image above?

I am not sure if this still works, but here it is from my previous post, which I have linked in the beginning:

Just get this file inside HA using a camera view or something.