Repository navigation
Numbers as pictures with AppDaemon
The card's image part shows a picture of Home Assistant's own where a value would stand. To show a count larger
than the screen's largest digits, something has to draw the number as a picture. The plugin's
examples/value-image does that
as a small service on a machine of its own. If you already run the AppDaemon app in Home Assistant, it can do the
same with no extra machine: AppDaemon's web server answers the address, and Home Assistant reaches it over its
internal network.
This page is a recipe, not part of the plugin. It was tested on a 7-inch Guition screen with AppDaemon 4.5.
Home Assistant 2026.11 and newer. The recipe stays the same. The app is two files you put into AppDaemon's
folder yourself; neither HACS nor the Marketplace that replaces it in 2026.11 installs or updates it (the Marketplace
installs no AppDaemon apps at all). AppDaemon itself comes from the Apps page as before. A new version of the app is
a new version of this page: copy value_image.py again.
Settings > Apps > AppDaemon > Configuration: add Pillow under python_packages, save and restart AppDaemon.
Its log says when Pillow is installed.
The app's Info page shows its hostname, usually a0d7b954-appdaemon. You need it below.
AppDaemon's apps are in /addon_configs/a0d7b954_appdaemon/apps/. Roboto Bold is the face of Tessera's digits; Tessera
ships it (SIL Open Font License):
curl -fsSL -o /addon_configs/a0d7b954_appdaemon/apps/Roboto-Bold.ttf \
https://raw.githubusercontent.com/MaxGramser/homeassistant_espscreen/main/fonts/Roboto-700.ttfNext to it, value_image.py:
"""A number as a picture, served by AppDaemon, for Tessera's custom card (its `image` part).
AppDaemon's web server answers http://<appdaemon>:5050/app/value_image?text=5.358&ink=300 with the text in Roboto
Bold, Tessera's blue, on a transparent ground, tight around its ink. A template image in Home Assistant fetches it.
Nothing is read or stored: the address alone decides the picture.
"""
import asyncio
import io
import os
from aiohttp import web
from PIL import Image, ImageDraw, ImageFont
import appdaemon.plugins.hass.hassapi as hass
COLORS = {'accent': '0A93D2', 'ink': 'DADADA'} # Tessera's theme.h, dark values
MAX_SIDE, MAX_TEXT = 2048, 32
def rgb(value):
value = COLORS.get(value, value).lstrip('#')
if len(value) != 6:
raise ValueError('colour')
return tuple(int(value[i:i + 2], 16) for i in (0, 2, 4))
def render_tight(font_path, text, ink, color='accent'):
"""The PNG bytes of `text` with its ink `ink` pixels high and no margin: the card decides the size."""
if not 8 <= ink <= MAX_SIDE or not 0 < len(text) <= MAX_TEXT:
raise ValueError('size')
lo, hi = 4, ink * 3
while lo < hi: # the size whose ink is `ink` high
mid = (lo + hi + 1) // 2
left, top, right, low = ImageFont.truetype(font_path, mid).getbbox(text)
if low - top <= ink:
lo = mid
else:
hi = mid - 1
font = ImageFont.truetype(font_path, lo)
left, top, right, low = font.getbbox(text)
if right - left > MAX_SIDE:
raise ValueError('size')
image = Image.new('RGBA', (right - left, low - top), (0, 0, 0, 0))
ImageDraw.Draw(image).text((-left, -top), text, font=font, fill=rgb(color) + (255,))
out = io.BytesIO()
image.save(out, 'PNG', optimize=True)
return out.getvalue()
class ValueImage(hass.Hass):
async def initialize(self):
self.font = self.args.get('font') or os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Roboto-Bold.ttf')
if not os.path.exists(self.font):
self.log(f'No font at {self.font}: put Roboto-Bold.ttf there, or give `font:` in apps.yaml', level='ERROR')
route = self.args.get('route', 'value_image')
await self.register_route(self.serve, route)
self.log(f'Serving numbers as pictures at /app/{route}')
async def serve(self, request, kwargs):
q = request.query
try:
png = await asyncio.get_running_loop().run_in_executor(
None, render_tight, self.font, q.get('text', ''), int(q.get('ink', 300)), q.get('color', 'accent'))
except (ValueError, OSError) as error:
return web.Response(status=400, text=str(error))
return web.Response(body=png, content_type='image/png', headers={'Cache-Control': 'no-store'})And in apps.yaml of the same folder:
value_image:
module: value_image
class: ValueImageAppDaemon's log then says Serving numbers as pictures at /app/value_image.
- If the
http:block ofappdaemon.yamlhasurl: http://127.0.0.1:5050and Home Assistant cannot reach the picture (step 3), change it tohttp://0.0.0.0:5050and restart AppDaemon. - A password under
http:keeps Home Assistant out: a template image cannot send one.
In configuration.yaml under template::
- image:
- name: Count scanned
unique_id: count_scanned
default_entity_id: image.count_scanned
verify_ssl: false
url: >-
http://a0d7b954-appdaemon:5050/app/value_image?ink=300&text={{
'{:,}'.format(states('sensor.entrance_scanned') | int(0)) | replace(',', '.') }}Check the configuration and reload the template entities. Developer tools > States > image.count_scanned shows the number in blue when Home Assistant reaches AppDaemon.
Give the image no trigger of its own: the picture and the card's mark have to change at the same moment. Tessera's app keeps a picture by its address, and the mark is in the address, so a mark that changes before its picture keeps the old picture under the new mark. To make a busy counter change less often, slow down what both read.
In the card's template sensor, the part names the image entity without image., with the same number as its mark:
elements: >
{% set s = states('sensor.entrance_scanned') | int(0) %}
{{ [
'image|' ~ ('{:,}'.format(s) | replace(',', '.')) ~ '|count_scanned|Scanned',
'value|' ~ states('sensor.entrance_valid') ~ '||Valid'
] }}A wide tile (3x2, 4x2) gives the largest numbers, and the card a tap opens shows them larger still. Where there are
no pictures (a board without the memory for them), the mark stands as a value. The image part needs custom card
0.7.0 and Tessera 0.4.89 or later.
/app/value_image takes text (up to 32 characters), ink (the height of the digits in pixels, 300 is plenty for a
7-inch screen; the card scales the picture down to its place) and color (accent, Tessera's blue, the default;
ink, light grey; or a hex colour such as ffffff).