Controlling water purity with Home Assistant

Hi all! I want to talk about a small and fairly simple case of using Home Assistant (hereinafter HA), but in my opinion very useful. This is monitoring the resource of main filters. The idea of ​​doing something like this has been bothering me for a long time and finally I got around to it.

So, introductory, our water is not very good, so the use of main filters is very justified, they collect quite a lot of dirt, and when they become clogged, the pressure decreases and some of the dirt can pass through them, so they need to be changed on time.

The filter collects this amount of dirt in a couple of months.

The filter collects this amount of dirt in a couple of months.

In my opinion, the best option for controlling replacement is the amount of water passed through the cartridge. My HA already collected information about water meter readings through a leak protection system; by the way, a description of how I developed the integration for it can be read here. The algorithm of my idea is this: when replacing the filter cartridge, you need to press a button, the counter of water passed through the filter is reset to zero and starts over again, so you can understand at any time how long each filter has worked.

To do this, let's create an auxiliary device (Settings -> Devices and services -> Auxiliary) “Number”

We fill in the fields, name the filter as it is convenient, the icon is also whatever you like, the minimum value is 0, the maximum value is higher, the main thing is that the maximum meter readings fit into the limit. Display mode – input field, step of course 1, unit of measurement m³.

In order not to go too far, here we will immediately create a “Date” field to record the date of the last replacement.

Now we’ll make a script that writes the current meter readings into a numeric field, and the current date into the date field. To do this, go to Settings -> Automations and scenes -> Scripts -> Create a new script, fill in the name and icon fields, single mode.

And add the “Call service” action, select the “Number: Set value” service, select the previously created field as the object, options will be offered. but then you will have to switch to text mode and modify the code as follows.

service: input_number.set_value
target:
  entity_id: input_number.filtr_vannaia_gv
data:
  value: "{{ states('sensor.watercounter_vannaia488') }}"

Where in entity_id you need to specify the id of the auxiliary field, you can view it by opening the field parameters. And in value you need to specify the identifier of the counter sensor, in my case it is called sensor.watercounter_vannaia488.

The second step is to add the “Call service” action, select the Date and time service: Set value, here everything is the same, only you need to write down the current date.

service: input_datetime.set_datetime
target:
  entity_id: input_datetime.data_poslednei_zameny_gv_vannaia
data:
  datetime: "{{ now() }}"

Thus, we created a script that, when executed, records the current meter readings and the current date. By calculating the difference between the current meter readings and those recorded in our field, we get how much the cartridge has currently worked. Let's make a sensor that will calculate this. To do this, we will need to edit the configuration.yaml file, add the following code.

template:
  - sensor:
    - name: "Фильтр ГВ Ванная отработал"
      state: >
        {% set hot_water_488 = states('sensor.watercounter_vannaia488') | float %}
        {% set hot_water_488_state = states('input_number.filtr_vannaia_gv') | float %}
        {{ (hot_water_488 - hot_water_488_state) | round(2, default=0) }}
      unit_of_measurement: m³
      device_class: water
      state_class: measurement 

If the template section already exists for you, then add it only from the next line to it. We indicate an arbitrary name here, then it will be needed to display indicators. We declare two variables, the first refers to the counter sensor, the second to our field, then the difference between them is calculated.

And since we have already opened configuration.yaml, let’s immediately create a sensor that will say that it’s time to change the cartridge.

template:
  - binary_sensor:
      - name: Фильтр ГВ ванная статус
        device_class: problem
        state: >
            {{ states('sensor.filtr_gv_vannaia_otrabotal')|float(0) > 10}} 

It checks the sensor readings from the previous step and if the value is greater than 10 (m³), which is how I determined the operating limit of the cartridge, then the sensor becomes true. Sensor identifier “sensor.filtr_gv_vannaia_otrabotal” is the name of the sensor from the previous step, to find out how HA did the transliteration, you can find it in the list and open the parameters, copy the identifier from there. If everything was done correctly, after rebooting the HA, you can start using the sensors.

I made such a block for each filter.

Where you can see how long it has worked, there is a button to launch the replacement script, the status of the filter and the date of the last replacement. I also use a binary sensor on the main page, where various problems are displayed, when it acquires the status true, it begins to be displayed there.

type: entity-filter
entities:
  - binary_sensor.filtr_gv_vannaia_status

If you have such a binary sensor, it is not difficult to make some kind of notifications, but as a rule, replacing filters is not very urgent and displaying the status in the list is enough.

That's all for me, I hope it was useful and not too tedious. For me, this solution does not look ideal. But I didn’t find or come up with another solution, so if anyone has their own solutions to a similar problem, I’ll read it in the comments.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *