Sht3xd ( or other i2x sensors) api Does not provide internal access to temperature or humidity (protected)

Hello folks, my first post !
so i am trying to display the temperature of sht3xd on my esphome device. the current workaround is to let the device publish to HA server and then retrieve the temp entity from HA server toward the esphome device and display it on the OLED … but it would make much sense to expose the two sensors inside sht3xd class as the are now private declared …
here is my Yaml and the error message associated any clue ?


sensor:

  - platform: rotary_encoder

    name: "Rotary Encoder"

    id : rotary

    restore_mode : RESTORE_DEFAULT_ZERO

    publish_initial_value : true

    resolution : 2

    pin_a: 2

    pin_b: 15

    min_value: 0

    max_value: 100

  - platform: sht3xd

    id: tempSensor

    temperature:

      name: "Temperature"

    humidity:

      name: "Humidity"

    address: 0x44

    update_interval: 60s

  - platform: adc

    pin: 39      

    name: "Brightness"

    unit_of_measurement: "lux"

    update_interval: 30s

    raw: true

    attenuation: 11dB

    accuracy_decimals: 1

  - platform: homeassistant

    id: this_temp

    entity_id: sensor.bedroomsensor_temperature

    internal: true

  - platform: homeassistant

    id: this_hum

    entity_id: sensor.bedroomsensor_humidity

    internal: true

time:

  - platform: homeassistant

    id: esptime

display:

  - platform: ssd1306_i2c

    flip_y : false

    flip_x : false

    id: oled

    model: "SSD1306 128x64"

    address: 0x3C

    lambda: |-

      // Print "Mitt Smarta Hus" in top center.

      it.printf(64, 0, id(arialfont_x_small_), TextAlign::TOP_CENTER, "bedroom Sensor");

      if (id(rotary).state >= 0)

        it.printf(0, 0, id(arialfont_x_small_), TextAlign::TOP_LEFT, "%.0f" , id(rotary).state);

      // Print time in HH:MM format

      it.strftime(5, 40, id(arialfont), TextAlign::BASELINE_LEFT, "%H:%M", id(esptime).now());

      it.printf(127, 23, id(arialfont_small), TextAlign::TOP_RIGHT , "%.1f°",id(tempSensor).temperature_sensor_->state);

      //if (id(this_temp).has_state()) {

      //  it.printf(127, 23, id(arialfont_small), TextAlign::TOP_RIGHT , "%.1f°", id(this_temp).state);

      // }

      // Print outside temperature (from homeassistant sensor)

      if (id(this_hum).has_state()) {

        it.printf(127, 60, id(arialfont_small), TextAlign::BASELINE_RIGHT , "%.1f%%", id(this_hum).state);

      }

error as described :

/config/esphome/bedroomsensor.yaml: In lambda function:
/config/esphome/bedroomsensor.yaml:150:87: error: 'esphome::sensor::Sensor* esphome::sht3xd::SHT3XDComponent::temperature_sensor_' is protected within this context
       it.printf(127, 23, id(arialfont_small), TextAlign::TOP_RIGHT , "%.1f°",id(tempSensor).temperature_sensor_->state);

You placed id: tempsensor on the wrong line. Change it like this:

  - platform: sht3xd
    temperature:
      id: tempSensor
      name: "Temperature"
    humidity:
      name: "Humidity"
    address: 0x44
    update_interval: 60s

Then the next line in the display lambda will work:

it.printf(127, 23, id(arialfont_small), TextAlign::TOP_RIGHT , "%.1f°",id(tempSensor).state);
1 Like