Différences
Ci-dessous, les différences entre deux révisions de la page.
| domotique:creer_un_graphique_personnalise_avec_le_plugin_htmldisplay [2026/07/11 11:44] – créée fate | domotique:creer_un_graphique_personnalise_avec_le_plugin_htmldisplay [2026/07/11 12:06] (Version actuelle) – fate | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Créer un graphique HP/HC + Prix avec htmldisplay dans Jeedom ====== | ====== Créer un graphique HP/HC + Prix avec htmldisplay dans Jeedom ====== | ||
| - | Voici un tuto permettant | + | J' |
| - | + | Je récupère ces information via l'excellent | |
| - | Ce tuto va permettre de : | + | |
| - | * Visualiser la répartition **HP/HC** sous forme de colonnes empilées. | + | |
| - | * Afficher le **prix** sur un axe secondaire (à droite). | + | |
| - | * Récupérer automatiquement les données depuis | + | |
| - | + | ||
| - | L'installation et la configuration du plugin **htmldisplay** ne seront pas détaillées ici. Vous devez avoir **Highcharts** accessible (via CDN ou hébergement local). | + | |
| - | + | ||
| - | --- | + | |
| ===== 1) Prérequis ===== | ===== 1) Prérequis ===== | ||
| Ligne 16: | Ligne 8: | ||
| Vous aurez besoin de : | Vous aurez besoin de : | ||
| * Plugin **htmldisplay** installé et activé. | * Plugin **htmldisplay** installé et activé. | ||
| - | * **3 commandes Jeedom** configurées avec un historique valide : | + | * Plugin |
| * **Heures Pleines (HP)** (ex: cmd_id **1800**) | * **Heures Pleines (HP)** (ex: cmd_id **1800**) | ||
| * **Heures Creuses (HC)** (ex: cmd_id **1801**) | * **Heures Creuses (HC)** (ex: cmd_id **1801**) | ||
| * **Prix** (ex: cmd_id **1832**) | * **Prix** (ex: cmd_id **1832**) | ||
| - | --- | + | Pour ces 3 commandes, vous devez configurer l' |
| + | |||
| + | {{.: | ||
| + | |||
| + | Si vous voulez faire un graphique sur une période différente, | ||
| ===== 2) Création de l’équipement htmldisplay ===== | ===== 2) Création de l’équipement htmldisplay ===== | ||
| ==== Étape 1 : Ajouter un équipement ==== | ==== Étape 1 : Ajouter un équipement ==== | ||
| - | 1. Allez dans **Plugins → Protocole DOM → htmldisplay**. | + | 1. Allez dans **Plugins → Programmation |
| - | 2. Cliquez sur **"Ajouter | + | 2. Cliquez sur **Ajouter**. |
| 3. Donnez-lui un nom explicite (ex: **" | 3. Donnez-lui un nom explicite (ex: **" | ||
| 4. Associez-le à un objet parent (ex: **" | 4. Associez-le à un objet parent (ex: **" | ||
| ==== Étape 2 : Configurer le code HTML ==== | ==== Étape 2 : Configurer le code HTML ==== | ||
| - | Dans l’onglet **" | + | Dans l’onglet **" |
| - | **Remplacez | + | **Remplacez |
| <code html> | <code html> | ||
| Ligne 39: | Ligne 35: | ||
| <html lang=" | <html lang=" | ||
| < | < | ||
| - | <meta charset=" | + | <meta charset=" |
| - | <script src=" | + | |
| - | < | + | |
| - | .highcharts-title { font-size: 22px !important; } | + | |
| - | .highcharts-xaxis-labels text, | + | |
| - | .highcharts-yaxis-labels text { font-size: 18px !important; } | + | |
| - | .highcharts-axis-title { font-size: 18px !important; } | + | |
| - | .highcharts-tooltip text { font-size: 16px !important; } | + | |
| - | .highcharts-legend-item text { font-size: 16px !important; } | + | |
| - | </style> | + | |
| </ | </ | ||
| + | |||
| < | < | ||
| + | |||
| <div id=" | <div id=" | ||
| + | |||
| + | < | ||
| + | .highcharts-title { | ||
| + | font-size: 22px !important; | ||
| + | } | ||
| + | .highcharts-xaxis-labels text, | ||
| + | .highcharts-yaxis-labels text { | ||
| + | font-size: 20px !important; | ||
| + | } | ||
| + | .highcharts-axis-title { | ||
| + | font-size: 20px !important; | ||
| + | } | ||
| + | .highcharts-tooltip text { | ||
| + | font-size: 20px !important; | ||
| + | } | ||
| + | .highcharts-legend-item text { | ||
| + | font-size: 20px !important; | ||
| + | } | ||
| + | </ | ||
| < | < | ||
| - | // ===== UTILITAIRES ===== | + | // Date du jour au format YYYY-MM-DD |
| function getTodayDate() { | function getTodayDate() { | ||
| - | | + | |
| + | return d.toISOString().split(' | ||
| } | } | ||
| + | |||
| + | // Date X jours avant aujourd' | ||
| function getDateMinusDays(days) { | function getDateMinusDays(days) { | ||
| - | const d = new Date(); d.setDate(d.getDate() - days); | + | const d = new Date(); |
| + | | ||
| return d.toISOString().split(' | return d.toISOString().split(' | ||
| } | } | ||
| - | // ===== INITIALISATION ===== | + | // Initialisation auto |
| - | setTimeout(() => chargerDonnees_# | + | setTimeout(() => { |
| + | | ||
| + | }, 100); | ||
| function chargerDonnees_# | function chargerDonnees_# | ||
| - | const dateEnd | + | |
| - | const dateStart | + | |
| - | let timestamps = [], hp = [], hc = [], prix = []; | + | |
| - | let loaded | + | const dateStartStr |
| + | |||
| + | let timestamps = []; | ||
| + | let hp_jour | ||
| + | let hc_jour | ||
| + | let price_jour | ||
| + | let chargements | ||
| + | |||
| + | function essayerAfficherGraphique_# | ||
| + | if (chargements < 3) return; | ||
| + | |||
| + | // On suppose que les séries partagent les mêmes dates et le même ordre | ||
| + | const hp_series | ||
| + | const hc_series | ||
| + | const price_series= timestamps.map((ts, | ||
| - | function renderChart() { | ||
| - | if (loaded < 3) return; | ||
| Highcharts.chart(' | Highcharts.chart(' | ||
| - | chart: { | + | chart: { type: ' |
| - | | + | title: { text: ' |
| - | backgroundColor: | + | |
| - | | + | |
| - | title: { | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| xAxis: { | xAxis: { | ||
| type: ' | type: ' | ||
| - | labels: { format: ' | + | labels: { format: ' |
| }, | }, | ||
| + | |||
| yAxis: [{ | yAxis: [{ | ||
| + | // Axe gauche : kWh | ||
| min: 0, | min: 0, | ||
| title: { text: ' | title: { text: ' | ||
| }, { | }, { | ||
| + | // Axe droit : € (le prix reste en colonne comme avant) | ||
| min: 0, | min: 0, | ||
| title: { text: 'Prix (€)' }, | title: { text: 'Prix (€)' }, | ||
| opposite: true | opposite: true | ||
| }], | }], | ||
| + | |||
| tooltip: { | tooltip: { | ||
| - | xDateFormat: | + | xDateFormat: |
| shared: true | shared: true | ||
| }, | }, | ||
| + | |||
| plotOptions: | plotOptions: | ||
| column: { | column: { | ||
| - | grouping: true, // Regroupe les colonnes (HP, HC, Prix) | + | grouping: true, // conserve la barre prix à côté |
| - | stacking: ' | + | stacking: ' |
| } | } | ||
| }, | }, | ||
| + | |||
| series: [ | series: [ | ||
| { | { | ||
| name: ' | name: ' | ||
| - | data: timestamps.map((t, | + | data: hp_series, |
| - | color: '# | + | color: '# |
| yAxis: 0, | yAxis: 0, | ||
| - | stack: ' | + | stack: ' |
| }, | }, | ||
| { | { | ||
| name: ' | name: ' | ||
| - | data: timestamps.map((t, | + | data: hc_series, |
| - | color: '# | + | color: '# |
| yAxis: 0, | yAxis: 0, | ||
| stack: ' | stack: ' | ||
| Ligne 122: | Ligne 149: | ||
| { | { | ||
| name: 'Prix (€)', | name: 'Prix (€)', | ||
| - | data: timestamps.map((t, | + | data: price_series, |
| color: '# | color: '# | ||
| yAxis: 1 | yAxis: 1 | ||
| + | // type laissé à ' | ||
| } | } | ||
| - | ], | + | ] |
| - | credits: { enabled: false } | + | |
| }); | }); | ||
| } | } | ||
| - | | + | // 1) Heures |
| - | | + | |
| jeedom.history.get({ | jeedom.history.get({ | ||
| cmd_id: 1800, | cmd_id: 1800, | ||
| - | dateStart: | + | dateStart: |
| - | dateEnd: | + | dateEnd: |
| - | success: function(result) { | + | success: function (result) { |
| - | timestamps = result.data.map(d => new Date(d[0]).getTime()); | + | console.log(" |
| - | hp = result.data.map(d => d[1]); | + | |
| - | | + | timestamps = []; |
| - | | + | hp_jour = []; |
| + | |||
| + | for (let i = 0; i < result.data.length; i++) { | ||
| + | const d = new Date(result.data[i][0]); | ||
| + | timestamps.push(d.getTime()); | ||
| + | | ||
| + | } | ||
| + | |||
| + | | ||
| + | | ||
| } | } | ||
| }); | }); | ||
| - | // 2) Heures | + | // 2) Heures |
| jeedom.history.get({ | jeedom.history.get({ | ||
| cmd_id: 1801, | cmd_id: 1801, | ||
| - | dateStart: | + | dateStart: |
| - | dateEnd: | + | dateEnd: |
| - | success: function(result) { | + | success: function (result) { |
| - | | + | |
| - | | + | |
| - | | + | hc_jour |
| + | |||
| + | for (let i = 0; i < result.data.length; i++) { | ||
| + | hc_jour.push(result.data[i][1]); // kWh | ||
| + | } | ||
| + | |||
| + | | ||
| + | | ||
| } | } | ||
| }); | }); | ||
| - | // 3) Prix (€) | + | // 3) Prix € (cmd 1832) |
| jeedom.history.get({ | jeedom.history.get({ | ||
| cmd_id: 1832, | cmd_id: 1832, | ||
| - | dateStart: | + | dateStart: |
| - | dateEnd: | + | dateEnd: |
| - | success: function(result) { | + | success: function (result) { |
| - | | + | |
| - | | + | |
| - | | + | price_jour |
| + | |||
| + | for (let i = 0; i < result.data.length; i++) { | ||
| + | price_jour.push(result.data[i][1]); // € | ||
| + | } | ||
| + | |||
| + | | ||
| + | | ||
| } | } | ||
| }); | }); | ||
| } | } | ||
| </ | </ | ||
| + | |||
| </ | </ | ||
| </ | </ | ||
| </ | </ | ||