TTGO HiGrow with ESPHome

Alright, apologies for my earlier post, I jumped the gun too soon. But the below config appears to work for the light sensor. It seems it takes a while for the BH1750 to show up on the i2c bus and ESPHome boot timing will miss it unless you use the setup_priority function on a few components.

esphome:
  name: garden_bed_01
  platform: ESP32
  board: lolin_d32
  on_shutdown:
    then:
      - switch.turn_off: spower
wifi:
  ssid: "SSID"
  password: "password"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Garden Bed 01 Fallback Hotspot"
    password: "password"

# Enable logging
logger:

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

ota:
  password: "password"

deep_sleep:
  run_duration: 60s
  sleep_duration: 60m

switch:
  - platform: gpio
    pin: GPIO4
    name: "Sensor Power"
    id: spower
    restore_mode: ALWAYS_ON
    internal: true
    setup_priority: 1000

binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO35
      mode: INPUT_PULLUP
      inverted: True
    name: "Wake Button"

i2c:
  sda: 25
  scl: 26
  scan: True
  id: bus_a
  setup_priority: -200

sensor:
  - platform: dht
    model: dht11
    pin:
      number: 16
      mode: input
    temperature:
      name: "HiGrow1 Temperature"
    humidity:
      name: "HiGrow1 Humidity"
    update_interval: 60s
    setup_priority: -100
    
  - platform: adc
    pin: GPIO32
    name: "HiGrow1 Soil"
    update_interval: 60s
    attenuation: 11db
    #unit_of_measurement: '%'
    #filters:
    #  - calibrate_linear:
    #      # Map 0.0 (from sensor) to 0.0 (true value)
    #      - 1.1 -> 0.0
    #      - 0.0 -> 100.0
    
  - platform: adc
    pin: 33
    name: "HiGrow1 Battery"
    attenuation: 6db
    unit_of_measurement: 'V'
    update_interval: 60s
    filters:
      - calibrate_linear:
          # Map 0.0 (from sensor) to 0.0 (true value)
          - 0.0 -> 0.0
          - 2.06 -> 1.89
      - lambda: return x * 2.0;
        
  - platform: adc
    pin: GPIO34
    name: "HiGrow1 Salt"
    update_interval: 60s
    unit_of_measurement: '%'
    accuracy_decimals: 4
    filters:
      - sliding_window_moving_average:
          window_size: 15
          send_every: 15
      - calibrate_linear:
          # Map 0.0 (from sensor) to 0.0 (true value)
          - 0.0 -> 0.0
          - 1.1 -> 100.0
    
  - platform: bh1750
    i2c_id: bus_a
    name: "BH1750 Illuminance"
    address: 0x23
    update_interval: 60s
    setup_priority: -300
2 Likes

What kind of battery life do you get with this? I have a similar one that gets terrible battery life.

I’m using a 1000mAh lipo on these. While the config posted (60s on, 1h off) wouldn’t last much more that a day or so, I am currently doing some power testing on a 60s on, 4hr off config and it looks like I’m getting about 1-2 weeks of battery life.

I’m currently building a little solar charging setup to attach to the sensor so that it tops off the sensor battery during the day so that it can run it continuously.

1 Like

I’m looking to do an improved version of this board, i2c everything where possible and support better (100% RH) and additional external sensors (ds18b20 or another sht30/31/35) and maybe swap lux sensor for LDR, and inspired by the feather S2 im going to have the power supply to sensors controlled to off by using a second dedicated sensor LDO with enable pin tied to gpio.

My needs also tempt me to add a low current relay with power sense for DC up to ²⁶volt using the INA219 to control a valve per device.

Will keep you in the loop as am on nodered right now but wish to get HA running comfortably

1 Like

how would it be with more deep sleep sets??
Is this possible?
Like set deep_sleep1 4h if soil 70%
and deep_sleep2 2h if soil 40% and so on…
but this should be automated from ha or node red I guess so the deep_sleep trigger comes from outside esp?

Dont know how to code it, Im relative new in this area…

2 Likes

