SDI-12 Logger through HomeAssistant

Connection is good, ESP reacts to HA switch, so I guess you are close. Two things

  • Did you check that your SDI-12 sensor has adress ‘1’ and is actually working?
  • I think you need to feed the modbus with ASCII? Try data: '49 77 33' for your read sensor

Edit: You might need to play around with the ASCII formatting: Convert a String to ASCII Code - Online String Tools
I haven’t looked into the serial connection of the Liudr board for compatibility (maybe Liudr has some documentation about this on his website?)

yes i have confirmed the sensor is working and i have changed the sensor address to 1. i used an android app “usb serial terminal” connected via the usb.

i tried the ‘49 77 33’, no luck, logs look the same as the ones i posted above.

liudr sell a version of his board without the usb port and chip (so only has the serial port for coms) called the SDI-12 TTL adapter, so i presume compatibility shouldnt be an issue?.

I guess that TTL serial is also on your SDI-12 board? Maybe ask Liudr what protocol is used for TTL coms, he seems responsive to these kind of questions.

ok quick update, i have been in contact with dr liu about using the serial connectror on his board as opposed to the usb and it turns out there are a couple of extra steps to hopefully get this to work.

first there is a couple of pads that need bridgeing on the pcb labled “FT_RST” to disable the usb serial port so the uart serial port can be used instead.

next the serial connection on the liudr board has both 3.3v tx and 5v tx pins, the esp32 wants 3.3v but on the usb version of the liudr board the 3.3v tx is not fully populated with the required components it is missing 2 10k resistors, so you need to add 2 resistors or use a seperate logic level converter and use the 5v tx on the uart serial port.

i have went with the level convertor and i am now pretty confident that everything is wired correctly, i have not had chance to try it out yet but fingers crossed this should work.

1 Like

starting to get somewhere, using the code below i have managed to get two basic switches on the dashboard sending the commands 1M! and 1D0! and finally have a response from the sensor!!!.

does everthing look correct?.

any pointers on how i go about seperating out the different data from the sensor and how do i save the data to a csv file to log?.

esphome:
  name: acclimatdr-310w
  platform: ESP32
  board: esp-wrover-kit
  includes:
    - uart_read_line_sensor.h
    
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Acclima Tdr-310W"
    password: "ytxcMUCZwHJt"

captive_portal:

# Enable logging
logger:
  level: VERBOSE #makes uart stream available in esphome logstream
  baud_rate: 0 #disable logging over uart

# Enable Home Assistant API
api:

ota:

uart:
  id: tdr_wc_ec
  tx_pin: 16
  rx_pin: 17
  baud_rate: 9600


text_sensor:
- platform: custom
  text_sensors:
    id: "tdr_wc_ec_uart"
  lambda: |-
    auto tdr_wc_ec_sensor = new UartReadLineSensor(id(tdr_wc_ec));
    App.register_component(tdr_wc_ec_sensor);
    return {tdr_wc_ec_sensor};
    
switch:
  - platform: uart
    name: "read sensor"
    data: '1M!'
    
  - platform: uart
    name: "get measurement"
    data: '1D0!'

