Template cookbook

Show anything from Home Assistant on your display

The Entity Status widget can show the result of a Home Assistant template: a sentence built from your sensors, like “Washer: Idle for 2 hr”. You do not need to know how to write one. Start with the helper buttons, or copy a recipe below.

Where it goes

Five ideas that cover almost everything

1

Show a value

Put the device’s id in quotes inside states(). Add its unit if it has one.

{{ states('sensor.living_temp') }} {{ state_attr('sensor.living_temp', 'unit_of_measurement') }}

Shows: 21.5 °C

2

Show how long it has been that way

time_since() turns the moment a device last changed into words. The 2 means two units, like 1 hour 5 minutes.

{{ time_since(states.sensor.washer.last_changed, 2) }}

Shows: 2 hours 5 minutes

3

Say one thing or another

An if chooses between two messages. Every if needs an endif at the end.

{% if is_state('binary_sensor.front_door', 'on') %}Front door is open{% else %}Front door is closed{% endif %}

Shows: Front door is closed

4

Tidy a number or a word

float turns text into a number and round trims it. title capitalises a word.

{{ states('sensor.living_temp') | float(0) | round(0) }} {{ states('sensor.washer') | title }}

Shows: 22 Idle

5

Count things

Count every light that is on, or every door that is open, in the whole house.

{{ states.light | selectattr('state', 'eq', 'on') | list | count }}

Shows: 3

Put two stars on each side of words to make them bold, like **Idle**. A new line in the box is a new line on the display.

Recipes to copy

Change the device names in the code to your own. The Step by step helper and the Inspect button will find them for you.

Washer and dryer

Two machines, how long each has been in its state, and a reminder to move the laundry along.

Washer: **{{ states('sensor.washer') | title }}** for {{ time_since(states.sensor.washer.last_changed, 2) }} Dryer: **{{ states('sensor.dryer') | title }}** for {{ time_since(states.sensor.dryer.last_changed, 2) }} {% if is_state('sensor.washer', 'idle') and is_state('sensor.dryer', 'idle') %}All done, nothing to swap{% elif is_state('sensor.washer', 'idle') %}Move the wet laundry to the dryer!{% endif %}

Garage door

The door’s state and how long it has been that way.

Garage: **{{ states('cover.garage_door') | title }}** for {{ time_since(states.cover.garage_door.last_changed, 2) }}

Doors open

How many doors are open right now.

Doors open: **{{ states.binary_sensor | selectattr('attributes.device_class', 'eq', 'door') | selectattr('state', 'eq', 'on') | list | count }}**

Lights on

How many lights are on in the house.

Lights on: **{{ states.light | selectattr('state', 'eq', 'on') | list | count }}**

Who is home

The names of everyone Home Assistant says is home, or “Nobody”.

Home now: **{{ states.person | selectattr('state', 'eq', 'home') | map(attribute='name') | join(', ') or 'Nobody' }}**

Temperature and humidity

Two sensors on one line, rounded.

**{{ states('sensor.living_temp') | float(0) | round(1) }}°** · **{{ states('sensor.living_hum') | float(0) | round(0) }}%**

A yes or no message

Say one thing while something is on and another when it is off.

**{% if is_state('switch.dishwasher', 'on') %}Dishwasher is running{% else %}Dishwasher is done{% endif %}**

A reminder from a number

Compare a sensor with a limit and show a reminder when it is crossed.

{% if states('sensor.plant_moisture') | float(0) < 30 %}Water the plant!{% else %}Plant is fine ({{ states('sensor.plant_moisture') }}%){% endif %}

If something goes wrong

It shows “unknown” or “unavailable”

The device id is not quite right, or the device is offline in Home Assistant. The helper under the box names any id that Home Assistant does not have and suggests the closest one.

I get an error about a }, an endif, or a filter

The helper explains Home Assistant’s errors in plain English. The usual causes are a missing } or %}, an if without its endif, or a misspelled word after a | .

How often does it update?

The display asks Home Assistant again about every 8 seconds, so a change shows within roughly 10 to 15 seconds.

How do I find a device’s id?

Use the Insert or Inspect buttons: they list your devices with their current values. In Home Assistant the same ids are under Settings → Devices & services → Entities.

Can I use any Home Assistant template?

Yes, anything Home Assistant can render, up to 2,000 characters in and 1,000 out. The only formatting Piazza HQ adds is **bold** and line breaks.

Does my template leave my home?

No. Piazza HQ sends it to your own Home Assistant, which renders it. Nothing goes to piazzahq.com.

Looking to control Piazza HQ from Home Assistant instead? See Home Assistant Control.