8000 Sonoff TH Origin 16A (THR316D) + Sonoff Temp and Humidity Sensor THS01 (SI7021) Invalid Readings · Issue #4189 · esphome/issues · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Sonoff TH Origin 16A (THR316D) + Sonoff Temp and Humidity Sensor THS01 (SI7021) Invalid Readings  #4189
Open
@paulguru

Description

@paulguru

The problem

Hi ESPHome team,

I'm struggling to get the Sonoff Temp and Humidity Sensor THS01 (SI7021) working on the Sonoff TH Origin 16A (THR316D).

I used the yaml configuration of the Sonoff THR320D (https://www.esphome-devices.com/devices/Sonoff-THR320D) as the base for the configuration of the THR316D with some changes (since the THR316D uses a slightly different GPIO's).

I ruled out hardware issues as the sensor works when using Tasmota32.bin firmware.

FYI - I tried compiling using various board and framework options i.e. nodemcu-32s/esp32dev and esp-idf/arduino but this does not seem to have an effect.

Which version of ESPHome has the issue?

2023.2.1

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

Home Assistant 2023.2.5

What platform are you using?

ESP32-IDF

Board

nodemcu-32s

Component causing the issue

DHT

Example YAML snippet

substitutions:
  device_name: sonoffth316d
  location: Garage
    
esphome:
  name: "${device_name}"
  friendly_name: Sonoff Elite TH 1
  # supply the external temp/hum sensor with 3v power by pulling this GPIO high
  on_boot:
    - priority: 90
      then:
      - switch.turn_on: TH_sensor_power


esp32:
  board: nodemcu-32s
  #board: esp32dev
  framework:
    type: esp-idf
  #  type: arduino
        
# Enable logging
logger:
  baud_rate: 0
#  level: VERBOSE
#  level: VERY_VERBOSE

# Enable Home Assistant API
api:
  encryption:
    key: "XXXXX"

ota:
  password: "XXXXX"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: XXXXX
    gateway: XXXXX
    subnet: XXXXX

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${device_name}"
    password: !secret wifi_debug

#captive_portal:
 
#### TIME ####

time:
  - platform: homeassistant
    id: homeassistant_time
    
### BUTTON ###

button:
  - platform: restart
    name: $device_name Restart
    device_class: restart
    entity_category: diagnostic

### DISPLAY ###

display:
  platform: tm1621
  id: tm1621_display
  cs_pin: GPIO17
  data_pin: GPIO5
  read_pin: GPIO23
  write_pin: GPIO18
  lambda: |-
    it.printf(0, "%.1f", id(${device_name}_temp).state);
    it.display_celsius(true);
    it.printf(1, "%.1f", id(${device_name}_humi).state);
    it.display_humidity(true);


### BINARY SENSOR ###

binary_sensor:
  # single main button that also puts device into flash mode when held on boot
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "${device_name} Button"
    on_press:
      then:
        - switch.toggle: relay_1

  - platform: status
    name: "${device_name} Status"


### SWITCH ###

switch:

# Main Relay GPIO21

  - platform: gpio
    name: ${device_name}_relay
    pin: GPIO21
    id: relay_1
    # after reboot, keep the relay off. this prevents light turning on after a power outage
    restore_mode: ALWAYS_OFF
    on_turn_on:
      light.turn_on: power_led
    on_turn_off:
      light.turn_off: power_led
    
    
  # dry contact relay switch
  - platform: gpio
    id: dryContRelay
    name: "Dry Contact Relay"
    pin:
      number: GPIO4
      inverted: true
    on_turn_on:
      light.turn_on: green_led
    on_turn_off:
      light.turn_off: green_led


  - platform: gpio
    pin:
      number: GPIO27
    #  inverted: false 
    id: TH_sensor_power
    restore_mode: ALWAYS_ON

### OUTPUT ###

# LEDs need gpio output defined
output:
  # Power LED
  - id: power_led_output
    platform: gpio
    pin: 16
    inverted: True

  # GREEN LED 
  - id: green_led_output
    platform: gpio
    pin: 13
    inverted: True
  
### LIGHT ###

light:
  # Power LED
  - platform: binary
    id: power_led
    name: "Power LED"
    output: power_led_output
    internal: true

  # Green LED
  - platform: binary
    id: green_led
    name: "Green LED"
    output: green_led_output
    internal: true

  # Blue LED (middle). Used as wifi status indicator.
  - platform: status_led
    name: "${device_name} Wifi LED"
    pin:
      number: GPIO15
      inverted: true
    id: wifi_led  
    internal: true   

### INTERVAL ###

interval:
  - interval: 60s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - light.turn_on: wifi_led
        else:
          - light.turn_off: wifi_led


### SENSOR ###

sensor:
  # "Sonoff THS01 - SI7021"
  - platform: dht
    pin: GPIO25
    model: SI7021
    temperature:
      name: "${location} Temperature"
      id: ${device_name}_temp
    humidity:
      name: "${location} Humidity"
      id: ${device_name}_humi
    update_interval: 60s

  - platform: wifi_signal
    name: $device_name Wifi RSSI
    update_interval: 60s

  - platform: uptime
    id: uptime_sensor
    internal: True
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();


#### TEXT SENSOR ####

text_sensor:
  - platform: version
    name: "ESPHome Version"
    hide_timestamp: true

  - platform: template
    name: $device_name Uptime
    id: uptime_human
    icon: mdi:clock-start

  - platform: wifi_info
    ip_address:
      name: $device_name IP
    mac_address:
      name: $device_name MAC Address

Anything in the logs that might be useful for us?

Log file snippets:
1) Sensor startup messages
2) Sensor Error messages

1) Sensor startup messages // ########################
[11:02:44][C][dht:017]: DHT:
[11:02:44][C][dht:018]:   Pin: GPIO25
[11:02:44][C][dht:024]:   Model: DHT22 (or equivalent)
[11:02:44][C][dht:027]:   Update Interval: 60.0s
[11:02:44][C][dht:029]:   Temperature 'Garage Temperature'
[11:02:44][C][dht:029]:     Device Class: 'temperature'
[11:02:44][C][dht:029]:     State Class: 'measurement'
[11:02:44][C][dht:029]:     Unit of Measurement: '°C'
[11:02:44][C][dht:029]:     Accuracy Decimals: 1
[11:02:44][C][dht:030]:   Humidity 'Garage Humidity'
[11:02:44][C][dht:030]:     Device Class: 'humidity'
[11:02:44][C][dht:030]:     State Class: 'measurement'
[11:02:44][C][dht:030]:     Unit of Measurement: '%'
[11:02:44][C][dht:030]:     Accuracy Decimals: 0

2) Sensor Error messages // ######################

[11:03:43][W][dht:169]: Requesting data from DHT failed!
[11:03:43][W][dht:060]: Invalid readings! Please check your wiring (pull-up resistor, pin number).
[11:03:43][D][sensor:127]: 'Garage Temperature': Sending state nan °C with 1 decimals of accuracy
[11:03:43][D][sensor:127]: 'Garage Humidity': Sending state nan % with 0 decimals of accuracy

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0