This write-up will focus on using several of our components, Mod-EC, Mod-pH, and DS18B20 temperature sensor, ย in one device, to create a complete sensor box that works with 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 carrier board, Mod-EC, Mod-pH, and DS18B20 sensor (probe or thermowell)
1.
๐ฆ Install ESPHome
Follow the instructions on the ESPHome website.
2.
๐ Start a project
Type esphome wizard mod-box.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-box.yaml
. If you type esphome compile mod-box.yaml
you should see the project compile.
3.
๐ป 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 pH+EC
device_name: microfire-ph-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 components
external_components:
- source:
type: git
url: https://github.com/u-fire/ESPHomeComponents/
# https://esphome.io/components/i2c.html
i2c:
sda: 21
scl: 22
# https://esphome.io/components/sensor/dallas.html
dallas:
- pin: 23
id: dallas_temp
sensor:
- platform: dallas
index: 0
name: "Temperature"
id: water_temp
on_value:
then:
- component.update: ec
- component.update: ph
- platform: mod_ec
id: ec
update_interval: never
name: EC
temperature_sensor: water_temp
temperature_constant: 25.0
temperature_coefficient: 0.019
- platform: mod_ph
id: ph
update_interval: never
name: pH
temperature_sensor: water_temp
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: 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.
Make sure to change the dallas
section to match which pin the DS18B20 is connected to.
4.
๐ Connect everything
Now is a good time to ensure the module is connected to the ESP-device.
- Connect the probes by screwing the SMA-BNC connector to the board, then attach the probes to the connector.
- Connect the 1W pin on the carrier board to a pin on your ESP-device. Remember to match it to the
ONE_WIRE
definition from the step above. - Attach the DS18B20 sensor to the carrier board: black=GND, red=VCC, yellow=SIG
- 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
5.
โก๏ธ Upload
Type esphome run mod-box.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.
6.
๐ 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 device information, Mod-EC, Mod-pH, temperature measurements, and some buttons to calibrate and reset the device. You can create dashboards, scripts, and anything else Home Assistant can do from here.