[16:37:18][C][logger:233]: Logger:
[16:37:19][C][logger:234]:   Level: VERBOSE
[16:37:19][C][logger:235]:   Log Baud Rate: 0
[16:37:19][C][logger:236]:   Hardware UART: UART0
[16:37:19][C][uart.arduino_esp32:107]: UART Bus:
[16:37:19][C][uart.arduino_esp32:108]:   TX Pin: GPIO16
[16:37:19][C][uart.arduino_esp32:109]:   RX Pin: GPIO17
[16:37:19][C][uart.arduino_esp32:111]:   RX Buffer Size: 256
[16:37:19][C][uart.arduino_esp32:113]:   Baud Rate: 9600 baud
[16:37:19][C][uart.arduino_esp32:114]:   Data Bits: 8
[16:37:19][C][uart.arduino_esp32:115]:   Parity: NONE
[16:37:19][C][uart.arduino_esp32:116]:   Stop bits: 1
[16:37:19][C][uart.switch:040]: UART Switch 'read sensor'
[16:37:19][C][uart.switch:040]: UART Switch 'get measurement'
[16:37:19][C][captive_portal:144]: Captive Portal:
[16:37:19][C][mdns:084]: mDNS:
[16:37:19][C][mdns:085]:   Hostname: acclimatdr-310w
[16:37:19][V][mdns:086]:   Services:
[16:37:19][V][mdns:088]:   - _esphomelib, _tcp, 6053
[16:37:19][V][mdns:090]:     TXT: version = 2022.2.6
[16:37:19][V][mdns:090]:     TXT: mac = 94b97e7b94d0
[16:37:19][V][mdns:090]:     TXT: platform = ESP32
[16:37:19][V][mdns:090]:     TXT: board = esp-wrover-kit
[16:37:19][C][ota:085]: Over-The-Air Updates:
[16:37:19][C][ota:086]:   Address: acclimatdr-310w.local:3232
[16:37:19][C][api:138]: API Server:
[16:37:19][C][api:139]:   Address: acclimatdr-310w.local:6053
[16:37:19][C][api:143]:   Using noise encryption: NO
[16:37:25][D][switch:013]: 'read sensor' Turning ON.
[16:37:25][D][switch:037]: 'read sensor': Sending state ON
[16:37:25][D][uart.switch:020]: 'read sensor': Sending data...
[16:37:25][D][switch:037]: 'read sensor': Sending state OFF
[16:37:25][V][text_sensor:016]: 'tdr_wc_ec_uart': Received new state 10025
[16:37:25][D][text_sensor:067]: 'tdr_wc_ec_uart': Sending state '10025'
[16:37:25][V][text_sensor:016]: 'tdr_wc_ec_uart': Received new state 1
[16:37:25][D][text_sensor:067]: 'tdr_wc_ec_uart': Sending state '1'
[16:37:32][D][switch:013]: 'get measurement' Turning ON.
[16:37:32][D][switch:037]: 'get measurement': Sending state ON
[16:37:32][D][uart.switch:020]: 'get measurement': Sending data...
[16:37:32][D][switch:037]: 'get measurement': Sending state OFF
[16:37:32][V][text_sensor:016]: 'tdr_wc_ec_uart': Received new state 1+0.0+23.0+1.1+0+0
[16:37:32][D][text_sensor:067]: 'tdr_wc_ec_uart': Sending state '1+0.0+23.0+1.1+0+0'

Looking good @sar1! Can you find the ‘tdr_wc_ec_uart’ sensor in home assistant? And does it’s value update with lines like ‘1+0.0+23.0+1.1+0+0’? Than you can point my code towards that sensor. If you go into developer tools in home assistant, and check your entities you should find the full name of your sensor. Probably something like ‘sensor.tdr_wc_ec_uart’

If you look back at my first post, at the configuration.yaml; you can edit the template and use the rest of my code.

So change sensor.serial_sensor to your SDI-12 output sensor here:

  - platform: template
    sensors:
      sensor_number_s1:
        friendly_name: Sensor Address 1
        value_template: >
          {% if '1' in states('sensor.serial_sensor') [0:1] -%}                
            {{ states('sensor.serial_sensor').split('+')[0] }}
          {% else -%}
            {{ states.sensor.sensor_number_s1.state }}
          {% endif -%}

This particular code looks for a ‘1’ inside the SDI-12 raw output from your ESP, then creates another sensor named ‘Sensor Adress 1’ that will simply display the sensor address, since this is the first thing to be extracted from the raw SDI-12 string. Later I repeat these steps with volumetric water, temperature and EC, I basically extract the value between the + signs in the raw string, and convert these to new home assistant sensors seperately. So you do have to change the same sensor for volumetric water content, temperature or which ever value your sensor puts in the SDI-12 string.

Later I combine all the newly created sensors in a home assistant automation, and group them in a message to log them. You can copy the automation and see if it works for you.

hey rik, i had put this on the back burner for a month or two but now i have found some time i am back on it.

i havent done anymore since your last post, only installing all the components in box ready for use.
i did add a 2 channel relay board to control 2 24v irrigation valves and have managed to add the code to get 2 bottons on the home assistant dashboard and they control the valves fine.

once i had everything wired up in the new box i checked the logs from the esp32 and its now no longer displaying the readings from the acclima sensor correctly anymore?, the data is still returned sometimes but now comes in with more odd data?.
i have included some pics of the new logs so you can compare to the old ones, i havent changed any code since our last conversation when it was working correctly?, only adding a little bit of code for gpio pins for the valve relays?.

