Getting other sensor's state in custom sensor component

Hi, I’m trying to create a custom sensor (it’s a CO2 and other gasses sensor) in C++.
In order to work properly, I need to calculate the ppm value according to room’s temperature and humidity, and I’ve got this values from another sensor.
Is there a way to get other esphome’s sensors state in my custom sensor class?

through HA, yes

Add a sensor on your esphome device like this:

sensor:
  - platform: homeassistant
    entity_id: sensor_name_in_homeassistant
    id: cool_sensor
    unit_of_measurement: apples
    internal: true

In your lambda you can insert the sensors state like this:

display:
  - platform: lcd_pcf8574
    dimensions: 16x2
    address: 0x27
    lambda: |-
      it.printf(0, 0, "My Cool Sensor: %.0f", id(cool_sensor_id).state);