{"id":8260,"date":"2024-12-28T01:16:23","date_gmt":"2024-12-27T23:16:23","guid":{"rendered":"https:\/\/www.sigalou-domotique.fr\/?p=8260"},"modified":"2026-01-03T16:22:09","modified_gmt":"2026-01-03T14:22:09","slug":"je-domotiser-ma-consommation-deau","status":"publish","type":"post","link":"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau","title":{"rendered":"I domotise my water consumption"},"content":{"rendered":"<p>This article follows on from the previous article:<\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/domotiser-sa-consommation-deau\/\" target=\"_blank\" rel=\"noopener\">Controlling water consumption<\/a><\/li>\r\n<\/ul>\r\n<p><!--more--><\/p>\r\n<p>I wanted to replace a D1 Mini with a\u00a0<a href=\"https:\/\/www.sigalou-domotique.fr\/en\/product\/d1-mini-v4\/\" target=\"_blank\" rel=\"noopener\">D1 MINI V4<\/a> new version.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8278\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20241221_140313.png\" alt=\"D1 Mini V4\" width=\"394\" height=\"268\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20241221_140313.png 1494w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20241221_140313-600x408.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20241221_140313-300x204.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20241221_140313-1024x696.png 1024w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20241221_140313-768x522.png 768w\" sizes=\"auto, (max-width: 394px) 100vw, 394px\" \/><\/p>\r\n<p>The previous one was flashed with Esp Easy, the new one, I flashed it with ESP Home.<\/p>\r\n<p>Here are the two tutorials:<\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/flasher-un-d1-mini\/\" target=\"_blank\" rel=\"noopener\">Flash a D1 Mini with ESP Easy<\/a><\/li>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/flasher-un-d1-mini-v4\/\" target=\"_blank\" rel=\"noopener\">Flash a D1 Mini V4 with ESP Home<\/a><\/li>\r\n<\/ul>\r\n<p>Once the\u00a0<a href=\"https:\/\/www.sigalou-domotique.fr\/en\/product\/d1-mini-v4\/\" target=\"_blank\" rel=\"noopener\">D1 MINI V4<\/a> flashed with Esp Home, I continue the configuration.<\/p>\r\n<p>I take advantage of the change of D1Mini to replace the resistance of the divider bridge between A0 and GND, I put a 51K. The value of this resistance is set on the value of the thermoresistance at 25 \u00b0 C (to be measured manually before installation therefore).<\/p>\r\n<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-6ae450b23624d\" 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-6ae450b23624d\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Pour_memoire_voici_le_schema_de_cablage\" >For the record, here is the wiring diagram<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Je_realise_la_configuration_du_fichier_yaml_du_device_ESP_Home\" >I realize the configuration of the yaml file of the device ESP Home<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Je_selectionne_les_capteurs_que_je_garde\" >I select the sensors I keep<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Jajoute_3_capteurs_doffset\" >I add 3 offset sensors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Jajoute_3_automatisations_pour_gerer_le_Reset_du_compteur_du_D1_Mini\" >I add 3 automations to manage the D1 Mini counter reset<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Je_declare_les_capteurs_finaux_de_consommation\" >I declare the final consumption sensors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Je_configure_recorder\" >I configure recorder<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Je_teste_le_reset_du_D1_Mini_V4\" >I'm testing the reset of the D1 Mini V4<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Resultat\" >Result<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.sigalou-domotique.fr\/en\/je-domotiser-ma-consommation-deau\/#Si_cetait_a_refaire_idees_ou_retour_dexperience\" >If it had to be done again (ideas or feedback)<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Pour_memoire_voici_le_schema_de_cablage\"><\/span>For the record, here is the wiring diagram<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8358\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/D1MiniCapteurDebitEauChaude-1.png\" alt=\"\" width=\"1146\" height=\"729\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/D1MiniCapteurDebitEauChaude-1.png 1146w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/D1MiniCapteurDebitEauChaude-1-600x382.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/D1MiniCapteurDebitEauChaude-1-300x191.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/D1MiniCapteurDebitEauChaude-1-1024x651.png 1024w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/D1MiniCapteurDebitEauChaude-1-768x489.png 768w\" sizes=\"auto, (max-width: 1146px) 100vw, 1146px\" \/><\/p>\r\n<p>The wiring of the D1 Mini is unchanged, so I reproduce the diagram with the D1 Mini V4.<\/p>\r\n<p>Please refer to this page for further explanation:<\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.sigalou-domotique.fr\/en\/domotiser-sa-consommation-deau\/\" target=\"_blank\" rel=\"noopener\">Controlling water consumption<\/a><\/li>\r\n<\/ul>\r\n<h2><span class=\"ez-toc-section\" id=\"Je_realise_la_configuration_du_fichier_yaml_du_device_ESP_Home\"><\/span>I realize the configuration of the yaml file of the device ESP Home<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>Once the <a href=\"https:\/\/www.sigalou-domotique.fr\/en\/flasher-un-d1-mini-v4\/\" target=\"_blank\" rel=\"noopener\">D1 mini flashed V4<\/a>, I go to ESPHome Builder and find my equipment:<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8267\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome111.png\" alt=\"ESPHome Builder\" width=\"1060\" height=\"382\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome111.png 1060w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome111-600x216.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome111-300x108.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome111-1024x369.png 1024w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome111-768x277.png 768w\" sizes=\"auto, (max-width: 1060px) 100vw, 1060px\" \/><\/p>\r\n<p>I click on EDIT and edit the yaml file, here is the configuration:<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">substitutions: name: esphome-web-e586c5 friendly_name: ESPHome Hot Water esphome: name: ${name} friendly_name: ${friendly_name} min_version: 2024.6.0 name_add_mac_suffix: false project: name: esphome.web version: dev esp8266: board: esp01_1m # Enable Logger Logging: # Enable the API Home Assistant api: # Allow Over-The-Air ota updates: - platform: esphome # Allow Wi-Fi configuration via the improv_serial serial port: wifi: # Set up a Wi-Fi AP: {} # In combination with the \"ap\" option, this allows the user to # configure Wi-Fi credentials via Wi-Fi AP. captive_portal: dashboard_import: _import _url package: github:\/\/esphome\/example-configs\/esphome-web\/esp8266.yaml@main import_full _config: true # To have a \"next URL\" for improv_serial web_server: sensor: - platform: ntc sensor: temp_resistance name: \"Temperature\" unit _of _measurement: \"\u00b0C\" accuracy _decimals: 2 calibration: b_constant: 3950 reference_temperature: 25\u00b0C reference_resistance: 50kOhm - platform: resistance id: temp_resistance sensor: temp_voltage configuration: DOWNSTREAM resistor: 50kOhm reference_voltage: 3.3V - platform: adc pin: A0 id: temp_voltage # Turbine sensor for cold water - platform: pulse_meter pin: number: GPIO13 mode: input: true pullup: true name: 'Drinking Water Flow' unit _of _measurement: 'L\/min' accuracy_decimals: 0 internal_filter: 100ms timeout: 5s filters: - multiply: 0.013 total: name: 'Total Drinking Water' unit _of _measurement: 'L' id: total_eau _potable accuracy_decimals: 2 filters: - multiply: 0.013 # Turbine sensor for hot water - platform: pulse_meter pin: number: GPIO14 mode: input: true pullup: true name: 'Hot Water Flow' unit _of _measurement: 'L\/min' accuracy_decimals: 0 internal_filter: 100ms timeout: 5s filters: - multiply: 0.013 # 1\/77 total: name: 'Total Conso Hot Water' unit _of _measurement: 'L' id: total_eau _chaude accuracy_decimals: 2 filters: - multiply: 0.013 # 1\/77 # Calculated sensor for net cold water consumption - platform: template name: \"Total Conso Cold Water\" unit _of _measurement: \"L\" accuracy _decimals: 2 lambda: |- return id(total _eau _potable).state - id(total _eau _chaude).state;\r\n<\/pre>\r\n<p>&nbsp;<\/p>\r\n<p>In a few lines, here is the explanation:<\/p>\r\n<p>Temperature sensor (NTC):<\/p>\r\n<ul>\r\n<li>Use an NTC thermistor<\/li>\r\n<li>Measurement in \u00b0C to 2 decimal places<\/li>\r\n<li>Cascading configuration: ADC (A0) \u2192 resistance \u2192 ntc<\/li>\r\n<li>Calibrated with a B constant of 3950 and a reference to 25\u00b0C\/50k\u03a9<\/li>\r\n<\/ul>\r\n<p>Two water flow sensors (pulse _meter):<\/p>\r\n<ul>\r\n<li>Drinking water on GPIO13, Hot water on GPIO14<\/li>\r\n<li>Setup in input mode with pullup enabled<\/li>\r\n<li>Conversion: multiplied by 0.013 (calibrated on 77 pulses\/L)<\/li>\r\n<li>5s timeout (return to 0 if no pulses)<\/li>\r\n<li>100ms internal filter to stabilize playback<\/li>\r\n<li>Each has a total meter in litres<\/li>\r\n<li>Clarification: 0 decimal places for flow, 2 decimal places for total<\/li>\r\n<\/ul>\r\n<p>A calculated sensor:<\/p>\r\n<ul>\r\n<li>Calculates cold water consumption<\/li>\r\n<li>Formula: Total drinking water \u2013 Total hot water<\/li>\r\n<li>Clarification: 2 decimal places<\/li>\r\n<\/ul>\r\n<h2><span class=\"ez-toc-section\" id=\"Je_selectionne_les_capteurs_que_je_garde\"><\/span>I select the sensors I keep<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8242\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome105.png\" alt=\"Sensor selection\" width=\"1198\" height=\"437\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome105.png 1198w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome105-600x219.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome105-300x109.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome105-1024x374.png 1024w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome105-768x280.png 768w\" sizes=\"auto, (max-width: 1198px) 100vw, 1198px\" \/><\/p>\r\n<p>I will keep the last 4 sensors, deactivate the others and rename them by:<\/p>\r\n<ul>\r\n<li>sensor.temperature _eau _chaude<\/li>\r\n<li>sensor.esphome _total_eau _potable<\/li>\r\n<li>sensor.esphome_total_eau_chaude<\/li>\r\n<li>sensor.esphome_total_eau_froide<\/li>\r\n<\/ul>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8246\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome106-1.png\" alt=\"Sensor renaming\" width=\"340\" height=\"291\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome106-1.png 340w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome106-1-300x257.png 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8247\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome107.png\" alt=\"Sensor renaming\" width=\"824\" height=\"242\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome107.png 824w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome107-600x176.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome107-300x88.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome107-768x226.png 768w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/p>\r\n<h2><span class=\"ez-toc-section\" id=\"Jajoute_3_capteurs_doffset\"><\/span>I add 3 offset sensors<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>When the D1 Mini V4 restarts (juice cutting for example), the count starts from zero.<\/p>\r\n<p>So I organised the calculation of the total count via a sensor that gives me the sum of an offset and the value of the current count.<\/p>\r\n<p>So I added 3 offset entities. For purists, only two are mandatory, the 3rd can be calculated.<\/p>\r\n<p>So in Settings\/Devices and Services\/Inputs, I added an entry<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8236\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome101.png\" alt=\"Adding an entry\" width=\"213\" height=\"63\" \/><\/p>\r\n<p>Then Number<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8237\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome102.png\" alt=\"Adding a number\" width=\"516\" height=\"580\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome102.png 516w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome102-267x300.png 267w\" sizes=\"auto, (max-width: 516px) 100vw, 516px\" \/><\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8238\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome103.png\" alt=\"Configuring the number\" width=\"519\" height=\"459\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome103.png 519w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome103-300x265.png 300w\" sizes=\"auto, (max-width: 519px) 100vw, 519px\" \/><\/p>\r\n<p>So this creates me input_number.eau _froide _offset.<\/p>\r\n<p>I'm doing this for the other two offsets.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8239\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome104.png\" alt=\"Setup of offsets\" width=\"888\" height=\"195\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome104.png 888w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome104-600x132.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome104-300x66.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome104-768x169.png 768w\" sizes=\"auto, (max-width: 888px) 100vw, 888px\" \/><\/p>\r\n<p>I chose to use \u2018drinking water\u2019 for everything that passes through the drinking water meter, i.e. total consumption: cold water + hot water.<\/p>\r\n<h2><span class=\"ez-toc-section\" id=\"Jajoute_3_automatisations_pour_gerer_le_Reset_du_compteur_du_D1_Mini\"><\/span>I add 3 automations to manage the D1 Mini counter reset<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>The D1 Mini has a size defect, it loses the value of its meters in case of reset, so everything starts from scratch, so it does not suit me.<\/p>\r\n<p>I noticed that at the time of the reset, the sensors switch to the \u2018unavailable\u2019 state before going back to zero.<\/p>\r\n<p>I will therefore assign the previous state unavailable to an input _number which will serve as an offset, i.e. as a correction value for the overall count.<\/p>\r\n<p>To make it simpler, I do 3 automations that do this:<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">alias: Offset Hot Water on Unavailable triggers: - entity_id: sensor.esphome _total_eau _chaude to: unavailable trigger: state actions: - target: entity_id: input_number.eau _chaude _offset data: value: &gt;- {{ states('input_number.eau _chaude _offset') | float + trigger.from _state.state | float }} action: input_number.set_value mode: single alias: Offset Cold Water on Unavailable triggers: - entity_id: sensor.esphome _total_eau _froide to: unavailable trigger: state actions: - target: entity_id: input_number.eau_froide_offset data: value: &gt;- {{ states('input _number.eau _froide _offset') | float + trigger.from _state.state | float }} action: input_number.set_value mode: single alias: Offset Drinking Water on Unavailable triggers: - entity_id: sensor.esphome _total_eau _potable to: unavailable trigger: state actions: - target: entity_id: input_number.eau _potable _offset data: value: &gt;- {{ states('input_number.eau _potable _offset') | float + trigger.from _state.state | float }} action: input_number.set_value mode: single<\/pre>\r\n<p class=\"whitespace-pre-wrap break-words\">For each type of water (hot, cold, drinking), when the sensor becomes unavailable:<\/p>\r\n<ul class=\"-mt-1 [li&gt;&amp;]:mt-2 list-disc space-y-2 pl-8\">\r\n<li class=\"whitespace-normal break-words\">Automation captures the last known value before disconnection<\/li>\r\n<li class=\"whitespace-normal break-words\">This value is added to an offset counter stored in an input_number<\/li>\r\n<li class=\"whitespace-normal break-words\">This keeps the total cumulation even after a sensor restart<\/li>\r\n<\/ul>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8251\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome108.png\" alt=\"Automation\" width=\"369\" height=\"191\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome108.png 369w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome108-300x155.png 300w\" sizes=\"auto, (max-width: 369px) 100vw, 369px\" \/><\/p>\r\n<h2><span class=\"ez-toc-section\" id=\"Je_declare_les_capteurs_finaux_de_consommation\"><\/span>I declare the final consumption sensors<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>In my templates.yaml file, I add these three sensors:<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8270\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome109-1.png\" alt=\"Final sensors\" width=\"1070\" height=\"517\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome109-1.png 1070w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome109-1-600x290.png 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome109-1-300x145.png 300w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome109-1-1024x495.png 1024w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome109-1-768x371.png 768w\" sizes=\"auto, (max-width: 1070px) 100vw, 1070px\" \/><\/pre>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">- sensor: - name: Single _id Drinking Water Consumption: sensor.consumption _eau _potable unit _of _measurement: \"L\" device _class: water state_class: total_increasing state: &gt; {% set measure_current = states('sensor.esphome_total_eau _potable') | float %} {% set total _offset = states('input_number.eau _potable _offset') | float %} {{ total _offset + measure _current if states('sensor.esphome _total_eau _potable')!= 'unavailable' else total _offset }} - name: Single _id \"Cold Water Consumption\": sensor.consumption _eau _froide unit _of _measurement: \"L\" device _class: water state_class: total_increasing state: &gt; {% set measure_current = states('sensor.esphome_total_eau_froide') | float %} {% set total _offset = states('input_number.eau _froide _offset') | float %} {{ total _offset + measure _current if states('sensor.esphome _total_eau _froide')!= 'unavailable' else total _offset }} - name: Single _id \"Hot Water Consumption\": sensor.consumption _eau _chaude unit _of _measurement: \"L\" device _class: water state_class: total_increasing state: &gt; {% set measure_current = states('sensor.esphome_total_eau _chaude') | float %} {% set total _offset = states('input_number.eau _chaude _offset') | float %} {{ total _offset + measure _current if states('sensor.esphome _total_eau _chaude')!= 'unavailable' else total _offset }}      <\/pre>\r\n<p>These sensors are virtual sensors (templates) that allow water consumption to be tracked persistently. Let's analyse how they work:<\/p>\r\n<p>Data sources:<\/p>\r\n<ul>\r\n<li>Physical sensors ESP Home (sensor.esphome_total_eau _*)<\/li>\r\n<li>Offset counters (input_number.eau _*_offset)<\/li>\r\n<\/ul>\r\n<p>Types of measures:<\/p>\r\n<ul>\r\n<li>Drinking water: Total incoming water<\/li>\r\n<li>Hot water: Hot water consumption<\/li>\r\n<li>Cold water: Cold water consumption<\/li>\r\n<\/ul>\r\n<p>Common characteristics:<\/p>\r\n<ul>\r\n<li>state_class: total_increasing: Indicates a meter that continuously increases<\/li>\r\n<li>_of _measurement unit: \u2018L\u2019: Measurement in litres<\/li>\r\n<\/ul>\r\n<p>Operational logic:<\/p>\r\n<p>{% set measure_current = states(\u2018sensor.esphome_total_eau _*\u2019) | float %}<br \/>{% set total _offset = states(\u2018input_number.eau _*_offset\u2019) | float %}<br \/>{{ total _offset + measure _current if states(\u2026)!= \u2018unavailable\u2019 else total _offset }}<\/p>\r\n<ul>\r\n<li>If the ESP sensor is available: Total = Offset + Current measure<\/li>\r\n<li>If the ESP sensor is unavailable: Total = Offset only<\/li>\r\n<\/ul>\r\n<h2><span class=\"ez-toc-section\" id=\"Je_configure_recorder\"><\/span>I configure recorder<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>We must remember to keep what we need but also not to record what is not useful.<\/p>\r\n<p>So in the Recorder configuration, I put in:<\/p>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\">  include: entity_globs: [...] - input_number.eau _* - sensor.consumption _eau _* exclude: entity_globs: [...] - sensor.esphome*    <\/pre>\r\n<h2><span class=\"ez-toc-section\" id=\"Je_teste_le_reset_du_D1_Mini_V4\"><\/span>I'm testing the reset of the D1 Mini V4<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p>So, in the end, I have<\/p>\r\n<ul>\r\n<li>3 input_number which serve as offset,<\/li>\r\n<li>3 sensors that give me the value of the current meters of the D1 Mini<\/li>\r\n<li>3 calculated sensors that give me the value of permanent meters<\/li>\r\n<\/ul>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8271\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome112.png\" alt=\"Reset test\" width=\"505\" height=\"467\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome112.png 505w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome112-300x277.png 300w\" sizes=\"auto, (max-width: 505px) 100vw, 505px\" \/><\/p>\r\n<p>At this stage, the D1 has never been relaunched, so the D1 counters and the permanent counters are identical.<\/p>\r\n<p>I unplug and reconnect the D1 mini, the sensors will become unavailable for the reset time and then go back to 0.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8272\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome113.png\" alt=\"Reset of the D1 Mini\" width=\"508\" height=\"465\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome113.png 508w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome113-300x275.png 300w\" sizes=\"auto, (max-width: 508px) 100vw, 508px\" \/><\/p>\r\n<p>At that time, the Offset take the last values of the counters. Then the D1 mini reconnects to Home assistant:<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8273\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome114.png\" alt=\"Reconnection of the D1 Mini\" width=\"503\" height=\"466\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome114.png 503w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome114-300x278.png 300w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/p>\r\n<p>Permanent counters include the value of offset + value of the counter of D1 (0).<\/p>\r\n<p>I run a little hot water and a little cold water, offsets do not move but the meters display the right values:<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8274\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome115.png\" alt=\"Consumption test\" width=\"506\" height=\"466\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome115.png 506w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/esphome115-300x276.png 300w\" sizes=\"auto, (max-width: 506px) 100vw, 506px\" \/><\/p>\r\n<p>So I keep only the last 3 meters for my Dashboard and for conso statistics.<\/p>\r\n<h2><span class=\"ez-toc-section\" id=\"Resultat\"><\/span>Result<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8291\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-scaled.jpg\" alt=\"Final result\" width=\"320\" height=\"452\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-scaled.jpg 1812w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-scaled-600x848.jpg 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-212x300.jpg 212w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-725x1024.jpg 725w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-768x1085.jpg 768w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-1087x1536.jpg 1087w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173642-1449x2048.jpg 1449w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8292\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-scaled.jpg\" alt=\"Final result\" width=\"319\" height=\"442\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-scaled.jpg 1849w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-scaled-600x831.jpg 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-217x300.jpg 217w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-740x1024.jpg 740w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-768x1063.jpg 768w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-1109x1536.jpg 1109w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_171840-1479x2048.jpg 1479w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-8293\" src=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-scaled.jpg\" alt=\"Final result\" width=\"321\" height=\"431\" srcset=\"https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-scaled.jpg 1905w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-scaled-600x806.jpg 600w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-223x300.jpg 223w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-762x1024.jpg 762w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-768x1032.jpg 768w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-1143x1536.jpg 1143w, https:\/\/www.sigalou-domotique.fr\/wp-content\/uploads\/2024\/12\/20250104_173050-1524x2048.jpg 1524w\" sizes=\"auto, (max-width: 321px) 100vw, 321px\" \/><\/p>\r\n<h2><span class=\"ez-toc-section\" id=\"Si_cetait_a_refaire_idees_ou_retour_dexperience\"><\/span>If it had to be done again (ideas or feedback)<span class=\"ez-toc-section-end\"><\/span><\/h2>\r\n<ul>\r\n<li>I would use a turbine with a temperature sensor even for cold water, I am curious to know the temperature especially in winter.<\/li>\r\n<\/ul>\r\n\r\n<p class=\"wp-block-paragraph\">&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>This article follows on from the previous article: Controlling water consumption<\/p>","protected":false},"author":1,"featured_media":2842,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,23,166],"tags":[],"class_list":["post-8260","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-domotique","category-jeedom-2","category-retex"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts\/8260","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=8260"}],"version-history":[{"count":0,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/posts\/8260\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/media\/2842"}],"wp:attachment":[{"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/media?parent=8260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/categories?post=8260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigalou-domotique.fr\/en\/wp-json\/wp\/v2\/tags?post=8260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}