In this write-up, we will install ESPHome to get pH 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-pH module and preferably a carrier board
📦 Install ESPHome
Follow the instructions on the ESPHome website.
🏁 Start a project
esphome wizard mod-ph.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-ph.yaml. If you type
esphome compile mod-ph.yaml you should see the project compile.
💻 Add some YAML and code
We'll make a custom sensor component to get the Mod-pH 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-pH device_name: microfire-mod-ph 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-ph 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_ph id: ph name: pH update_interval: 15s button: - platform: template id: ph_calibrate_low name: pH Calibrate Low 4.0 icon: mdi:format-vertical-align-bottom on_press: lambda: |- id(ph).calibrateLow(4.0); - platform: template id: ph_calibrate_mid name: pH Calibrate Mid 7.0 icon: mdi:format-vertical-align-center on_press: lambda: |- id(ph).calibrateMid(7.0); - platform: template id: ph_calibrate_high name: pH Calibrate High 10.0 icon: mdi:format-vertical-align-top on_press: lambda: |- id(ph).calibrateHigh(10.0); - platform: template id: ph_calibrate_reset name: pH Calibrate Reset icon: mdi:restore on_press: lambda: |- id(ph).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-pH SDA to controller SDA
- Mod-pH SCL to controller SCL
- Mod-pH GND to controller ground
- Mod-pH VCC to controller 3.3 or 5-volt
esphome run mod-ph.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-pH measurement, and some buttons to calibrate and reset the device. You can create dashboards, scripts, and anything else Home Assistant can do from here.