Referencing miflora attributes internally

I have a miflora sensor setup and working via esphome and I’m wanting to reference the values captured (temperature, moisture etc) within esphome itself to output to a display which I have connected and working to the esp32 I’m using but I can’t work out how to reference the attributes within the printf command.

Any help grateful.

Maybe start with a cookbook like this one here to see how things work:
Time & Temperature on OLED Display — ESPHome

Probably over complicating things :joy:

What display are you using?

It’s an SSD1306 but I have the display working great it’s just referencing the miflora attributes I can’t work out.

Using the display component you use the formatted text where you can specify an id of the sensor you want to include but the miflora sensor only had 1 ID assigned to the sensor but 4 attributes (temperature, moisture, illuminance, conductivity).

maybe somethingn like that :point_down:

  - platform: xiaomi_hhccjcy01
    mac_address: '94:2B:FF:5C:91:61'
      name: "Xiaomi HHCCJCY01 Temperature"
      id: temp
      name: "Xiaomi HHCCJCY01 Moisture"
      id: hum
      name: "Xiaomi HHCCJCY01 Illuminance"
      name: "Xiaomi HHCCJCY01 Soil Conductivity"
      name: "Xiaomi HHCCJCY01 Battery Level"

  - platform: ...
    # ...
    lambda: |-
      it.printf(0, 0, id(my_font), "The sensor value is: %.1f", id(temp).state);
      it.printf(0, 1, id(my_font), "The sensor value is: %.1f", id(hum).state);

Thats works! Many thanks :slight_smile:

I couldn’t find anywhere in the docs that talked about being able to specify individuals ID’s unless you can point me in the right direction.

1 Like

Should be this :point_down:


Quite an important aspect of ESPHome are “IDs”. They are used to connect components from different domains. For example, you define an output component together with an ID and then later specify that same ID in the light component. IDs should always be unique within a configuration and ESPHome will warn you if you try to use the same ID twice.

Because ESPHome converts your configuration into C++ code and the IDs are in reality just C++ variable names, they must also adhere to C++’s naming conventions. C++ Variable names

  • … must start with a letter and can end with numbers.
  • … must not have a space in the name.
  • … can not have special characters except the underscore (“_“).
  • … must not be a keyword.

…but the search :mag: on is really everything else than great. First thing when searching id is CAN bus :bus: (but to be fair the second results leads to this quote :point_up:)

And I did read that but it doesn’t give the impression you can assign multiple ID’s within the same sensor.

Anyway thanks again for the help :slight_smile:

Well, I never thought about that actually. But when something can have a name I always think it also can have an id :+1: (Actually now I think it needs at least name or id :thinking:)

1 Like