diff --git a/src/panels/lovelace/components/hui-card-options.ts b/src/panels/lovelace/components/hui-card-options.ts
index f594d313c5..1d7c0431ba 100644
--- a/src/panels/lovelace/components/hui-card-options.ts
+++ b/src/panels/lovelace/components/hui-card-options.ts
@@ -78,6 +78,11 @@ export class HuiCardOptions extends LitElement {
"ui.panel.lovelace.editor.edit_card.move"
)}
+ ${this.hass!.localize(
+ "ui.panel.lovelace.editor.edit_card.duplicate"
+ )}
${this.hass!.localize(
"ui.panel.lovelace.editor.edit_card.delete"
@@ -152,6 +157,17 @@ export class HuiCardOptions extends LitElement {
`;
}
+ private _duplicateCard(): void {
+ const path = this.path!;
+ const cardConfig = this.lovelace!.config.views[path[0]].cards![path[1]];
+ showEditCardDialog(this, {
+ lovelaceConfig: this.lovelace!.config,
+ cardConfig,
+ saveConfig: this.lovelace!.saveConfig,
+ path: [path[0]],
+ });
+ }
+
private _editCard(): void {
showEditCardDialog(this, {
lovelaceConfig: this.lovelace!.config,
diff --git a/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts b/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts
index 28b560b42d..9e8ff26856 100755
--- a/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts
+++ b/src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts
@@ -56,7 +56,7 @@ export class HuiDialogEditCard extends LitElement {
const [view, card] = params.path;
this._viewConfig = params.lovelaceConfig.views[view];
this._cardConfig =
- card !== undefined ? this._viewConfig.cards![card] : undefined;
+ card !== undefined ? this._viewConfig.cards![card] : params.cardConfig;
if (this._cardConfig && !Object.isFrozen(this._cardConfig)) {
this._cardConfig = deepFreeze(this._cardConfig);
}
diff --git a/src/panels/lovelace/editor/card-editor/show-edit-card-dialog.ts b/src/panels/lovelace/editor/card-editor/show-edit-card-dialog.ts
index 13b3214342..fd794affb2 100644
--- a/src/panels/lovelace/editor/card-editor/show-edit-card-dialog.ts
+++ b/src/panels/lovelace/editor/card-editor/show-edit-card-dialog.ts
@@ -1,11 +1,12 @@
import { fireEvent } from "../../../../common/dom/fire_event";
-import { LovelaceConfig } from "../../../../data/lovelace";
+import { LovelaceConfig, LovelaceCardConfig } from "../../../../data/lovelace";
export interface EditCardDialogParams {
lovelaceConfig: LovelaceConfig;
saveConfig: (config: LovelaceConfig) => void;
path: [number] | [number, number];
entities?: string[]; // We can pass entity id's that will be added to the config when a card is picked
+ cardConfig?: LovelaceCardConfig;
}
const importEditCardDialog = () =>
diff --git a/src/translations/en.json b/src/translations/en.json
index 5b770289d5..6528af6d3a 100755
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -1951,6 +1951,7 @@
"add": "Add Card",
"edit": "Edit",
"delete": "Delete Card",
+ "duplicate": "Duplicate Card",
"move": "Move to View",
"options": "More options"
},