I imagine that you could use a combination of global variables and lambdas to make updates to the sleep interval during each wake period. That’s my unofficial guess just by looking at the docs. You might try hitting up the Discord channel.

On the one i have, the sensors are directly attached to power and not controlled by the ESP. this is the main cause of power loss. No matter how much you put it to sleep, the battery drops like a rock. i would suspect this might be suffering from a similar issue.

On the ESP32, you have the option of waking up on any RTC pin. However, there’s one scenario that you need to tell ESPHome how to handle: What if the wakeup pin is already in the state with which it would wake up when the deep sleep should start? There are three ways of handling this using the wakeup_pin_mode option:

  • IGNORE (Default): Ignore the fact that we will immediately exit the deep sleep mode because the wakeup pin is already active.
  • KEEP_AWAKE : Keep the ESP32 awake while the wakeup pin is still active. Or in other words: defer the activation of the deep sleep until the wakeup pin is no longer active.
  • INVERT_WAKEUP : When deep sleep was set up to wake up on a HIGH signal, but the wakeup pin is already HIGH, then re-configure deep sleep to wake up on a LOW signal and vice versa. Useful in situations when you want to use observe the state changes of a pin using deep sleep and the ON/OFF values last longer.

…On the ESP32, you additionally have the option to wake up on any RTC pin ( GPIO0 , GPIO2 , GPIO4 , GPIO12 , GPIO13 , GPIO14 , GPIO15 , GPIO25 , GPIO26 , GPIO27 , GPIO32 , GPIO39 ).

Don’t know if it helps :wink:

(PS: I can’t test anything for now, my T-Higrow are still in China @ packaging…)

1 Like

I think this might be the earlier version? The version of the board that I have has an enable pin on one of the 3.3v regulators that feeds the sensors. It’s connected to GPIO4, referred in the config above as Sensor Power/spower. I make sure to turn that off before shutting down.

Go to:

LILYGO TTGO HIGrow

There is a fully functional program and a tutorial for setting this module up and integrate into Home-Assistant.

Also a 3D print is available for a case to the module

3 Likes

Thanks for the info :wink:
I don’t know about the others in this thread, but my goal is to use the higrow with esphome and not have to manage a clean code by ardruino ide…

would be nice if it work to convert the orginal bin of the seller to a esphome yaml, so we could see what are the breaking differences :smiley:

I did look into the ESPHome, but that was too Chinese to me.

I and BeardedTinker is working on to get the mqtt autodiscover to work with the module, so all the configuration yaml code will disappear.

This will be the version 2.0.
Version 2.0 of the INO sketch will be a one only, meaning, that no matter how many modules you have, you only need one sketch.

2 Likes

how this going? i want to do the exact same thing control a dc valve and monitor everything else. Did you prototype our own PCB?

LilyGo released on Twitter image yesterday (and video) of small pump attached to PCB to pump water based on sensor data.

saw that, but the newest higrow gives me poor data compared to the 8266 version. its why i was curious if @tyeth made any headway

Hi,
Anyone has experience with the bme280 version? How to set the yaml file?
Second question: Do i need to include the configuration.h file?

Regards

2 Likes

For anyone reading this trying to get this to integrate with HA, I have this specific YAML working in Oct 2022 with a few small adjustments. I had to change the ‘60m’ notation to ‘360s’ and comment out the ‘INPUT_PULLUP’ line, and once that was done, the device flashes & is integrating into HA without any issue

sounds great.
can you share your configuration? I think that people would like to see it

Here’s my yaml (ca. 1 year old), works fine…

substitutions:
  
  devicename: "pflanzensensor_1"
  upper_devicename: Pflanzensensor 1
  run_duration: 6s      # set how long to stay awake - NOT less then 10sec
  sleep_duration: 60min    # set how long to sleep in minutes
  update_interval: 5s
  fixed_ip: 192.168.1.25
  gateway_ip: 192.168.1.1
  subnet_mask: 255.255.255.0
  
###############################################################################################
  
esphome:
  name: "${devicename}"
  platform: ESP32
  board: esp32dev
  
