Skip to content

Commit

Permalink
Mark some sensors internal to speed up device
Browse files Browse the repository at this point in the history
  • Loading branch information
tronikos committed Jul 14, 2024
1 parent 64e1988 commit bc316a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ substitutions:
volume_unit: 'gal'
i2c_scl: GPIO5 # D1
i2c_sda: GPIO4 # D2
# Set to false only if needed during manual calibration.
# Do not keep them at false since these slow down the ESP device
# and reduce the accuracy during high flow.
hide_magnetic_field_strength_sensors: 'true'
hide_half_rotations_total_sensor: 'true'

packages:
meter:
Expand All @@ -19,7 +24,7 @@ packages:
# file: esphome-gas-meter.yaml
# Or if you are using HMC5883L instead of QMC5883L:
# files: [esphome-water-meter.yaml, hmc5883l.yaml]
refresh: 0s
refresh: 0s
```
<img src="https://github.com/tronikos/esphome-magnetometer-water-gas-meter/assets/9987465/9363747e-ea4d-457b-b219-90f0192fcf8d" alt="Water meter in Home Assistant" width=40%>
Expand Down Expand Up @@ -127,6 +132,11 @@ The ethernet cable has 4 twisted pairs of wires. Use any solid wire color for th
volume_unit: 'gal'
i2c_scl: GPIO5 # D1
i2c_sda: GPIO4 # D2
# Set to false only if needed during manual calibration.
# Do not keep them at false since these slow down the ESP device
# and reduce the accuracy during high flow.
hide_magnetic_field_strength_sensors: 'true'
hide_half_rotations_total_sensor: 'true'
packages:
meter:
Expand All @@ -148,6 +158,11 @@ The ethernet cable has 4 twisted pairs of wires. Use any solid wire color for th
volume_unit: 'gal'
i2c_scl: GPIO5 # D1
i2c_sda: GPIO4 # D2
# Set to false only if needed during manual calibration.
# Do not keep them at false since these slow down the ESP device
# and reduce the accuracy during high flow.
hide_magnetic_field_strength_sensors: 'true'
hide_half_rotations_total_sensor: 'true'
packages:
meter:
Expand Down Expand Up @@ -209,7 +224,7 @@ To calibrate these just run a light stream of water/gas and press the "Calibrate

Alternatively:

1. Temporarily enable the Magnetic Field Strength X, Y, and Z sensors in HA.
1. Temporarily set `hide_magnetic_field_strength_sensors: 'false'` to show the Magnetic Field Strength X, Y, and Z sensors in HA.
2. Run a light stream of water/gas.
3. Observe which axis changes the most and its range.
4. Set the axis and thresholds. e.g. if y axis ranges from min to max use:
Expand All @@ -220,21 +235,13 @@ Alternatively:
Threshold upper = max - 0.25 * (max - min)
```
5. Disable the Magnetic Field Strength X, Y, and Z sensors in HA. Otherwise HA recorder will get overwhelmed.
5. Set `hide_magnetic_field_strength_sensors: 'true'`.

### Volume per half rotation

This depends on your specific water/gas meter model and its size.

To calibrate:

1. Temporarily enable the "Half rotations total" sensor in HA.
2. Write it down and also write down the reading on your water/gas meter.
3. After a few hours or even days of regular water/gas usage, write down both of them again.
4. Set this to the result of: diff of readings in volume_unit divided by diff of half rotations.
5. Disable the "Half rotations total" sensor in HA.

Alternatively you can search for specifications of your specific water/gas meter and its size. e.g.
You can search for specifications of your specific water/gas meter and its size. e.g.
for [Neptune T-10](https://www.riotronics.com/wp-content/uploads/2019/11/NT10-4P-WaterRead-pdf3.01.pdf):

Meter size | Pulses/Gallon
Expand All @@ -250,6 +257,14 @@ So for a 5/8" Neptune T-10 you will set this to `0.00864902` (2 / 231.24)
If you have the Flume water sensor you can use its lowest reported value. You can find it with:
`select min(min) from statistics_short_term, statistics_meta where statistics_meta.statistic_id = 'sensor.water_usage_current' and statistics_meta.id = metadata_id and min > 0;`

Alternatively:

1. Temporarily set `hide_half_rotations_total_sensor: 'false'` to show the "Half rotations total" sensor in HA.
2. Write it down and also write down the reading on your water/gas meter.
3. After a few hours or even days of regular water/gas usage, write down both of them again.
4. Set this to the result of: diff of readings in volume_unit divided by diff of half rotations.
5. Set `hide_half_rotations_total_sensor: 'true'`.

For water meters this defaults to `0.01008156 gal` which is for my 3/4" Badge Meter Model 35.
For gas meters this defaults to `0.125 ft³` which seems to be the most common in US.
If you have modified the `volume_unit` you have to manually convert this value.
Expand Down
11 changes: 7 additions & 4 deletions esphome-magnetometer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ substitutions:
volume_per_half_rotation_initial_value: '0.01008156'
flow_update_interval_seconds: '10'

hide_magnetic_field_strength_sensors: 'true'
hide_half_rotations_total_sensor: 'true'

esphome:
min_version: "2024.4.0" # This version includes https://github.com/esphome/esphome/pull/6456
# Default loop interval is 16ms. Setting it to 0 to make updates faster.
Expand Down Expand Up @@ -275,7 +278,7 @@ sensor:
field_strength_x:
id: ${prefix_id}qmc5883l_axis_x
name: ${prefix_name}Magnetic Field Strength X
disabled_by_default: true
internal: ${hide_magnetic_field_strength_sensors}
entity_category: diagnostic
on_raw_value:
then:
Expand All @@ -290,7 +293,7 @@ sensor:
field_strength_y:
id: ${prefix_id}qmc5883l_axis_y
name: ${prefix_name}Magnetic Field Strength Y
disabled_by_default: true
internal: ${hide_magnetic_field_strength_sensors}
entity_category: diagnostic
on_raw_value:
then:
Expand All @@ -305,7 +308,7 @@ sensor:
field_strength_z:
id: ${prefix_id}qmc5883l_axis_z
name: ${prefix_name}Magnetic Field Strength Z
disabled_by_default: true
internal: ${hide_magnetic_field_strength_sensors}
entity_category: diagnostic
on_raw_value:
then:
Expand Down Expand Up @@ -336,7 +339,7 @@ sensor:
name: ${prefix_name}Half rotations total
lambda: return id(${prefix_id}half_rotations_total);
update_interval: 1s
disabled_by_default: true
internal: ${hide_half_rotations_total_sensor}
entity_category: diagnostic
accuracy_decimals: 0
state_class: 'total_increasing'
Expand Down

0 comments on commit bc316a1

Please sign in to comment.