Setting up Atlas Scientific sensors in ESPHome (aquaponics kit)

Home Assistant automation projects, questions, etc. go here.
HydroRay
LED-Curious
LED-Curious
Reactions:
Posts: 16
Joined: Tue Feb 22, 2022 5:58 pm

Here's the code I used in order to get my Aquaponics Kit from Atlas Scientific to read data. It's not 100% yet as I haven't worked on calibrating or anything (I'll update when I get there), but I know just getting this far took me probably 5 days of messing around with ESPHome, Tasmota, and just a sprinkle of Arduino.

But first, see my first hand account of Tasmota vs ESPHome with the goal getting everything in Home Assistant for automation (like I believe we're all going for).

I got frustrated with esphome and this forum made me think it was going to be easier to figure out tasmota... Well I was able to get all the sensors to recognize the programming but not send the information back to me.
Getting it that close in Tasmota involved:
- taking the code that Tasmota flashes on your device at the original setup (I have the Atlas Scientific Aquaponics Kit that's powered by an Adafruit Huzzah32 Feather)
- opening it up with Gitpod
- modifying the "platformio_override.ini" for esp32 devices instead of esp8266 AND
- modifying the "user_config_override.h" to #define the ezo sensors, etc, then
- running in the Terminal

Code: Select all

platformio run -e tasmota32
and praying it builds all the way
- downloading the "tasmota32.bin" file to my computer and moving it into the esptool folder
- opening my computers Terminal in the esptool folder and running the following commands
-

Code: Select all

esptool.py --port COM7 erase_flash
(My USB port is COM7)
-

Code: Select all

esptool.py --port COM7 write_flash -fs 2MB -fm dout 0x0 tasmota32.bin
This is when it's ready to go back into Tasmota where you can define if the pins should be "high" or "low" (HUM, CO2, and RTD high. EC, DO, and pH low) so that the proper current is flowing to get readings.

But that's where I got stuck because I couldn't figure out how to use MQTT to share data with Home Assistant.

The big thing for a beginner like me that I couldn't figure out until today was that both i2c and gpio, while located at the same place, have to be defined in order for readings to happen.

I have zero coding experience and am working on automating a pretty significantly sized hydroponic system. I was able to get a little esp32-CAM setup in ESPHome yesterday so I decided to give ESPHome another try for the kit.

here's some code so hopefully you won't have to spend as long as I did figuring it out :D
(or if you're a seasoned vet you can have a good laugh)

Code: Select all

esphome:
  name: lettuce-hub-v4

esp32:
  board: featheresp32
  framework:
    type: arduino

i2c:
  sda: 23
  scl: 22
  scan: True
  id: bus_a
  
binary_sensor:
  - platform: gpio
    name: "HUM"
    pin:
      number: 32
      inverted: false
      mode:
        input: true
        pullup: true
  - platform: gpio
    name: "CO2"
    pin:
      number: 15
      inverted: false
      mode:
        pullup: true
        input: true
  - platform: gpio
    name: "RTD"
    pin:
      number: 33
      mode:
        input: true
        pullup: true
    filters:
      - delayed_on: 100ms
  - platform: gpio
    name: "EC"
    pin:
      number: 27
      mode:
        input: true
        pullup: false
  - platform: gpio
    name: "DO"
    pin:
      number: 12
      mode:
        input: true
        pullup: false
  - platform: gpio
    name: "pH"
    pin:
      number: 13
      mode:
        input: true
        pullup: false


sensor:
  - platform: ezo
    id: EZO_HUM
    name: "HUM"
    device_class: humidity
    state_class: measurement
    address: 111
    unit_of_measurement: "%"
    on_raw_value:
      then:
        logger.log: "Humidity f****** worked!!!"
  - platform: ezo
    id: EZO_CO2
    name: "CO2"
    device_class: carbon_dioxide
    state_class: measurement
    address: 105
    unit_of_measurement: "ppm"
  - platform: ezo
    id: EZO_RTD
    name: "RTD"
    device_class: temperature
    state_class: measurement
    address: 0x66
    accuracy_decimals: 2
    unit_of_measurement: temperature
  - platform: ezo
    id: EZO_EC
    name: "EC"
    state_class: measurement
    address: 100
    accuracy_decimals: 0
    unit_of_measurement: "CN"
  - platform: ezo
    id: EZO_DO
    name: "DO"
    state_class: measurement
    address: 97
    unit_of_measurement: "DO"
  - platform: ezo
    id: EZO_pH
    name: "PH"
    device_class: ""
    state_class: measurement
    address: 99
    accuracy_decimals: 2
    unit_of_measurement: "pH"
I guess the binary_sensor: is how you define if the pin should be high/low as well as let HA know it's got data you want, while the sensor: lets HA know what kind of data and how often it should give it to you.

For whatever reason I still can't get the co2 sensor to respond, but I figured 5/6 was still pretty good.

Sorry if this post is a little long but I've been creeping around this forum for a while now for advice/guidance and I actually, finally have something I think is worth contributing... The complete beginner's account.

-Ray
stud
LED Lover
LED Lover
Reactions:
Posts: 143
Joined: Wed Jun 03, 2020 4:19 pm
Location: Canada

Rebuilt Tasmota working 100% for me for the last year + , im a fan of Atlas Scientific for the last 5 years .
I also run 3 atlas scientific ezo-co2 sensors with no problem ,
my 2 cents !
HydroRay
LED-Curious
LED-Curious
Reactions:
Posts: 16
Joined: Tue Feb 22, 2022 5:58 pm

maybe you can give me a hand with the co2 sensor!

These are the relevant lines from the install/boot:

WARNING GPIO15 is a Strapping PIN and should be avoided.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why- ... pping-pins
- The kit has the co2 sensor set to gpio15. Not sure if it being a strapping pin matters, because the DO sensor is also on a strapping pin and it seems to be working

[09:28:00][C][i2c.arduino:038]: I2C Bus:
[09:28:00][C][i2c.arduino:039]: SDA Pin: GPIO23
[09:28:00][C][i2c.arduino:040]: SCL Pin: GPIO22
[09:28:00][C][i2c.arduino:041]: Frequency: 50000 Hz
[09:28:00][C][i2c.arduino:044]: Recovery: bus successfully recovered
[09:28:00][i2c.arduino:054]: Results from i2c bus scan:
[09:28:00][i2c.arduino:060]: Found i2c device at address 0x61
[09:28:00][i2c.arduino:060]: Found i2c device at address 0x63
[09:28:00][i2c.arduino:060]: Found i2c device at address 0x64
[09:28:00][i2c.arduino:060]: Found i2c device at address 0x66
[09:28:00][i2c.arduino:060]: Found i2c device at address 0x6F

- co2 should be found at address 0x69 but isn't

[09:28:00][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'CO2'
[09:28:00][C][gpio.binary_sensor:016]: Pin: GPIO15

[09:31:18][C][ezo.sensor:015]: EZO 'CO2'
[09:31:18][C][ezo.sensor:015]: Device Class: 'carbon_dioxide'
[09:31:18][C][ezo.sensor:015]: State Class: 'measurement'
[09:31:18][C][ezo.sensor:015]: Unit of Measurement: 'ppm'
[09:31:18][C][ezo.sensor:015]: Accuracy Decimals: 0
[09:31:18][C][ezo.sensor:016]: Address: 0x69
[09:31:18][C][ezo.sensor:019]: Update Interval: 60.0s

as for how I've got it coded:

Code: Select all

binary_sensor:
  - platform: gpio
    name: "CO2"
    pin:
      number: 15
      mode:
        pullup: true
        input: true

sensor:
  - platform: ezo
    id: EZO_CO2
    name: "CO2"
    device_class: carbon_dioxide
    state_class: measurement
    address: 0x69
    unit_of_measurement: "ppm"
    
I know I'm missing something because when I put it in Tasmota earlier I was able to get the led on the sensor to stay blue (like all the other sensors) and when I look at the HA entity card it says the sensor is "on". That makes me think it's not being told to get data and send, which makes me think it's an issue with the "sensor:" code and not the "binary_sensor:" code... or maybe it should be classified as something else?

Any advice is extra welcome! Thanks

P.S. has anyone found/written any code for calibrating in HA? I've found a couple pull requests that have the code, but I can't get it flashed on my device because of errors.

This is the one that's tested on esp32 and I wish wish wish I could get working: https://github.com/esphome/esphome/pull/1684
This one is tested on esp8622 but looks to have the same calibration ability: https://github.com/esphome/esphome/pull/1865

P.P.S. I found and added some code to add to the humidity sensor if anyone has one (because it reads temp, humidity, and dew point). Here it is:

Code: Select all

sensor:
  - platform: ezo
    id: ezo_hum
    name: "Humidity"
    device_class: humidity
    state_class: measurement
    address: 111
    accuracy_decimals: 1
    unit_of_measurement: "%"
  - platform: ezo
    id: ezo_hum_temp
    name: "Air Temp"
    device_class: temperature
    state_class: measurement
    address: 111
    filters:
    - lambda: return x * (9.0/5.0) + 32.0;
    unit_of_measurement: "°F"
  - platform: template
    name: "Dew Point"
    lambda: |-
      return (243.5*(log(id(ezo_hum).state/100)+((17.67*id(ezo_hum_temp).state)/
      (243.5+id(ezo_hum_temp).state)))/(17.67-log(id(ezo_hum).state/100)-
      ((17.67*id(ezo_hum_temp).state)/(243.5+id(ezo_hum_temp).state))));
    filters:
    - lambda: return x * (9.0/5.0) + 32.0;
    unit_of_measurement: "°F"
stud
LED Lover
LED Lover
Reactions:
Posts: 143
Joined: Wed Jun 03, 2020 4:19 pm
Location: Canada

have you tried wt Tasmota ? try it , i did get it to work on ESPHome last year , but i never figured how to calibrate , on Tasmota i can calibrate very easy on Tasmota Console or by sending a command or via mqtt on HA and its also HA friendly . my EZO-CO2 is also on Tasmota for the last year on a wemos-d1 running Tasmota 9 , no need for calibration untill now , the TDS and PH after 1 year i only calibrated once and that time it was offset by very little i do verify both every ~2 weeks , the sensors also sit in my water reservoir 24/7 .
Atlas Scientific is doing a very good job building these sensors for us . they are not cheap in price but they are really well built and quality !!!!
stud
LED Lover
LED Lover
Reactions:
Posts: 143
Joined: Wed Jun 03, 2020 4:19 pm
Location: Canada

For ESPHome help Also chk this post :

viewtopic.php?f=35&t=5771&hilit=Ezo+ph
Last edited by stud on Fri Apr 15, 2022 12:17 am, edited 1 time in total.
HydroRay
LED-Curious
LED-Curious
Reactions:
Posts: 16
Joined: Tue Feb 22, 2022 5:58 pm

So I've spent most of the day trying to re-setup Tasmota but I'm stuck at the exact same place I was before...

I'm unable to get the sensors to show up on the WebUI Main Menu, let alone figure out how to set up calibration, automation, etc.

I did figure out how to get the basic MQTT communication with HA though...

Are there some instructions somewhere on how to get the sensors to appear?

Thanks for any help!
stud
LED Lover
LED Lover
Reactions:
Posts: 143
Joined: Wed Jun 03, 2020 4:19 pm
Location: Canada

Did you configure the gpios for i2c ?
If yes ,
Type this in console to see if the device is visible : i2cscan

Code: Select all

01:35:51.672 CMD: i2cscan
01:35:51.709 MQT: stat/atlaskit/RESULT = {"I2CScan":"Device(s) found at 0x63 0x64 0x66"}
also :
did you install the Tasmota i compiled ? or from tasmota github ? if you installed the one from tasmota github , the Atlas libraries are not available by default .
and you wont see the sensors
you can read it here :
https://tasmota.github.io/docs/EZO/
HydroRay
LED-Curious
LED-Curious
Reactions:
Posts: 16
Joined: Tue Feb 22, 2022 5:58 pm

- I configured the gpios and when I did the i2cscan i would get back "error on 0x07" or something (an address that doesn't exist)

- I installed my own build (via gitpod building a new tasmota32.bin file and esptool.py flashing it on) that had ezo's enabled (and my wifi/mqtt settings) which seemed to install successfully, but I downloaded and flashed your 11.0.0 version just to be safe.

What I didn't do was know how to setup the board. I saw

Code: Select all

{"NAME":"HUZZAH32","GPIO":[0,0,0,0,4709,0,1,1,1,288,1,1,1,1,0,1,0,0,608,640,0,4705,4704,1,0,0,0,0,1,1,4706,4710,4708,0,0,4707],"FLAG":0,"BASE":1}
and first tried to put it in both consoles with no luck, only to discover if you go under the "Configure Other" tab and paste the code in there, once you save it resets and POOF I have DO, EC, and possibly 3 other that are currently on analog's I need to change.
stud
LED Lover
LED Lover
Reactions:
Posts: 143
Joined: Wed Jun 03, 2020 4:19 pm
Location: Canada

nice you compile it yourself , its the new version 11.1.0 ? if yes share it , ill try here .if you enabled all the ezo sensors
if your aquaponic kit is running the Huzzah esp32 most be the same like my new hydrokit i ordered recently ,
my older ones are on Feather huzzah esp8266
follow the other post and ull get it working on Tasmota + super easy to do the calibration on it .
HydroRay
LED-Curious
LED-Curious
Reactions:
Posts: 16
Joined: Tue Feb 22, 2022 5:58 pm

I've got a Aquaponics kit and a Hydroponics kit actually. I figured if I could get the aquaponics kit to work I could just copy and paste into the hydro kit with no issues.

- I'm going to be running out of two separate reservoirs (technically 3 if you count the seedlings, but that's flood & drain, so no need to monitor constantly) with different ppm/EC/pH settings. Getting one Aquaponics kit adds Dissolved Oxygen, Humidity/Temp, and CO2 which I feel would be beneficial but not necessary to have twice.

I attached the .bin file... let me know if it works for you.

Also, I saw somewhere on here people setting the pins as only Output Hi and Lo but would it make any sense to use the "ADC pH, ADC Temp" or "Switch_n, Switch" options?
Attachments
tasmota32-HydroRay.zip
(960.14 KiB) Downloaded 79 times
Post Reply