wifi:
  ssid: !secret Wlan-ssid
  password: !secret Wlan-pw
  
  manual_ip:
    static_ip: ${fixed_ip}
    gateway: ${gateway_ip}
    subnet: ${subnet_mask}
  
  fast_connect: enable
  
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${devicename}"
    password: !secret HS-pw 
  
captive_portal:
  
# Enable logging
logger:
  
# Enable Home Assistant API
  
#api:
#  password: !secret API-pw
  
ota:
  password: !secret OTA-pw
  
# Enable Home Assistant via MQTT
mqtt:
  broker: !secret MQTT-bkr
  username: !secret MQTT-usr
  password: !secret MQTT-pw
  discovery: true
  discovery_retain: true
  on_message:
  
# Update Mode from MQTT (a switch in HA to prevent deepsleep)
  
    - topic: esphome/update/state/set
      payload: "on"
      qos: 0
      then:
        - switch.turn_on: ${devicename}_update_mode
        
    - topic: esphome/update/state/set
      payload: "off"
      qos: 0
      then:
        - switch.turn_off: ${devicename}_update_mode
  
# Deep Sleep
  
deep_sleep:
  id: deep_sleep_control
  run_duration: ${run_duration}
  sleep_duration: ${sleep_duration}
  
  
##time:
##  - platform: homeassistant
##    id: esptime
  
i2c:
  - id: bus_a
    sda: GPIO25
    scl: GPIO26
    scan: true
    setup_priority: -200
  - id: bus_b
    sda: GPIO21
    scl: GPIO22
    scan: true
    setup_priority: -200
  
switch:
  
# Update Mode
  
  - platform: template
    name: "update mode ${upper_devicename}"
    id: "${devicename}_update_mode"
    icon: "mdi:alarm-light"
    optimistic: true
#    internal: true
    turn_on_action:
      - deep_sleep.prevent: deep_sleep_control
    turn_off_action:
            if:
              condition:
                and:
                  - switch.is_off: ${devicename}_pumpe
                  - mqtt.connected:
              then:
                - delay: ${run_duration}
                - deep_sleep.enter: deep_sleep_control
  
# Watering pump

  - platform: template
    name: "Pumpe ${upper_devicename}"
    id: "${devicename}_pumpe"
    icon: "mdi:water-pump"
    optimistic: true
    turn_on_action:
      - deep_sleep.prevent: deep_sleep_control
    turn_off_action:
            if:
              condition:
                and:
                  - switch.is_off: ${devicename}_update_mode
                  - mqtt.connected:
              then:
                - delay: ${run_duration}
                - deep_sleep.enter: deep_sleep_control
  
# Power Switch
  
  - platform: gpio
    name: "${upper_devicename} Sensor Power"
    pin: 4
    id: spower
    restore_mode: ALWAYS_ON
    internal: true
    setup_priority: 1000
  
# Wake Button
  
binary_sensor:
  - platform: gpio
    name: "${upper_devicename} Wake Button"
    pin: 35
    internal: true
    setup_priority: 1000
  
sensor:

# Wifi Signal

  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval:  ${update_interval}
  
# Temperature and humidity
  
# BME280 Sensor
  
#  - platform: bme280
#    i2c_id: bus_a
#    temperature:
#      name: "${upper_devicename} Temperatur"
#      oversampling: 16x
#      unit_of_measurement: "°C"
#      icon: "mdi:thermometer"
#      device_class: "temperature"
#      state_class: "measurement"
#      accuracy_decimals: 1
#    pressure:
#      name: "${upper_devicename} Luftdruck"
#      unit_of_measurement: "mbar"
#      icon: "mdi:gauge"
#      device_class: "pressure"
#      state_class: "measurement"  
#    humidity:
#      name: "${upper_devicename} Feuchtigkeit"
#      unit_of_measurement: "%"
#      icon: "mdi:cloud-percent"
#      device_class: "humidity"
#      state_class: "measurement"  
#    address: 0x77
#    setup_priority: -300
#    update_interval: ${update_interval}
  