also in your last post you asked if the ‘tdr_wc_ec_uart’ sensor shows up in home assistant/developertools/entities, the answer is no it does not show up?.

any light you could shed on this would be very much appriciated.

yaml

esphome:
  name: acclimatdr-310w
  platform: ESP32
  board: esp-wrover-kit
  includes:
    - uart_read_line_sensor.h
    
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Acclima Tdr-310W"
    password: "ytxcMUCZwHJt"

captive_portal:

# Enable logging
logger:
  level: VERBOSE #makes uart stream available in esphome logstream
  baud_rate: 0 #disable logging over uart

# Enable Home Assistant API
api:

ota:

uart:
  id: tdr_wc_ec
  tx_pin: 16
  rx_pin: 17
  baud_rate: 9600


text_sensor:
- platform: custom
  text_sensors:
    id: "tdr_wc_ec_uart"
  lambda: |-
    auto tdr_wc_ec_sensor = new UartReadLineSensor(id(tdr_wc_ec));
    App.register_component(tdr_wc_ec_sensor);
    return {tdr_wc_ec_sensor};
    
switch:
  - platform: uart
    name: "read sensor"
    data: '1M!'
    
  - platform: uart
    name: "get measurement"
    data: '1D0!'

  - platform: gpio
    pin: 26
    name: "mix relay"
    inverted: yes
    
  - platform: gpio
    pin: 27
    name: "irrigation relay"
    inverted: yes


[14:09:22][C][logger:233]: Logger:
[14:09:22][C][logger:234]: Level: VERBOSE
[14:09:22][C][logger:235]: Log Baud Rate: 0
[14:09:22][C][logger:236]: Hardware UART: UART0
[14:09:22][C][uart.arduino_esp32:107]: UART Bus:
[14:09:23][C][uart.arduino_esp32:108]: TX Pin: GPIO16
[14:09:23][C][uart.arduino_esp32:109]: RX Pin: GPIO17
[14:09:23][C][uart.arduino_esp32:111]: RX Buffer Size: 256
[14:09:23][C][uart.arduino_esp32:113]: Baud Rate: 9600 baud
[14:09:23][C][uart.arduino_esp32:114]: Data Bits: 8
[14:09:23][C][uart.arduino_esp32:115]: Parity: NONE
[14:09:23][C][uart.arduino_esp32:116]: Stop bits: 1
[14:09:23][C][switch.gpio:050]: GPIO Switch ‘mix relay’
[14:09:23][C][switch.gpio:050]: Inverted: YES
[14:09:23][C][switch.gpio:051]: Pin: GPIO26
[14:09:23][C][switch.gpio:073]: Restore Mode: Restore (Defaults to OFF)
[14:09:23][C][switch.gpio:050]: GPIO Switch ‘irrigation relay’
[14:09:23][C][switch.gpio:050]: Inverted: YES
[14:09:23][C][switch.gpio:051]: Pin: GPIO27
[14:09:23][C][switch.gpio:073]: Restore Mode: Restore (Defaults to OFF)
[14:09:23][C][uart.switch:040]: UART Switch ‘read sensor’
[14:09:23][C][uart.switch:040]: UART Switch ‘get measurement’
[14:09:23][C][captive_portal:144]: Captive Portal:
[14:09:23][C][mdns:084]: mDNS:
[14:09:23][C][mdns:085]: Hostname: acclimatdr-310w
[14:09:23][V][mdns:086]: Services:
[14:09:23][V][mdns:088]: - _esphomelib, _tcp, 6053
[14:09:23][V][mdns:090]: TXT: version = 2022.2.6
[14:09:23][V][mdns:090]: TXT: mac = 94b97e7b94d0
[14:09:23][V][mdns:090]: TXT: platform = ESP32
[14:09:23][V][mdns:090]: TXT: board = esp-wrover-kit
[14:09:23][C][ota:085]: Over-The-Air Updates:
[14:09:23][C][ota:086]: Address: acclimatdr-310w.local:3232
[14:09:23][C][api:138]: API Server:
[14:09:23][C][api:139]: Address: acclimatdr-310w.local:6053
[14:09:23][C][api:143]: Using noise encryption: NO
[14:09:29][D][switch:013]: ‘read sensor’ Turning ON.
[14:09:29][D][switch:037]: ‘read sensor’: Sending state ON
[14:09:29][D][uart.switch:020]: ‘read sensor’: Sending data…
[14:09:29][D][switch:037]: ‘read sensor’: Sending state OFF
[14:09:30][V][text_sensor:016]: ‘tdr_wc_ec_uart’: Received new state \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
[14:09:30][D][text_sensor:067]: ‘tdr_wc_ec_uart’: Sending state ‘\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff’
[14:09:30][V][text_sensor:016]: ‘tdr_wc_ec_uart’: Received new state \xff\xff1
[14:09:30][D][text_sensor:067]: ‘tdr_wc_ec_uart’: Sending state ‘\xff\xff1’
[14:09:39][D][switch:013]: ‘get measurement’ Turning ON.
[14:09:39][D][switch:037]: ‘get measurement’: Sending state ON
[14:09:39][D][uart.switch:020]: ‘get measurement’: Sending data…
[14:09:39][D][switch:037]: ‘get measurement’: Sending state OFF
[14:09:39][V][text_sensor:016]: ‘tdr_wc_ec_uart’: Received new state \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff1+39.4+26.9+24.4+203+734
[14:09:39][D][text_sensor:067]: ‘tdr_wc_ec_uart’: Sending state ‘\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff1+39.4+26.9+24.4+203+734’

