esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

Atlas Scientific EZO i2c sensors #766

Closed Neukam closed 3 years ago

Neukam commented 4 years ago

Describe the problem you have/What new integration you would like

I would like to see support for Atlas Scientific EZO sensors with i2c interface, specifically the ORP and PH sensors

Please describe your use case for this integration and alternatives you've tried:

I want to be able to fully automate my pool with salt water generator. I'm currently using a Sonoff 4ch running Tasmota to control the pump, SWG and lights and read from a DS18B20 temperature sensor. I would like to be able to add the Atlas Scientific sensors and switch to ESPHome so that i can control the runtime of the SWG based on ORP, and also monitor PH. These sensor modules could also be useful for a hydroponics system.

Additional context

There is a library with examples. There are datasheets and documentation on the product pages. The following EZO devices are available ORP PH Dissolved Oxygen Electrical Conductivity RTD Temperature Flow Meter Totalizer This could be useful for tracking domestic water usage 50 psi Pressure Sensor Peristaltic Dosing Pump RGB Color Sensor

Atlas Scientific also has a Hydroponics Kit which has an ESP8266 mounted on a carrier board with PH, Electrical Conductivity, and RTD Temperature EZO boards with a provision to add one additional EZO board. This could also be very useful for a pool controller. Their code for the ESP is open source and posted on their github.

dylonsease commented 4 years ago

User @ssieb has a custom component for these sensors. github com/ssieb/custom_components/tree/master/ezo

I have my sensors on a tentacle shield attached to an arduino mega, the scl and sda pins from the mega are attached to the D2 and D1 pins on a NodeMCU.

I created a folder called "custom-components" under my esphome folder and placed ssieb's "ezo" folder in it.

Here is the relevant part of my yaml file.

i2c:
  sda: D2
  scl: D1
  scan: True
  id: bus_a

  #ezo platform from: https://github.com/ssieb/custom_components
sensor:
  - platform: ezo
    id: ph_ezo
    name: "pH"
    address: 99
    accuracy_decimals: 2
    unit_of_measurement: "pH"

  - platform: ezo
    id: rtd_ezo
    name: "RTD Temperature"
    address: 101
    accuracy_decimals: 2
    unit_of_measurement: "°C"

  - platform: ezo
    id: ec_ezo
    name: "EC CN"
    address: 100
    accuracy_decimals: 0
    unit_of_measurement: "CN"

Here is a snip of how it looks in Home Assistant: image

I don't have much experience with esphome or arduino, but ssied's component made this easy.

ssieb commented 4 years ago

Ok, fine, I'll write up the docs and file a PR. :-)

dylonsease commented 4 years ago

Ok, fine, I'll write up the docs and file a PR. :-)

I was trying to get these sensors to work for the last couple days, stumbled across your repo and presto I was up and running. Thanks for putting it out there, I really appreciate it! So much that I had to share on this thread!

Neukam commented 4 years ago

Sweet! You guys are awesome! I'll be trying this out this weekend

iHakia commented 4 years ago

Hi guys, Thanks for the help implementing those sensors. I'm really trying to get this one working. for now, it seems that I have problem with the esphome folder structure or something. the files are located at \config(where my HA configuration yaml)\esphome\custom_components\ezo this is my code

esphome:
  name: nfatxxxxxlas
  platform: ESP8266
  board: esp01_1m
  includes:
    - ezo.h

i2c:
  sda: 4
  scl: 5
  scan: True
  id: bus_a

wifi:
  ssid: "xxxxxx"
  password: "xxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "xxxxFallback Hotspot"
    password: "LYoPZoHB4pdh"

sensor:
  - platform: ezo
    id: ph_ezo
    address: 99
    unit_of_measurement: "pH"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxxx"

ota:
  password: "xxxxxxxxxx"

Unfortunately I keep getting the message "platform not found. 'sensor. ezo'" anyone have an idea? Help much appreciated 👍

ssieb commented 4 years ago

Don't use the include. Do you have all the files, including the two python ones in the ezo directory?

iHakia commented 4 years ago

