4.1.0 - Templating Overhaul and A New Action
Templating Overhaul and A New Action
Templating Overhaul
Technical Info Dump
Home Assistant's templating is powered by jinja2, a templating engine for Python. Traditional frontend templates in Home Assistant are sent from the frontend to the backend core, where they are processed and then sent back to the frontend. This entire process can take up to a second or more, which can cause frontend elements to appear incorrect for few seconds on page load or when entities change. If you use templates in card-mod styles on other cards or themes you've probably experienced this.
To eliminate the latency of templates being processed in the backend, I developed ha-nunjucks
- an alternate synchronous instantaneous frontend only templating system for Home Assistant. Nunjucks is a templating engine for JavaScript maintained by Mozilla that is heavily inspired by jinja2 and shares the same syntax with very few exceptions. With ha-nunjucks
templates can be processed instantaneously before your dashboard renders! But there's a catch - all Home Assistant template extensions had to be reimplemented in ha-nunjucks
. When I initially developed ha-nunjucks
, I only included a handful of extensions like states and attributes, leading to many questions from users as to why things like datetime functions weren't working.
Parity With Backend Templates
As of ha-nunjucks
1.3.0 I've reimplemented almost all of the template extensions listed on the Home Assistant templating page. This includes datetime extensions, courtesy of ts-py-datetime. All but a few obscure templating extensions have been reimplemented in ha-nunjucks
. See the ha-nunjucks
documentation for more information on how to use all of the new template extensions. While the syntax is mostly the same, there were some limitations I had to work around which may cause slightly different behavior for some of the extensions.
New Action - Evaluate JS
You can now execute JavaScript as an action using Evaluate JS
. This action calls the eval
function on a code string you write, and can be used to execute blocks of JavaScript code.
Other Changes
- Confirmation failure triggers a value and render update, which helps reset styles on action cancellation.
- Confirmation haptics now fire when box appears.
- Added more sources using the HA-Firemote launcher list #127 #144.
Full Changelog: 4.0.6...4.1.0