I have an Sdi12 Sk16 from Dr Lui And is this the code i would put in to make my teros 12 get readings? I am really new to all of this and just need some help.

hi man, im just a beginer at all this stuff aswell but if i can help i will.

are you using the teros sensor and the sdi-12 adapter directly with a rp4?.

i have the device hooked into the sdi12 usb adapter and thats plugged into my rpi400. I just need help converting it to ec, moisture %, and temp and then that data somehow being read in HA.

have you loaded any code yet?, have you checked the sensor address or assigned one yet?.

i have assigned and checked the address. I can get it to work, i just would like it to read the EC, Water Moisture Content % and Temperature.

No problem @sar1, excuse me for replying a bit late, busy times are behind me :wink:

For your text sensor to show on home assistant, i think you have to add a name to it, I’m also not sure if ‘ID’ works, since that one is not listed (anymore) in the docs:

For your odd data, I think one of your pins is interfering with your UART pins, maybe you could try commenting out your relay switches in de code first and see what happens. Other than that, I think you might need to solder these off the ESP and test with a breadboard if other pins have more succes

hi @Potterstraat, no excuse needed im just glad you replied.

i did notice i had not named my text sensor, i will try it today to see if i can get it to show in home assistant.

as for the odd data i have already tried deleting the code for the relay pins and it made no difference, i also tried deleting the relay code and unsoldering the relay wires from the esp32 and unplugging the powerpacks for the relay board and the 24v valves and no change?.

i also checked with a magnifying glass for stray wire strands or a solder ball causing an issue but couldnt see anything?.

and of course i have checked the wiring just to make sure i have not made a silly mistake but it all looks correct.

i agree it does look like maybe some sort of interference in the data but not sure why?.

Taking a closer look at the Wroom pinout, I think your setup and pin use is correct.

Started googling on your output, just finding out that I know little about UART and ESPs:

I did not read through this, but think the answer is close

i will have a read and a mess about and report back any findings.

i just strange that it worked flawlessly on the bench and now its taking a shit once installed in the box???.

Very recognizable, and it is indeed strange that it worked before. Now the UART log probably shows a lot of jibberish because it outputs about everything going on in that ESP I guess?

I have one UART device in my Home Assistant setup (an ESP connected to an arduino board), and I also stole an include from somewhere to enable UART coms on the ESP:

  name: skarsta
  includes:
    - uart_read_line_sensor.h

just to point out that the data returned in the logs is never the same ie -

sometimes you get some jibberish and the sensor data at the end of the jibberish,

sometimes you just get jibberish and no sensor data,

sometimes you get jibberish and just some of the sensor data,

sometimes you get no jibberish and no sensor data returned.

also the jibberish itself changes sometimes there is a few lines of it, sometimes only a few characters.

Reading that much inconsistency almost makes me think something bigger is going on, checked your power supply already I suppose? Try hooking up the Liudr board on a seperate power supply (USB) maybe?

I purchased the sdi12 sk16 adapter and i’m using a teros12 meter attached to it. How will i get this to work with home assistant and be able to read vwc, ec and temp. right now im using the python script that came dr lui recommends but its not giving me the data in those 3 outputs. just the raw data.