{"id":5493,"date":"2023-10-28T10:57:18","date_gmt":"2023-10-28T08:57:18","guid":{"rendered":"https:\/\/www.sigalou-domotique.fr\/?p=5493"},"modified":"2026-01-02T16:56:55","modified_gmt":"2026-01-02T14:56:55","slug":"sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique","status":"publish","type":"post","link":"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique","title":{"rendered":"Save the Wallbox charging sessions of an electric vehicle"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<label for=\"ez-toc-cssicon-toggle-item-6aea4d1deddfd\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6aea4d1deddfd\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Je_regarde_les_donnees_recuperees_de_lintegration_Wallbox\" >I look at the data retrieved from the Wallbox integration<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Le_declencheur\" >The trigger<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Les_donnees\" >Data<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Jajoute_lintegration_qui_va_stocker_les_donnees_de_charge\" >I add the integration that will store the load data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Jajoute_un_sensor_detectant_le_debut_de_la_charge\" >I add a sensor detecting the start of the load<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Jajoute_lautomatisation_qui_va_enregistrer_les_donnees\" >I add the automation that will save the data<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Explication_partie_par_partie\" >Explanation part by part<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Explication_du_code_du_declencheur\" >Explanation of the trigger code\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Explication_de_laction_1\" >Explanation of Action 1\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Explication_de_laction_2\" >Explanation of Action 2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Explication_de_laction_3_%E2%80%93_Principale_action\" >Explanation of Action 3 \u2013 Main Action<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Resultat\" >Result<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Ajout_dune_carte_qui_affiche_toutes_les_sessions_de_charge\" >Added a map that displays all charging sessions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Ajout_dune_carte_qui_affiche_un_recapitulatif_par_annee_mois_semaine\" >Addition of a map showing a summary by year, month, week<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Bonus_Enregistrer_les_donnees_dans_un_fichier_CSV\" >Bonus: Save data to a CSV file<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Jajoute_un_sensor_%C2%AB_file_%C2%BB_qui_correspond_au_fichier_CSV\" >I add a sensor \u2018file\u2019 which corresponds to the CSV file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/sauvegarder-les-sessions-de-charge-wallbox-dun-vehicule-electrique\/#Jajoute_une_action\" >I add an action<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Je_regarde_les_donnees_recuperees_de_lintegration_Wallbox\"><\/span>I look at the data retrieved from the Wallbox integration<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>Here is a small recap of the data that will allow me to save the data from the last charging session in sensor.wallbox _charges.<\/p>\r\n<p>I have already described all the Wallbox integration entities on this Retex:<\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/jintegre-la-wallbox-a-home-assistant\/\" target=\"_blank\" rel=\"noopener\">I integrate the Wallbox into the Home Assistant<\/a><\/li>\r\n<\/ul>\r\n<p><!--more--><\/p>\r\n<h4><span class=\"ez-toc-section\" id=\"Le_declencheur\"><\/span>The trigger<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p>So I'm going to use <a href=\"https:\/\/www.sigalou-domotique.fr\/en\/jintegre-la-wallbox-a-home-assistant\/#Je_decortique_lentite_Wallbox_Portal_Status_Description\" target=\"_blank\" rel=\"noopener\">sensor.wallbox_portal_status_description<\/a> as the trigger for recording the last charging session.<\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/status.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5194\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/status.png\" alt=\"\" width=\"449\" height=\"150\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/status.png 449w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/status-300x100.png 300w\" sizes=\"auto, (max-width: 449px) 100vw, 449px\" \/><\/a><\/p>\r\n<p>I will therefore use the change of status from Charging to something else to trigger the recording.<\/p>\r\n<h4><span class=\"ez-toc-section\" id=\"Les_donnees\"><\/span>Data<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5514\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox8.png\" alt=\"\" width=\"438\" height=\"210\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox8.png 438w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox8-300x144.png 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/a><\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/jintegre-la-wallbox-a-home-assistant\/#Je_decortique_lentite_Wallbox_Portal_Added_Energy\" target=\"_blank\" rel=\"noopener\">Wallbox Portal Added Energy<\/a> (sensor.wallbox_portal_added_energy) will give me the number of kWh added to the car's battery during the last charge<\/li>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/jintegre-la-wallbox-a-home-assistant\/#Je_decortique_lentite_Wallbox_Portal_Added_Range\" target=\"_blank\" rel=\"noopener\">Wallbox Portal Added Range<\/a> (sensor.wallbox_portal_added_range) will give me an estimate of the number of km added that can be achieved with the last load.<\/li>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/jintegre-la-wallbox-a-home-assistant\/#Je_decortique_les_entites_Wallbox_Portal_Max_Available_Power_et_Wallbox_Portal_Max_Charging_Current\" target=\"_blank\" rel=\"noopener\">Wallbox Portal Energy Price<\/a> (sensor.wallbox_portal_energy_price) will give me the price per kWh, I will use it to calculate the cost of the load<\/li>\r\n<\/ul>\r\n<h3><span class=\"ez-toc-section\" id=\"Jajoute_lintegration_qui_va_stocker_les_donnees_de_charge\"><\/span>I add the integration that will store the load data<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>I found the integration <a href=\"https:\/\/github.com\/enkama\/hass-variables\" target=\"_blank\" rel=\"noopener\">hass-variables<\/a>, absolutely great. Thanks to <a href=\"https:\/\/github.com\/enkama\" target=\"_blank\" rel=\"noopener\">Ankama<\/a> and <a href=\"https:\/\/github.com\/Snuffy2\" target=\"_blank\" rel=\"noopener\">Snuffy2<\/a> for this work and follow-up.<\/p>\r\n<p>It allows you to create a sensor that is not connected to anything (not a template). This sensor keeps its values even at the relaunch of HA. Exactly what I needed without using an external data backup mode (json, other \u2026 database).<\/p>\r\n<p><a href=\"https:\/\/my.home-assistant.io\/redirect\/hacs_repository\/?owner=Wibias&amp;repository=hass-variables\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone size-full wp-image-5498\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/config_flow_start.svg\" alt=\"\" \/><\/a><\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5506\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox4.png\" alt=\"\" width=\"292\" height=\"116\" \/><\/a><\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5507\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox5.png\" alt=\"\" width=\"369\" height=\"210\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox5.png 369w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox5-300x171.png 300w\" sizes=\"auto, (max-width: 369px) 100vw, 369px\" \/><\/a><\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5508\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox6.png\" alt=\"\" width=\"368\" height=\"668\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox6.png 368w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox6-165x300.png 165w\" sizes=\"auto, (max-width: 368px) 100vw, 368px\" \/><\/a><\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5509\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox7.png\" alt=\"\" width=\"549\" height=\"220\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox7.png 549w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox7-300x120.png 300w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/a><\/p>\r\n<p>The new sensor is called: sensor.wallbox _charges<\/p>\r\n<h3><span class=\"ez-toc-section\" id=\"Jajoute_un_sensor_detectant_le_debut_de_la_charge\"><\/span>I add a sensor detecting the start of the load<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>Indeed, the integration does not give me the time and start date of the last load. To calculate the duration, I find it interesting to have this information. So I'm going to create it.<\/p>\r\n<p>I rely on the sensor.wallbox _portal _added _range entity and I will fetch the start time\/date of charging (thus its minimum value over the last 5 hours)<\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5515\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox9.png\" alt=\"\" width=\"501\" height=\"336\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox9.png 501w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox9-300x201.png 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/a><\/p>\r\n<p>In my sensors.yaml file, I add this entity:<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">- platform: statistics name: \"Wallbox Portal Added Range Min\" entity_id: sensor.wallbox _portal _added _range state _characteristic: datetime _value _min max_age: hours: 5  <\/pre>\r\n<p>This will create for me the entity: sensor.wallbox _portal _added_range _min<\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5519\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox10.png\" alt=\"\" width=\"503\" height=\"260\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox10.png 503w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox10-300x155.png 300w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/a><\/p>\r\n<p>I will use this entity to record the start of charging and to calculate the charging time.<\/p>\r\n\r\n\r\n\r\n<h3><span class=\"ez-toc-section\" id=\"Jajoute_lautomatisation_qui_va_enregistrer_les_donnees\"><\/span>I add the automation that will save the data<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>It is quite complex, I imagine it is simplifiable, I will explain it step by step<\/p>\r\n<p>Here is the full code first<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">alias: Saves a load session description: \"\" trigger: - platform: state entity _id: - sensor.wallbox_portal_status_description from: Charging to: null alias: When the charge ends condition: [] action: - alias: &gt;- Initialize the first conso, to be launched only once (by disabling the other actions) then disable service: variable.update _sensor data: replace _attributes: true value: INIT attributes: sessionsload: null target: entity_id: sensor.wallbox _charges enabled: false - service: variable.update _sensor data: replace _attributes: true value: &gt;- {{ as_timestamp(states('sensor.wallbox _portal _added_range _min')) | int | timestamp _custom('%d\/%m\/%Y %H:%M:%S', true)}} attributes: sessionsload: &gt; {% set sessioncharge = {'consumption': 2.14, 'cost': 0.43, 'duration': '00:27', 'beginning': '19\/09\/2023 20:36', 'end': '21:03', 'km': 17, 'saved_at': 1695150359} %}{{ sessionload }},{% set sessioncharge = {'consumption': 23.29, 'cost': 4.66, 'duration': '04:19', 'beginning': '21\/09\/2023 21:06', 'end': '01:25', 'km': 192, 'saved_at': 1695323159} %}{{ sessionload }},{% set sessioncharge = {'consumption': 7.68, 'cost': 1.54, 'duration': '01:23', 'beginning': '22\/09\/2023 08:45', 'end': '10:08', 'km': 63, 'saved_at': 1695409559} %}{{ sessionload }},{% set sessioncharge = {'consumption': 23.8, 'cost': 4.76, 'duration': '04:26', 'beginning': '23\/09\/2023 16:57', 'end': '21:23', 'km': 196, 'saved_at': 1695495959} %}{{ sessionload }},{% set sessioncharge = {'consumption': 23.64, 'cost': 4.73, 'duration': '04:05', 'start': '26\/09\/2023 20:59', 'end': '01:04', 'km': 195, 'saved_at': 1695755159} %}{{ sessionload }},{% set sessioncharge = {'consumption': 24.04, 'cost': 4.81, 'duration': '05:17', 'beginning': '28\/09\/2023 21:21', 'end': '02:38', 'km': 198, 'saved_at': 1695927959} %}{{ sessionload }},{% set sessioncharge = {'consumption': 17.3, 'cost': 3.46, 'duration': '03:51', 'beginning': '30\/09\/2023 21:31', 'end': '01:22', 'km': 143, 'saved_at': 1696100759} %}{{ sessionload }},{% set sessioncharge = {'consumption': 22.18, 'cost': 4.44, 'duration': '04:25', 'beginning': '03\/10\/2023 20:43', 'end': '01:08', 'km': 183, 'saved_at': 1696359959} %}{{ sessionload }},{% set sessioncharge = {'consumption': 23.86, 'cost': 4.77, 'duration': '05:26', 'beginning': '05\/10\/2023 21:03', 'end': '02:29', 'km': 197, 'saved_at': 1696532759} %}{{ sessionload }},{% set sessioncharge = {'consumption': 23.43, 'cost': 4.69, 'duration': '05:07', 'beginning': '07\/10\/2023 20:34', 'end': '01:41', 'km': 193, 'saved_at': 1696705559} %}{{ sessionload }},{% set sessioncharge = {'consumption': 23.32, 'cost': 4.66, 'duration': '04:40', 'beginning': '10\/10\/2023 20:57', 'end': '04:40', 'km': 192, 'saved_at': 1696964759} %}{{ sessionload }},{% set sessioncharge = {'consumption': 25.19, 'cost': 5.04, 'duration': '04:39', 'beginning': '12\/10\/2023 19:53', 'end': '00:32', 'km': 208, 'saved_at': 1697137559} %}{{ sessionload }},{% set sessioncharge = {'consumption': 8.61, 'cost': 1.72, 'duration': '01:32', 'beginning': '13\/10\/2023 21:05', 'end': '22:37', 'km': 71, 'saved_at': 1697223959} %}{{ sessionload }},{% set sessioncharge = {'consumption': 27.76, 'cost': 5.55, 'duration': '04:46', 'beginning': '16\/10\/2023 02:11', 'end': '06:57', 'km': 231, 'saved_at': 1697474976} %}{{ sessionload }},{% set sessioncharge = {'consumption': 24.18, 'cost': 4.84, 'duration': '04:12', 'beginning': '18\/10\/2023 02:11', 'end': '06:23', 'km': 201, 'saved_at': 1697657509} %}{{ sessionload }},{% set sessioncharge = {'consumption': 20.17, 'cost': 4.03, 'duration': '03:38', 'beginning': '19\/10\/2023 02:11', 'end': '05:50', 'km': 168, 'saved_at': 1697688628} %}{{ sessionload }},{% set sessioncharge = {'consumption': 23.08, 'cost': 4.62, 'duration': '04:13', 'beginning': '21\/10\/2023 02:12', 'end': '06:25', 'km': 192, 'saved_at': 1697867735} %}{{ sessionload }},{% set sessioncharge = {'consumption': 12.19, 'cost': 2.44, 'duration': '03:21', 'beginning': '22\/10\/2023 02:13', 'end': '05:34', 'km': 101, 'saved_at': 1697946854} %}{{ sessionload }} target: entity_id: sensor.wallbox _charges enabled: false alias: &gt;- Initialize the first conso, to launch only once (by disabling the other actions) then disable - service: variable.update _sensor data: replace _attributes: true value: &gt;- {{ as_timestamp(states('sensor.wallbox _portal _added_range _min')) | int | timestamp _custom('%d\/%m\/%Y %H:%M:%S', true)}} attributes: sessionsload: &gt;- {% set diff_seconds = now().timestamp() - states.sensor.wallbox _portal _added _range _min.state | as_timestamp %} {% set hours = (diff _seconds \/ 3600) | int %} {% set minutes = ((diff_seconds % 3600) \/ 60) | int %} {% set sessioncharge = { 'consumption': states('sensor.wallbox _portal _added _energy') | float | round(2), 'cost': (states('sensor.wallbox _portal _energy _price') | float * states('sensor.wallbox _portal _added _energy') | float | round(2)) | round(2), 'duration': 'd:d' | format(hours, minutes) , 'beginning': as_timestamp(states('sensor.wallbox_portal_added_range_min')) | int | timestamp_custom('%d\/%m\/%Y %H:%M', true), 'end': now().strftime(')%H:%M') , 'km': states('sensor.wallbox _portal _added _range') | int, 'saved_at': now().timestamp() | int } %} {% if state_attr('sensor.wallbox _charges', 'sessionscharge') is not none %} {{ state_attr('sensor.wallbox _charges', 'sessionscharge') }}, {{ sessioncharge }} {% else %} {{ sessionload }}, {{ sessionload }} {% endif %} target: entity_id: sensor.wallbox _charges enabled: true alias: Saves the load session that just ended mode: single\r\n<\/pre>\r\n<p>&nbsp;<\/p>\r\n\r\n\r\n\r\n<h4><span class=\"ez-toc-section\" id=\"Explication_partie_par_partie\"><\/span>Explanation part by part<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5524\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox11.png\" alt=\"\" width=\"983\" height=\"487\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox11.png 983w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox11-600x297.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox11-300x149.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox11-768x380.png 768w\" sizes=\"auto, (max-width: 983px) 100vw, 983px\" \/><\/a><\/p>\r\n<ul>\r\n<li>The trigger: this is when the load is finished<\/li>\r\n<li>Action 1 (disabled by default) is to be activated only once thinking of disabling the other 2 actions, it is to initialise to \u2018null\u2019 once the entity that records the data.<\/li>\r\n<li>Action 2 (disabled by default) should only be activated once when thinking about disabling the other 2 actions, this is to initialise some previous data. Indeed, I did not want to lose the charging data since the purchase of the car, so I stored it there.\u00a0<\/li>\r\n<li>Action 3 (to be activated by default) is the action that calculates and records load data.<\/li>\r\n<\/ul>\r\n<h4><span class=\"ez-toc-section\" id=\"Explication_du_code_du_declencheur\"><\/span>Explanation of the trigger code\u00a0<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5529\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\" alt=\"\" width=\"20\" height=\"20\" \/><\/a><\/p>\r\n<blockquote>\r\n<p>This trigger is based on the \"state\" platform of Home Assistant. It monitors the status of a specific entity, in this case, \u2018sensor.wallbox _portal _status _description\u2019. Specifically, it is configured to react when a change in the state of that entity occurs. The configuration details are as follows:<\/p>\r\n<p>\u2013 \u2018entity _id\u2019: It specifies the entity whose status is monitored. In this case, it is \u2018sensor.wallbox _portal _status _description\u2019. Multiple entities can be monitored by providing a list of entities in the form of a list. However, in this example, only one entity is monitored.<\/p>\r\n<p>\u2013 \u201cfrom: Charging\u2019: This means that the trigger reacts when the previous state of \u2018sensor.wallbox _portal _status _description\u2019 was \u2018Charging\u2019. This is a condition for triggering automation. The trigger only reacts if the previous state was \u2018Charging\u2019.<\/p>\r\n<p>\u2013 `to: null\u201c: This means that the trigger reacts when the current state of \u2018sensor.wallbox _portal _status _description\u2019 has changed from \u2018Charging\u2019 to any other state, including \u2018null\u2019. This is the new condition for triggering automation. The trigger reacts when the state changes from Charging to any other state.<\/p>\r\n<p>\u2013 \u201dalias: When the load ends: This is an alias for the trigger, a name that makes it easier for you to recognise it. In this case, it simply indicates that the automation will be triggered when the load ends.<\/p>\r\n<p>In summary, this automation is triggered whenever the state of \u2018sensor.wallbox_portal_status_description\u2019 changes from \u2018Charging\u2019 to any other state, which means that it is designed to react when the electric car load ends.<\/p>\r\n<\/blockquote>\r\n<h4><span class=\"ez-toc-section\" id=\"Explication_de_laction_1\"><\/span>Explanation of Action 1\u00a0<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5529\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\" alt=\"\" width=\"20\" height=\"20\" \/><\/a><\/p>\r\n<blockquote>\r\n<p>This action is intended to initialize the first consumption (charge) for a sensor called \"sensor.wallbox _charges\" using the \"variable.update _sensor\" service of Home Assistant. Here is a detailed explanation of each component of the action:<\/p>\r\n<p>\u2013 \u2018alias\u2019: It is simply a name or description of the action to make it more understandable. In this case, it indicates that this action is intended for the initialisation of the first consumption and that it should only be performed once. It also suggests disabling further actions after its execution.<\/p>\r\n<p>\u2013 `service: variable.update_sensor\u201c: This row specifies the service to be used to perform the action. The variable.update _sensor service is used to update or initialise the attributes of an entity (in this case, \u2018sensor.wallbox _charges\u2019).<\/p>\r\n<p>\u2013 \"data\": This section contains the data to be sent with the service. In this case:<br \/>\u2013 \u2018replace _attributes: true\u2019: This indicates that the attributes of the existing entity need to be replaced by the new data. If \"replace _attributes\" is set to \"true\", the existing attributes of \"sensor.wallbox _charges\" will be replaced by the new data.<\/p>\r\n<p>\u2013 Value: INIT\u2019: This indicates the value to be assigned to the \u2018sessionload\u2019 attribute of \u2018sensor.wallbox _charges\u2019. In this case, the value \"INIT\" is assigned.<\/p>\r\n<p>\u2013 Attributes: sessionsload: null\u201c: This row indicates that the \u2018sessionload\u2019 attribute of \u2018sensor.wallbox _charges\u2019 must be initialised to \u2018null\u2019.<\/p>\r\n<p>\u2013 \u201ctarget\u201d: It specifies the target entity, i.e. the entity whose attributes are updated. In this case, the target entity is sensor.wallbox _charges.<\/p>\r\n<p>\u2013 \u2019enabled: true\u2019: This indicates that this action is enabled and can be executed.<\/p>\r\n<p>In summary, this action is used to initialise the \u2018sessionload\u2019 attribute of the \u2018sensor.wallbox _charges\u2019 entity with the value \u2018null\u2019 using the service \u2018variable.update _sensor\u2019. It is intended to be executed only once to perform this initialization, after which it is recommended to disable this action. This could be useful for getting started with specific initial values in your automations or entities.<\/p>\r\n<\/blockquote>\r\n<h4><span class=\"ez-toc-section\" id=\"Explication_de_laction_2\"><\/span>Explanation of Action 2<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5529\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\" alt=\"\" width=\"20\" height=\"20\" \/><\/a><\/p>\r\n<blockquote>\r\n<p>This action aims to initialise the \u2018sessionload\u2019 attribute of an entity called \u2018sensor.wallbox _charges\u2019 with a series of pre-existing load session data. Here is a detailed explanation of each element of the action:<\/p>\r\n<p>\u2013 `service: variable.update_sensor\u201c: This is the service used to update or initialise an entity\u2019s attributes in Home Assistant.<\/p>\r\n<p>\u2013 \"data\": This section contains the data to be sent with the service. In this case:<br \/>\u2013 \u2018replace _attributes: true\u2019: This indicates that the existing attributes of the sensor.wallbox _charges entity will be replaced by the new data.<\/p>\r\n<p>\u2013 \"value\": This part is used to define the value of the sessionload attribute of the sensor.wallbox _charges entity. The value is generated dynamically using Jinja2 models. It uses the timestamp of the first charging session (i.e. \u2018sensor.wallbox _portal _added _range _min\u2019) to obtain a date and time, and then formats it in the style \u2018day\/month\/year hour:minute:second\u2019. This means that the value \u2018sessionload\u2019 will be initialised with the date and time of the first charging session.<\/p>\r\n<p>\u2013 \"attributes\": This is where the data for each charging session is defined. Each load session is defined in a specific format using Jinja2 templates. These charging sessions are separated by commas.<\/p>\r\n<p>\u2013 \u201ctarget\u201d: It specifies the target entity, i.e. the entity whose attributes are updated. In this case, the target entity is sensor.wallbox _charges.<\/p>\r\n<p>\u2013 \u2019enabled: true\u2019: This indicates that this action is enabled and can be executed.<\/p>\r\n<p>The purpose of this action is to initialise the \u2018sessionload\u2019 attribute of \u2018sensor.wallbox _charges\u2019 with simulated data from load sessions. This can be useful for testing or starting with fictitious load data. After initialisation, it is recommended to disable this action, as indicated in the alias, as it does not need to be repeated.<\/p>\r\n<\/blockquote>\r\n<h4><span class=\"ez-toc-section\" id=\"Explication_de_laction_3_%E2%80%93_Principale_action\"><\/span>Explanation of Action 3 \u2013 Main Action<span class=\"ez-toc-section-end\"><\/span><\/h4>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5529\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/ChatGPT_logo.svg-1.png\" alt=\"\" width=\"20\" height=\"20\" \/><\/a><\/p>\r\n<blockquote>\r\n<p>This action aims to update the \u2018sessionload\u2019 attribute of the \u2018sensor.wallbox _charges\u2019 entity with the data from the load session that has just ended. Here is a detailed explanation of each element of the action:<\/p>\r\n<p>\u2013 `service: variable.update_sensor\u201c: This is the service used to update or initialise an entity\u2019s attributes in Home Assistant.<\/p>\r\n<p>\u2013 \"data\": This section contains the data to be sent with the service. In this case:<br \/>\u2013 \u2018replace _attributes: true\u2019: This indicates that the existing attributes of the sensor.wallbox _charges entity will be replaced by the new data.<\/p>\r\n<p>\u2013 \"value\": This part is used to define the value of the sessionload attribute of the sensor.wallbox _charges entity. The value is generated dynamically using Jinja2 models. It includes:<br \/>\u2013 The conversion of the time stamp of \u2018sensor.wallbox_portal_added_range_min\u2019 into a specific date and time format using the \u2018timestamp_custom\u2019 function.<\/p>\r\n<p>\u2013 \"attributes\": This is where the load session data is defined. Those data are calculated from various entities, in particular \u2018sensor.wallbox _portal _added _energy\u2019, \u2018sensor.wallbox _portal _energy _price\u2019, \u2018sensor.wallbox _portal _added _rangemin\u2019, \u2018sensor.wallbox _portal _added _range\u2019, and the current timestamp (obtained via \u2018now()\u02bc). The data shall include the consumption, cost, duration, start, end, kilometres and timestamp of the charging session.<\/p>\r\n<p>\u2013 Duration is calculated by subtracting the start timestamp of the charging session from the current timestamp (expressed in seconds). Then these seconds are converted into hours and minutes.<\/p>\r\n<p>\u2013 In section `{% if \u2026 %}\u201c, the code checks whether the \u2018sessionload\u2019 attribute of the \u2018sensor.wallbox _charges\u2019 entity is already defined. If this is the case, the existing data shall be retained. Otherwise, new load session data is added.<\/p>\r\n<p>\u2013 \u201ctarget\u201d: It specifies the target entity, i.e. the entity whose attributes are updated. In this case, the target entity is sensor.wallbox _charges.<\/p>\r\n<p>\u2013 \u2019enabled: true\u2019: This indicates that this action is enabled and can be executed.<\/p>\r\n<p>The objective of this action is to record the data of each load session that has just ended in the \u2018sessionload\u2019 attribute of the \u2018sensor.wallbox _charges\u2019 entity. This keeps track of each charging session performed.<\/p>\r\n<\/blockquote>\r\n<p>\u00a0<\/p>\r\n\r\n\r\n\r\n<h3><span class=\"ez-toc-section\" id=\"Resultat\"><\/span>Result<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>Thus, at each end of the load, a new record is added to the sensor.wallbox _charges entity.<\/p>\r\n<p>Its content is as follows:<\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5542\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox12.png\" alt=\"\" width=\"784\" height=\"548\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox12.png 784w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox12-600x419.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox12-300x210.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox12-768x537.png 768w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/a>&nbsp;<\/p>\r\n<h3><span class=\"ez-toc-section\" id=\"Ajout_dune_carte_qui_affiche_toutes_les_sessions_de_charge\"><\/span>Added a map that displays all charging sessions<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox13.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5543\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox13.png\" alt=\"\" width=\"453\" height=\"487\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox13.png 453w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox13-279x300.png 279w\" sizes=\"auto, (max-width: 453px) 100vw, 453px\" \/><\/a><\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">&lt;div&gt;Charging sessions&lt;\/div&gt; \r\nLast update: {{ state_attr(&#039;sensor.sessions_de _charge&#039;,&#039;updated_at&#039;)}} &lt;br&gt;&lt;br&gt;\r\n{% set items = state_attr(&#039;sensor.wallbox _charges&#039;, &#039;sessionscharge&#039;) %}\r\n&lt;table width=&#039;100%&#039;&gt;\r\n&lt;tbody&gt;\r\n{% for i in range(0, items | count, 1) %}\r\n&lt;tr&gt;\r\n&lt;td&gt;{{ items[i].start }} to {{ items[i].fin }} ({{ items[i].duration }})&lt;\/td&gt;\r\n&lt;td&gt;{{ items[i].consumption }} kWh&lt;\/td&gt;\r\n&lt;td&gt;+{{ items[i].km }} km&lt;\/td&gt;\r\n&lt;td&gt;{{ items[i].cost }} &euro;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n\r\n{% endfor %}\r\n&lt;\/tbody&gt;\r\n&lt;\/table&gt;<\/pre>\r\n\r\n\r\n\r\n<h3><span class=\"ez-toc-section\" id=\"Ajout_dune_carte_qui_affiche_un_recapitulatif_par_annee_mois_semaine\"><\/span>Addition of a map showing a summary by year, month, week<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox14.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5547\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox14.png\" alt=\"\" width=\"457\" height=\"416\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox14.png 457w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/wallbox14-300x273.png 300w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/a><\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">Type: markdown content: &amp;gt;-\r\n  &lt;div&gt;&lt;h1&gt;Charging sessions&lt;\/div&gt;  {%- set default _language = &#039;en&#039; %} Latest update: {{ state_attr(&#039;sensor.wallbox _charges&#039;,&#039;updated _at&#039;)}} &lt;br&gt;&lt;br&gt;\r\n\r\n\r\n  {% set items = state_attr(&#039;sensor.wallbox _charges&#039;, &#039;sessionscharge&#039;) %} {% set septjours = now() - timedelta(days=7) %} {% set power_semaine = namespace(value=0) %} {% set cout_semaine = namespace(value=0) %} {% set unmois = now() - timedelta(days=30) %} {% set power_months = namespace(value=0) %} {% set cout_mois = namespace(value=0) %} {% set uneannee = now() - timedelta(days=365) %} {% set power_annee = namespace(value=0) %} {% set cout_annee = namespace(value=0) %} {% for i in range(0, items | count, 1) %} {% if items[i].saved_at | int &amp;gt;= as_timestamp(uneannee) %} {% set power_annee.value = power_annee.value + items[i].consumption %} {% set cout_annee.value = cout_annee.value + items[i].cost %} {% if items[i].saved_at | int &amp;gt;= as_timestamp(unmonth) %} {% set power_mois.value = power_mois.value + items[i].consumption %} {% set cout_mois.value = cout_mois.value + items[i].cost %} {% if items[i].saved_at | int &amp;gt;= as_timestamp(sevendays) %} {% set power_semaine.value = power_semaine.value + items[i].consumption %} {% set cout_semaine.value = cout_semaine.value + items[i].cost %} {% endif %} {% endif %} {% endif %} {% endfor %}\r\n\r\n  &lt;\/ha-alert&gt; &lt;ha-alert alert-type=&quot;info&quot; title=&quot;Last month: {{ power _mois.value | int }} kWh - {{ cost _mois.value | float | round(2) }} &euro;&quot;&gt;&lt;\/ha-alert&gt; &lt;ha-alert alert-type=&quot;info&quot; title=&quot;Last year: {{ power_annee.value | int }} kWh - {{ cout _annee.value | float | round(2) }} &euro;&quot;&gt;&lt;\/ha-alert&gt;\r\n\r\n\r\n  &lt;br&gt; \r\n\r\n\r\n  {% set items = state_attr(&#039;sensor.wallbox _charges&#039;, &#039;sessionscharge&#039;) %} {% set septjours = now() - timedelta(days=7) %}\r\n\r\n  &lt;table width=&#039;100%&#039;&gt; &lt;tbody&gt;  {% for i in range(0, items | count, 1) %} {% if items[i].saved_at | int &amp;gt;= as_timestamp(sevendays) %} {% set datetime _obj = strptime(items[i].start, &#039;%d\/%m\/%Y %H:%M&#039;) %}\r\n\r\n  &lt;tr&gt; &lt;td&gt;&lt;h5&gt;{{items[i].start }} to {{ items[i].fin }} ({{ items[i].duration }})&lt;\/td&gt; &lt;td&gt;{{ items[i].consumption }} kWh&lt;\/td&gt; &lt;td&gt;+{{ items[i].km }} km&lt;\/td&gt; &lt;td&gt;{{ items[i].cost }} &euro;&lt;\/td&gt; &lt;\/tr&gt; {% endif %} {% endfor %} &lt;\/tbody&gt; &lt;\/table&gt;\r\n    &lt;ha-alert alert-type=&quot;success&quot; title=&quot;Last week: {{ power_semaine.value | int}} kWh - {{ cost_semaine.value | float | round(2) }}&euro;&quot;&gt;    \r\nstyle: .: | ha-card { margin: 0px 0px 0px 0px; box-shadow: none; } ha-markdown: $: | h5 { font-size: 15px!important; font-weight: normal!important; padding: 0px 0px 0px 8px!important; border-left: 3px solid #429f46; }\r\n<\/pre>\r\n<p>&nbsp;<\/p>\r\n\r\n\r\n\r\n<h2><span class=\"ez-toc-section\" id=\"Bonus_Enregistrer_les_donnees_dans_un_fichier_CSV\"><\/span>Bonus: Save data to a CSV file<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>For future use (and not to lose data in case of a glitch), I decided to save each load session without a CSV file. At each session, a line is added.<\/p>\r\n<p>Here is how I realised this.<\/p>\r\n<h3><span class=\"ez-toc-section\" id=\"Jajoute_un_sensor_%C2%AB_file_%C2%BB_qui_correspond_au_fichier_CSV\"><\/span>I add a sensor \u2018file\u2019 which corresponds to the CSV file<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>I use a file <strong>notify.yaml<\/strong> which is in the configuration.yaml folder that is declared in this file by the command <strong>Notify: !include notify.yaml<\/strong><\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5624\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify.png\" alt=\"\" width=\"396\" height=\"74\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify.png 396w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify-300x56.png 300w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><\/p>\r\n<p>I declare this new sensor with this code:<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">- name: _de_charge _CSV platform sessions: file filename: \/config\/www\/csv\/sessions_de _charge.csv timestamp: false<\/pre>\r\n<p>Thus, when I would like to write to the file, it will be enough for me to execute the service <strong>notify.sessions_de _charge_CSV<\/strong><\/p>\r\n<p><a href=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5625\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify2.png\" alt=\"\" width=\"395\" height=\"121\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify2.png 395w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2023\/10\/notify2-300x92.png 300w\" sizes=\"auto, (max-width: 395px) 100vw, 395px\" \/><\/a><\/p>\r\n<h3><span class=\"ez-toc-section\" id=\"Jajoute_une_action\"><\/span>I add an action<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n<p>I add an action in the automation presented above that will write a line to each record of a load session<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">Service: notify.sessions_de _charge _CSV data: data: {} message: &gt;- {% set diff_seconds = now().timestamp() - states.sensor.wallbox _portal _added _range _min.state | as_timestamp %} {% set hours = (diff _seconds \/ 3600) | int %} {% set minutes = ((diff_seconds % 3600) \/ 60) | int %} {% set sessioncharge _string = \"\" + states('sensor.wallbox _portal _added _energy') | round(2) | replace('.', ',') | string + \"; \" + (states('sensor.wallbox _portal _energy _price') | float * states('sensor.wallbox _portal _added _energy') | float | round(2)) | round(2) | replace('.', ',') | string + \"; \" + 'd:d' | format(hours, minutes) | string + \"; \" + as_timestamp(states('sensor.wallbox_portal _added_range_min')) | int | timestamp_custom('%d\/%m\/%Y', true) | string + \"; \" + as_timestamp(states('sensor.wallbox_portal _added_range_min')) | int | timestamp_custom('%H:%M', true) | string + \"; \" + now().strftime('%H:%M') | string + \"; \" + states('sensor.wallbox _portal _added _range') | int | string + \"; \" + now().timestamp() | int | string %} {{ sessioncharge _string }} enabled: true alias: Add a line to the _de_charge.CSV sessions file\r\n<\/pre>\r\n<p>\u00a0<\/p>","protected":false},"excerpt":{"rendered":"<p>I look at the data retrieved from the Wallbox integration Here is a small recap of the data that will allow me to save the data from the last charging session in sensor.wallbox _charges. I have already described all the Wallbox integration entities on this Retex: I integrate the Wallbox into the Home Assistant<\/p>","protected":false},"author":1,"featured_media":5262,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,53,166],"tags":[81,80,67],"class_list":["post-5493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-domotique","category-home-assistant","category-retex","tag-developpement","tag-vehicule-electrique","tag-wallbox"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts\/5493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/comments?post=5493"}],"version-history":[{"count":0,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts\/5493\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/media\/5262"}],"wp:attachment":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/media?parent=5493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/categories?post=5493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/tags?post=5493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}