Seven segments display


The seven_segments image processing platform allows you to read physical seven segments displays through Home Assistant. ssocr is used to extract the value shown on the display which is observed by a camera.

If you are using Hass.io then just move forward to the configuration as all requirements are already fulfilled.

ssocr needs to be available on your system. Check the installation instruction below:

$ sudo dnf -y install imlib2-devel # Fedora
$ sudo apt install libimlib2-dev # Ubuntu
$ brew install imlib2 # macOS
$ git clone https://github.com/auerswal/ssocr.git
$ cd ssocr
$ make
$ sudo make PREFIX=/usr install # On most systems
$ make deb # (Optional) This allows you to make a deb so that you apt is aware of ssocr

To enable the OCR of a seven segment display in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
image_processing:
  - platform: seven_segments
    source:
      - entity_id: camera.seven_segments

Configuration Variables

ssocr_bin

(string)(Optional)The command line tool ssocr. Set it if you use a different name for the executable.

Default value: ssocr

x_position

(integer)(Optional)X coordinate of the upper left corner of the area to crop.

Default value: 0

y_position

(integer)(Optional)Y coordinate of the upper left corner of the area to crop.

Default value: 0

height

(integer)(Optional)Height of the area to crop.

Default value: 0

width

(integer)(Optional)Width of the area to crop.

Default value: 0

rotate

(integer)(Optional)Rotation of the image.

Default value: 0

threshold

(integer)(Optional)Threshold for the difference between the digits and the background.

Default value: 0

digits

(integer)(Optional)Number of digits in the display.

Default value: -1

extra_arguments

(string)(Optional)Other arguments to use. Like -D, dilation, erosion, greyscale, make_mono, etc.

source

(list)(Required)List of image sources.

entity_id

(string)(Required)A camera entity id to get picture from.

name

(string)(Optional)This parameter allows you to override the name of your image_processing entity.

Setup process

It’s suggested that the first attempt to determine the needed parameters is using ssocr directly. This may require a couple of iterations to get the result

$ ssocr -D erosion crop 390 250 490 280 -t 20 -d 4 seven-seg.png

This would lead to the following entry for the configuration.yaml file:

camera:
  - platform: local_file
    file_path: /home/homeassistant/.homeassistant/seven-seg.png
    name: seven_segments
image_processing:
  - platform: seven_segments
    x_position: 390
    y_position: 250
    height: 280
    width: 490
    threshold: 20
    digits: 4
    source:
      - entity_id: camera.seven_segments

With the help of a template sensor, the value can be shown as badge.

sensor:
  - platform: template
    sensors:
      power_meter:
        value_template: '{{ states.image_processing.sevensegment_ocr_seven_segments.state }}'
        friendly_name: 'Ampere'
        unit_of_measurement: 'A'