Don't use the include. Do you have all the files, including the two python ones in the ezo directory? I guess that yes. I removed the include. still not working :/ image

ssieb commented 4 years ago

Which esphome version are you using? You might need to use dev.

dylonsease commented 4 years ago

Double check your folder path. Here is mine. It looks like I had a typo in my instructions above. Screenshot_20200724-093354

ssieb commented 4 years ago

That looks the same as his. It's likely that it needs something that is only in dev. It would be something in the config parsing because that would make it not find the sensor code. If you use the cli esphome to compile it, you would see the error message.

dylonsease commented 4 years ago

They typed it with the underscore but the picture of their config has a hyphen. Unless I'm not seeing something since I'm on mobile.

ssieb commented 4 years ago

Oh, good catch! I completely missed that. :facepalm:

iHakia commented 4 years ago

Oh, good catch! I completely missed that. 🤦

thanks mrgoose2 - That Worked!!! Thanks for that 👍

iHakia commented 4 years ago

So now we now that custom_componenets works while using normal esphome version. Now I have all my EZP sensors working and I this is how it's look on my config side. Is there a way to do the Calibration side of things also? PH calibration EC calibration DO calibration ?

`sensor:

ssieb commented 4 years ago

You can do the temperature calibration in a lambda using id(ph_ezo).set_tempcomp_value(rtd_ezo.state); for example. You need to decide when you want to calibrate it based on time or change in temperature.

ssieb commented 4 years ago

I haven't quite finished the documentation for the PR yet.

iHakia commented 4 years ago

You can do the temperature calibration in a lambda using id(ph_ezo).set_tempcomp_value(rtd_ezo.state); for example. You need to decide when you want to calibrate it based on time or change in temperature.

You are great, How about the pH calibration? In the Atlas documents the commands are ph:cal,mid,7 calibrate to pH 7
ph:cal,low,4 calibrate to pH 4
ph:cal,high,10 calibrate to pH 10
ph:cal,clear clear calibration

is this can be done?

ssieb commented 4 years ago

I'll have to look up the docs again. I don't have any of these sensors and I had only been asked about the temperature compensation.

ssieb commented 4 years ago

I checked the docs and the calibration really should be done from a PC. It's not something that you're going to do regularly, it's mostly a one-time action. I've now made a pull request for bringing the component into esphome.

iHakia commented 4 years ago

I checked the docs and the calibration really should be done from a PC. It's not something that you're going to do regularly, it's mostly a one-time action. I've now made a pull request for bringing the component into esphome.

Well I can say that until now it works great. The calibration part of the pH is highly important and should be done every month (for hydroponic use) and in order to do it from pc you basically have to reflash the esp with atlas firmware and use their uart command line. it's a harsh task to do.

is there a way to send i2c commands to the module?

ssieb commented 4 years ago

I don't think Atlas has ESP firmware. Their firmware is in the sensor board. You connect the sensor board to the PC to send it commands. Nothing to do with the ESP device. How have you been doing the calibrations now? And how did you get it into i2c mode? You could send arbitrary i2c commands using lambdas if you really wanted to.

iHakia commented 4 years ago

Check this out https://www.atlas-scientific.com/files/Wi-Fi-Pool-kit-setup-guide.pdf it's based on esp. maybe we can fish it out somehow. also, I don't really know how to use lambdas, Any good read recommendation?

ssieb commented 4 years ago

Unless you're intending to make that, it's much more complicated than you need. Just follow the instructions in https://www.atlas-scientific.com/files/pH_EZO_Datasheet.pdf. It's too complicated to add the calibrations to esphome and out of scope. You can read about lambdas at https://esphome.io/guides/automations.html. It's a method of embedding C++ code in your esphome configs.

krazykatz69 commented 3 years ago

Hi ssieb,

I bought the Atlas Scientific Wi-Fi Hydroponics Kit, do you know if it is possible to get this to work over i2c? I am getting an error saying Found no i2c devices. See below:

[21:32:31][C][i2c:028]: I2C Bus: [21:32:31][C][i2c:029]: SDA Pin: GPIO4 [21:32:31][C][i2c:030]: SCL Pin: GPIO5 [21:32:31][C][i2c:031]: Frequency: 50000 Hz [21:32:31][I][i2c:033]: Scanning i2c bus for active devices... [21:32:31][I][i2c:049]: Found no i2c devices!

[21:32:31][C][logger:186]: Level: DEBUG [21:32:31][C][logger:187]: Log Baud Rate: 115200 [21:32:31][C][logger:188]: Hardware UART: UART0

[21:32:31][C][ezo.sensor:014]: Unit of Measurement: 'pH' [21:32:31][C][ezo.sensor:014]: Accuracy Decimals: 2 [21:32:31][C][ezo.sensor:015]: Address: 0x63 [21:32:31][C][ezo.sensor:018]: Update Interval: 60.0s

[21:32:31][C][ezo.sensor:014]: Unit of Measurement: '°C' [21:32:31][C][ezo.sensor:014]: Accuracy Decimals: 2 [21:32:31][C][ezo.sensor:015]: Address: 0x66 [21:32:31][C][ezo.sensor:018]: Update Interval: 60.0s

[21:32:31][C][ezo.sensor:014]: Unit of Measurement: 'CN' [21:32:31][C][ezo.sensor:014]: Accuracy Decimals: 0 [21:32:31][C][ezo.sensor:015]: Address: 0x64 [21:32:31][C][ezo.sensor:018]: Update Interval: 60.0s [21:32:31][C][captive_portal:169]: Captive Portal: [21:32:31][C][ota:029]: Over-The-Air Updates: [21:32:31][C][ota:030]: Address: 192.168.0.144:8266 [21:32:31][C][ota:032]: Using Password. [21:32:31][C][api:095]: API Server: [21:32:31][C][api:096]: Address: 192.168.0.144:6053 [21:32:32][W][i2c:086]: Requesting 20 bytes from 0x64 failed! [21:32:32][E][ezo.sensor:049]: read error [21:32:34][W][i2c:070]: Received NACK on transmit of address 0x66 [21:32:34][W][i2c:086]: Requesting 20 bytes from 0x66 failed!

krazykatz69 commented 3 years ago

I think that I may just need to enable pin 14, 12 and 15 on the huzzah esp8266 to power the EZO circuit boards , but am unsure how to achieve this.

krazykatz69 commented 3 years ago

Got it working, added the below to the code:

switch:

krazykatz69 commented 3 years ago

I can see that the sensors are working in the ESPhome logs but don't know how to add them as entities in HA.

[16:34:45][D][sensor:092]: 'pH': Sending state 5.77700 pH with 2 decimals of accuracy [16:34:56][D][sensor:092]: 'EC CN': Sending state 829.29999 CN with 0 decimals of accuracy [16:34:58][D][sensor:092]: 'RTD Temperature': Sending state 20.14200 °C with 2 decimals of accuracy

I have enable newly discovered entities enabled in esphome.

I have another esp8266 which is up and running and can see all 5 entities connected to that one.

Any help would be much appreciated.

ssieb commented 3 years ago

This isn't the right place for getting help for things like that. The esphome Discord channel would be best or the home assistant forum.

Morbidbystandard commented 3 years ago

Tasmota now has calibration under i2c operation. Some of us like to calibrate weekly during a reservoir change.

jesserockz commented 3 years ago

Tasmota now has calibration under i2c operation. Some of us like to calibrate weekly during a reservoir change.

Please create a new feature-request for this.

iyotee commented 3 years ago

id(ph_ezo).set_tempcomp_value(rtd_ezo.state);

Can you please give an exemple, i always have a : Lambas is an invalid option for sensor.ezo. Please check the indentation.

I tried all the indentation possible. Thx ( here it looks like there are no indentation, it's only a github frontend displaying problem. )

`switch:

sensor:

nilsi commented 2 years ago

Hi @ssieb did you ever manage to get the PR out there for this? Very interested as well. Will probably try your custom component if not.

ssieb commented 2 years ago

https://github.com/esphome/esphome/pull/1239 was merged almost a year ago. See https://esphome.io/components/sensor/ezo.html