# DHT Sensor
  
  - platform: dht
    pin: 16
    model: dht11
    temperature:
      name: "${upper_devicename} Temperatur"
      unit_of_measurement: "°C"
      icon: "mdi:thermometer"
      device_class: "temperature"
      state_class: "measurement"
      accuracy_decimals: 1            
    humidity:
      name: "${upper_devicename} Feuchtigkeit"
      unit_of_measurement: "%"
      icon: "mdi:cloud-percent"
      device_class: "humidity"
      state_class: "measurement"
    setup_priority: -100
    update_interval: ${update_interval}
  
# Soil humidity %
  
  - platform: adc
    pin: 32
    name: "${upper_devicename} Bodenfeuchte"
    id: "${devicename}_bodenfeuchte"
    icon: "mdi:watering-can"
    attenuation: 11db
#    unit_of_measurement: 'V'       # uncomment for raw data
    unit_of_measurement: '%'        # comment for raw data
    filters:                        # comment for raw data
    - calibrate_linear:             # comment for raw data
      # Map 0.0 (from sensor) to 0.0 (true value)
      - 2.71 -> 0.0                 # comment for raw data
      - 1.44 -> 100.0               # comment for raw data
    update_interval: ${update_interval}
  
# Fertilizer sensor
  
  - platform: adc
    pin: 34
    name: "${upper_devicename} Salz"
    id: "${devicename}_salz"
    icon: "mdi:flower"
    unit_of_measurement: '%'
    accuracy_decimals: 4
    filters:
    - calibrate_linear:
      # Map 0.0 (from sensor) to 0.0 (true value)
      - 0.0 -> 0.0
      - 1.1 -> 100.0    
#    - sliding_window_moving_average:
#        window_size: 15
#        send_every: 15 
    update_interval: ${update_interval}
  
# Lux sensor
  
  - platform: bh1750
    i2c_id: bus_a
    name: "${upper_devicename} Helligkeit"
    id: "${devicename}_lux"
    address: 0x23
    unit_of_measurement: "lx"
    icon: "mdi:white-balance-sunny"
    device_class: "illuminance"
    state_class: "measurement"
    setup_priority: -300
    update_interval: ${update_interval}
  
# Batterie
  
  - platform: adc
    pin: 33
    name: "${upper_devicename} Batterie"
    id: "${devicename}_voltage"
    attenuation: 11db
    unit_of_measurement: "V"
    icon: "mdi:battery-high"
    device_class: "voltage"
    state_class: "measurement"
    accuracy_decimals: 3
    filters:
    - multiply: 2
    - calibrate_linear:
      # Map 0.0 (from sensor) to 0.0 (true value)
      - 0.0 -> 0.0
      - 4.0 -> 4.0
#    - sliding_window_moving_average:
#        window_size: 10
#        send_every: 10
    update_interval: ${update_interval}
  
# Battery %
  - platform: adc
    pin: 33
    name: "${upper_devicename} Batterie %"
    id: "${devicename}_percent"
    attenuation: 11db
    unit_of_measurement: '%'
    filters:
    - multiply: 2
    - calibrate_linear:
      # Map 0.0 (from sensor) to 0.0 (true value)
      - 3.18 -> 0.0
      - 4.20 -> 100.0
#      - lambda: |-
#          return ((id(${devicename}_voltage).state - 2.76) / 0.379 * 100.00); 
    # (current - minimum) / difference between max & min * 100
    update_interval: ${update_interval}
  
# Soil Moisture Pump Control (a climate bang bang to control the pump)
  
climate:
  - platform: bang_bang
    visual:
      min_temperature: 0
      max_temperature: 100
      temperature_step: 1
      
    name: ${upper_devicename} Regler
    sensor: ${devicename}_bodenfeuchte
    default_target_temperature_low: 20
    default_target_temperature_high: 70
  
    heat_action:
      - switch.turn_on: ${devicename}_pumpe
      
    idle_action:
      - switch.turn_off: ${devicename}_pumpe
  
3 Likes

this is better than the definition that I have, and I also still need to integrate my pump. Thanks for sharing, I will integrate some of your deep sleep stuff into mine today.