Bonjour, ceci est ma première carte, elle me permet de visualiser et interagir avec ma PAC mitsubishi ECODAN. Les entités me viennent du projet Asgard mais vous pouvez utiliser les vôtres. A la création, il faut juste les sélectionner. Il s'agit d'une PAC bizone gérant l'ECS.
On peut suivre l'historique d'à peu près tout ce qui est affiché et on peut changer les consignes.
tuto: mettre le .js et l'image dans votre dossier visible par HA, typiquement www
paramètre, tableau de bord, ressource, ajouter une ressource, pointer vers le .js qui est du javascript, valider, recharger et la carte est opérationnelle. Elle demande de sélectionner toutes les entités, pas de YAML.
Pensez à mettre le chemin de votre image de PAC comme sur la capture d'écran.
Merci pour vos retours et soyez indulgents, c'est ma première participation dans ce topic.
fichier ecodan-synoptic-card.js :
/**
* ecodan-synoptic-card
* Synoptique d'une PAC Mitsubishi Ecodan : image de fond + valeurs
* positionnées en pourcentage de la carte. Entités choisies par l'utilisateur
* (YAML ou éditeur visuel).
*/
// ---------------------------------------------------------------
// 1. Les champs affichables et leur position par défaut
// top / left : % de l'image size : % de la largeur de la carte
// ---------------------------------------------------------------
const R = { left: 92, size: 1.3, right: true }; // colonne de droite
const B = { top: 95, size: 1.2 }; // ligne du bas
const FIELDS = {
outdoor_temp: { top: 16, left: 20, size: 2.2, bold: true },
weather: { top: 18, left: 10, size: 3.5, icon: true },
// Étage (Zone 1) affiché en haut (positions 19, 23, 27)
z1_flow: { ...R, top: 19 },
z1_target: { ...R, top: 23 },
z1_room: { ...R, top: 27 },
// RDC (Zone 2) affiché en bas (positions 45, 49, 53)
z2_flow: { ...R, top: 45 },
z2_target: { ...R, top: 49 },
z2_room: { ...R, top: 53 },
dhw_current: { ...R, top: 71 },
dhw_target: { ...R, top: 76 },
dhw_force: { top: 82, left: 89, size: 3, icon: true },
refrigerant: { top: 84.5, left: 20, size: 1.3, right: true },
mode: { ...B, left: 31 },
compressor: { ...B, left: 43 },
hvac_action: { ...B, left: 55 },
firmware: { ...B, left: 66.5 },
};
// Noms affichés dans l'éditeur visuel
const LABELS = {
image: "Image de fond (ex. /local/PAC4.png)",
max_height: "Hauteur maximale (ex. 80vh ; vide = toute la hauteur disponible)",
outdoor_temp: "Température extérieure",
weather: "Météo actuelle (entité weather)",
z1_flow: "Zone 1 (Étage) – Départ",
z1_target: "Zone 1 (Étage) – Consigne",
z1_room: "Zone 1 (Étage) – Température actuelle",
z2_flow: "Zone 2 (RDC) – Départ",
z2_target: "Zone 2 (RDC) – Consigne",
z2_room: "Zone 2 (RDC) – Température actuelle",
dhw_current: "ECS – Température du ballon",
dhw_target: "ECS – Consigne",
dhw_force: "ECS – Forcer l'ECS (interrupteur)",
refrigerant: "Fluide frigorigène (liquide)",
mode: "Mode de fonctionnement",
compressor: "Fréquence du compresseur",
hvac_action: "Action en cours (entité climate)",
firmware: "Mise à jour du firmware (entité update)",
};
const HVAC_LABELS = {
heating: "Chauffage",
heat: "Chauffage",
cooling: "Refroidissement",
cool: "Refroidissement",
idle: "En attente",
off: "Éteint",
};
// Correspondance des états météo vers les icônes MDI
const WEATHER_ICONS = {
clear_night: "mdi:weather-night",
cloudy: "mdi:weather-cloudy",
exceptional: "mdi:alert-circle-outline",
fog: "mdi:weather-fog",
hail: "mdi:weather-hail",
lightning: "mdi:weather-lightning",
lightning_rainy: "mdi:weather-lightning-rainy",
partlycloudy: "mdi:weather-partly-cloudy",
pouring: "mdi:weather-pouring",
rainy: "mdi:weather-rainy",
snowy: "mdi:weather-snowy",
snowy_rainy: "mdi:weather-snowy-rainy",
sunny: "mdi:weather-sunny",
windy: "mdi:weather-windy",
windy_variant: "mdi:weather-windy-variant"
};
// ---------------------------------------------------------------
// 2. La carte
// ---------------------------------------------------------------
class EcodanSynopticCard extends HTMLElement {
static getConfigElement() {
return document.createElement("ecodan-synoptic-card-editor");
}
static getStubConfig() {
return { image: "", entities: {} };
}
setConfig(config) {
this._config = { ...config, entities: config.entities || {} };
if (!this.shadowRoot) this.attachShadow({ mode: "open" });
this._build();
if (this._hass) this.hass = this._hass;
}
_build() {
const c = this._config;
const maxH = c.max_height || "calc(100vh - var(--header-height, 56px) - 8px)";
const fields = Object.entries(FIELDS)
.filter(([key]) => c.entities[key])
.map(([key, defaults]) => {
const p = { ...defaults, ...(c.positions?.[key] || {}) };
if (p.icon) {
return `<div class="f icon" data-key="${key}"
style="top:${p.top}%;left:${p.left}%;--mdc-icon-size:${p.size}cqw">
<ha-state-icon></ha-state-icon>
</div>`;
}
const cls = ["f", p.right ? "right" : "", p.bold ? "bold" : ""].join(" ");
return `<div class="${cls}" data-key="${key}"
style="top:${p.top}%;left:${p.left}%;font-size:${p.size}cqw"></div>`;
})
.join("");
const image = c.image
? `<img src="${c.image}" alt="">`
: `<div class="hint">Indiquez le chemin de l'image de fond (ex. /local/PAC4.png).</div>`;
this.shadowRoot.innerHTML = `
<style>
ha-card { background: transparent; box-shadow: none; border: none; overflow: hidden; }
.wrap { --ratio: 1.6; --max-h: ${maxH};
width: min(100%, calc(var(--max-h) * var(--ratio))); margin: 0 auto;
position: relative; container-type: inline-size; line-height: 0; }
img { width: 100%; display: block; }
.hint { padding: 24px; line-height: 1.4; color: var(--secondary-text-color); }
.f { position: absolute; color: #fff; white-space: nowrap; line-height: 1;
transform: translate(-50%, -50%); }
.f.right { transform: translate(-100%, -50%); }
.f.bold { font-weight: bold; }
.f { cursor: pointer; }
.f.icon { line-height: 0; }
.f.icon.on { color: var(--ecodan-active-color, #ff9800); }
</style>
<ha-card>
<div class="wrap">${image}${fields}</div>
</ha-card>`;
const img = this.shadowRoot.querySelector("img");
if (img) {
const apply = () => {
if (img.naturalHeight) {
this.shadowRoot
.querySelector(".wrap")
.style.setProperty("--ratio", img.naturalWidth / img.naturalHeight);
}
};
img.addEventListener("load", apply);
if (img.complete) apply();
}
this.shadowRoot.querySelectorAll(".f").forEach((el) => {
const key = el.dataset.key;
// Gestion spécifique pour l'interrupteur dhw_force
if (key === "dhw_force") {
let timer;
let held = false;
el.addEventListener("pointerdown", () => {
held = false;
timer = setTimeout(() => {
held = true;
this._moreInfo(key);
}, 500);
});
["pointerup", "pointerleave", "pointercancel"].forEach((evt) =>
el.addEventListener(evt, () => clearTimeout(timer))
);
el.addEventListener("contextmenu", (ev) => ev.preventDefault());
el.addEventListener("click", () => {
if (!held) this._toggle(key);
});
return;
}
// Gestion de l'appui long pour z1_target, z2_target et dhw_target
if (["z1_target", "z2_target", "dhw_target"].includes(key)) {
let timer;
let held = false;
el.addEventListener("pointerdown", () => {
held = false;
timer = setTimeout(() => {
held = true;
this._moreInfo(key);
}, 500);
});
["pointerup", "pointerleave", "pointercancel"].forEach((evt) =>
el.addEventListener(evt, () => clearTimeout(timer))
);
el.addEventListener("contextmenu", (ev) => ev.preventDefault());
el.addEventListener("click", () => {
if (!held) this._moreInfo(key);
});
return;
}
// Clic simple par défaut
el.addEventListener("click", () => this._moreInfo(key));
});
}
set hass(hass) {
this._hass = hass;
if (!this._config || !this.shadowRoot) return;
this.shadowRoot.querySelectorAll(".f").forEach((el) => {
const key = el.dataset.key;
const stateObj = hass.states[this._config.entities[key]];
if (el.classList.contains("icon")) {
const icon = el.querySelector("ha-state-icon");
icon.hass = hass;
if (key === "weather" && stateObj) {
const customStateObj = {
...stateObj,
attributes: {
...stateObj.attributes,
icon: WEATHER_ICONS[stateObj.state] || stateObj.attributes.icon || "mdi:weather-sunny"
}
};
icon.stateObj = customStateObj;
} else {
icon.stateObj = stateObj;
}
el.classList.toggle("on", stateObj?.state === "on");
return;
}
el.textContent = stateObj ? this._format(hass, key, stateObj) : "—";
});
}
_format(hass, key, stateObj) {
if (key === "hvac_action") {
const action = stateObj.attributes.hvac_action;
return HVAC_LABELS[action] ?? action ?? "—";
}
// Si l'entité est un climate ou water_heater (ou contient un attribut temperature), on force 1 décimale
if (["z1_target", "z2_target", "dhw_target"].includes(key) && stateObj.attributes.temperature !== undefined) {
const temp = parseFloat(stateObj.attributes.temperature);
const unit = stateObj.attributes.unit_of_measurement || hass.config.unit_system.temperature || "";
return `${isNaN(temp) ? stateObj.attributes.temperature : temp.toFixed(1)} ${unit}`.trim();
}
// Formatage général avec gestion de la décimale forcée si c'est un nombre
const val = parseFloat(stateObj.state);
if (!isNaN(val) && (key.includes("temp") || key.includes("flow") || key.includes("current"))) {
const unit = stateObj.attributes.unit_of_measurement ?? "";
return `${val.toFixed(1)} ${unit}`.trim();
}
if (typeof hass.formatEntityState === "function") {
return hass.formatEntityState(stateObj);
}
const unit = stateObj.attributes.unit_of_measurement ?? "";
return `${stateObj.state} ${unit}`.trim();
}
_moreInfo(key) {
this.dispatchEvent(
new CustomEvent("hass-more-info", {
detail: { entityId: this._config.entities[key] },
bubbles: true,
composed: true,
})
);
}
_toggle(key) {
this._hass.callService("homeassistant", "toggle", {
entity_id: this._config.entities[key],
});
}
getCardSize() {
return 6;
}
}
// ---------------------------------------------------------------
// 3. L'éditeur visuel
// ---------------------------------------------------------------
const DOMAINS = {
hvac_action: "climate",
firmware: "update",
dhw_force: "switch",
weather: "weather",
};
const SCHEMA = [
{ name: "image", selector: { text: {} } },
{ name: "max_height", selector: { text: {} } },
...Object.keys(FIELDS).map((key) => ({
name: key,
selector: { entity: DOMAINS[key] ? { domain: DOMAINS[key] } : {} },
})),
];
class EcodanSynopticCardEditor extends HTMLElement {
setConfig(config) {
this._config = config;
this._render();
if (this._form) {
this._form.data = {
image: config.image,
max_height: config.max_height,
...(config.entities || {}),
};
}
}
set hass(hass) {
this._hass = hass;
if (this._form) this._form.hass = hass;
}
_render() {
if (this._form) return;
this._form = document.createElement("ha-form");
this._form.schema = SCHEMA;
this._form.computeLabel = (item) => LABELS[item.name] ?? item.name;
this._form.hass = this._hass;
this._form.addEventListener("value-changed", (ev) => this._changed(ev));
this.appendChild(this._form);
}
_changed(ev) {
const { image, max_height, ...rest } = ev.detail.value;
const entities = Object.fromEntries(
Object.entries(rest).filter(([, value]) => value)
);
this._config = { ...this._config, image, entities };
if (max_height) this._config.max_height = max_height;
else delete this._config.max_height;
this.dispatchEvent(
new CustomEvent("config-changed", {
detail: { config: this._config },
bubbles: true,
composed: true,
})
);
}
}
// ---------------------------------------------------------------
// 4. Enregistrement auprès de Home Assistant
// ---------------------------------------------------------------
customElements.define("ecodan-synoptic-card", EcodanSynopticCard);
customElements.define("ecodan-synoptic-card-editor", EcodanSynopticCardEditor);
window.customCards = window.customCards || [];
window.customCards.push({
type: "ecodan-synoptic-card",
name: "Ecodan Synoptic Card",
description: "Synoptique d'une PAC Mitsubishi Ecodan sur une image de fond",
preview: false,
});


