diff --git a/src/panels/developer-tools/template/developer-tools-template.ts b/src/panels/developer-tools/template/developer-tools-template.ts
index b21abece9f..fe0a0c158c 100644
--- a/src/panels/developer-tools/template/developer-tools-template.ts
+++ b/src/panels/developer-tools/template/developer-tools-template.ts
@@ -10,6 +10,7 @@ import {
RenderTemplateResult,
subscribeRenderTemplate,
} from "../../../data/ws-templates";
+import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
import { haStyle } from "../../../resources/styles";
import { HomeAssistant } from "../../../types";
import { documentationUrl } from "../../../util/documentation-url";
@@ -142,6 +143,9 @@ class HaPanelDevTemplate extends LitElement {
"ui.panel.developer-tools.tabs.templates.reset"
)}
+
+ ${this.hass.localize("ui.common.clear")}
+
@@ -378,11 +382,42 @@ class HaPanelDevTemplate extends LitElement {
localStorage["panel-dev-template-template"] = this._template;
}
- private _restoreDemo() {
+ private async _restoreDemo() {
+ if (
+ !(await showConfirmationDialog(this, {
+ text: this.hass.localize(
+ "ui.panel.developer-tools.tabs.templates.confirm_reset"
+ ),
+ warning: true,
+ }))
+ ) {
+ return;
+ }
this._template = DEMO_TEMPLATE;
this._subscribeTemplate();
delete localStorage["panel-dev-template-template"];
}
+
+ private async _clear() {
+ if (
+ !(await showConfirmationDialog(this, {
+ text: this.hass.localize(
+ "ui.panel.developer-tools.tabs.templates.confirm_clear"
+ ),
+ warning: true,
+ }))
+ ) {
+ return;
+ }
+ this._unsubscribeTemplate();
+ this._template = "";
+ // Reset to empty result. Setting to 'undefined' results in a different visual
+ // behaviour compared to manually emptying the template input box.
+ this._templateResult = {
+ result: "",
+ listeners: { all: false, entities: [], domains: [], time: false },
+ };
+ }
}
declare global {
diff --git a/src/translations/en.json b/src/translations/en.json
index 883659695f..4479abbf2d 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -5348,6 +5348,8 @@
"description": "Templates are rendered using the Jinja2 template engine with some Home Assistant specific extensions.",
"editor": "Template editor",
"reset": "Reset to demo template",
+ "confirm_reset": "Do you want to reset your current template back to the demo template?",
+ "confirm_clear": "Do you want to clear your current template?",
"result_type": "Result type",
"jinja_documentation": "Jinja2 template documentation",
"template_extensions": "Home Assistant template extensions",