In this write-up, we will install ESPHome to get water conductivity measurements into Home Assistant.
- We will be working in a terminal and using a few commands
- You'll need a Home Assistant installation running
- An ESP-device
- A Mod-EC module and preferably a carrier board
📦 Install ESPHome
Follow the instructions on the ESPHome website.
🏁 Start a project
esphome wizard mod-ec.yaml in the terminal. Make sure the path on the terminal is where you want the project to be. Follow the steps, and there should be a .yaml file in the directory you ran the command in. For this write-up, it will be
mod-ec.yaml. If you type
esphome compile mod-ec.yaml you should see the project compile.
💻 Add some YAML and code
We'll make a custom sensor component to get the Mod-EC module working. This is done by adding some lines to the YAML.
The YAML file should be changed to the following:
substitutions: friendly_name: Microfire Mod-EC device_name: microfire-mod-ec esphome: name: $device_name esp32: board: esp32dev framework: type: arduino logger: api: ota: wifi: ssid: !secret wifi_ssid password: !secret wifi_password ap: ssid: $device_name password: !secret wifi_failover captive_portal: # import the mod-ec component external_components: - source: type: git url: https://github.com/u-fire/ESPHomeComponents/ # https://esphome.io/components/i2c.html i2c: sda: 21 scl: 22 sensor: - platform: mod_ec id: ec name: EC button: - platform: template id: ec_calibrate_low name: EC Calibrate Low 0.1 icon: mdi:format-vertical-align-bottom on_press: lambda: |- id(ec).calibrateLow(0.1); - platform: template id: ec_calibrate_mid name: EC Calibrate Mid 1.0 icon: mdi:format-vertical-align-center on_press: lambda: |- id(ec).calibrateMid(1.0); - platform: template id: ec_calibrate_high name: EC Calibrate High 10.0 icon: mdi:format-vertical-align-top on_press: lambda: |- id(ec).calibrateHigh(10.0); - platform: template id: ec_calibrate_reset name: EC Calibrate Reset icon: mdi:restore on_press: lambda: |- id(ec).calibrateReset(); - platform: factory_reset name: Restart with Factory Default Settings
Make sure you change the
wifi section to your network and password if you aren't using a secrets.yaml. Check that the
i2c section is using the correct pins.
🔌 Connect everything
Now is a good time to ensure the module is connected to the ESP-device.
- Connect the probe
- Make the I2C connections:
- Mod-EC SDA to controller SDA
- Mod-EC SCL to controller SCL
- Mod-EC GND to controller ground
- Mod-EC VCC to controller 3.3 or 5-volt
esphome run mod-ec.yaml It will compile the project and ask you which serial device to upload the code to. After that, you'll see the ESP debug output. If everything goes to plan, you should see a device has been discovered in Home Assistant.
🏠 Home Assistant
From within Home Assistant, press
Settings > Devices & Services and find the device in the ESPHome integration box. Click it and then click where it says
1 Device. You should see a screen with all the information, Mod-EC measurement, and some buttons to calibrate and reset the device. You can create dashboards, scripts, and anything else Home Assistant can do from here.
This example used a minimal amount of code and hardware. To get an accurate conductivity reading, you'll need temperature as well. Look at the Carrier Board for Home Assistant article to see how it looks with a DS18B20 sensor attached.