How do you acquire sensor data that's not numeric or text

I’m trying to acquire the data from the “octoprint current status” entity. It shows various text values on the dashboard card, like “Operational”, etc but the data type shows it’s float! What’s Up! I can only assume it’s not float but rather a pointer to a char[ ] array? Can anybody help? is this a case for a template of some sort? I’m new at this so I’m unsure. I’m also having trouble getting time values like “octoprint estimated time” to display. I’ve tried reading values into global variables with no success. Anybody in the know?

You may be over-thinking it. :wink: Does this help?

Thanks for the response. Looks promising…I’ll give it a go.

so… this must NOT be how state.state is used. Any guidance?

          it.printf(20, 95, id(font_roboto_medium22), my_black, "Octoprint State: %s", id(octostate).state.state);
                                                                                                     ^~~~~
*** [/data/esphome-web-67c524/.pioenvs/esphome-web-67c524/src/main.cpp.o] Error 1 ```

Hard tell. No Yaml, no issue.

Maybe better?

  - platform: homeassistant
    entity_id: sensor.octoprint_target_tool0_temp
    id: octottemp
  - platform: homeassistant
    entity_id: sensor.octoprint_estimated_finish_time
    id: octofinish  
  - platform: homeassistant
    entity_id: sensor.octoprint_job_percentage
    id: octopercent
  - platform: homeassistant
    entity_id: sensor.octoprint_actual_bed_temp
    id: octobtemp 
  - platform: homeassistant
    entity_id: sensor.octoprint_current_state
    id: octostate
#   
#  setup for MQTT connected CZ-300 on Unit 1    
  - platform: homeassistant
    entity_id: sensor.octoprint_tool_0_temperature
    id: mqttoctottemp
  - platform: homeassistant
    entity_id: sensor.octoprint_approximate_completion_time
    id: mqttoctofinish  
  - platform: homeassistant
    entity_id: sensor.octoprint_jprint_progress
    id: mqttoctopercent
  - platform: homeassistant
    entity_id: sensor.octoprint_bed_temperature
    id: mqttoctobtemp 
display:
  - platform: ili9xxx
    id: m5stack_display
    model: M5Stack
    cs_pin: 14
    dc_pin: 27
    reset_pin: 33
    rotation: 0
    lambda: |-   
      if (id(show_page) == 0)
      { 
         it.fill(my_white);
         it.print(it.get_width() / 2, 11, id(font_roboto_medium22), my_blue, TextAlign::CENTER, "CZ-300 Unit 1");
         if (id(octoprinting).state) {
            it.print(20, 63, id(font_roboto_medium22), my_black, "Printing state: ON");
         } else {
            it.print(20, 63, id(font_roboto_medium22), my_black, "Printing state: OFF");
         }
         it.printf(20, 95, id(font_roboto_medium22), my_black, "PrinterStatus: %s", id(octostate).state.state);
         it.printf(20, 95, id(font_roboto_medium22), my_black, "Tool Temperature: %.1f°F", id(octottemp).state);
         it.printf(20, 125, id(font_roboto_medium22), my_black, "Bed Temperature: %.1f°F", id(octobtemp).state);
         it.printf(20, 155, id(font_roboto_medium22), my_black, "Job Percent %.1f%%", id(octopercent).state);
      } else  {      
         it.fill(my_white);  
         it.print(it.get_width() / 2, 11, id(font_roboto_medium22), my_blue, TextAlign::CENTER, "CZ-300 Unit 2");
         if (id(mqttoctoconnected).state) {
            it.print(20, 33, id(font_roboto_medium22), my_black, "Printer Connected");
         } else {
            it.print(20, 33, id(font_roboto_medium22), my_black, "Printer Offline");
         }         
         if (id(mqttoctoprinting).state) {
            it.print(20, 63, id(font_roboto_medium22), my_black, "Printing state: ON");
        } else {
            it.print(20, 63, id(font_roboto_medium22), my_black, "Printing state: OFF");
        }
         it.printf(20, 95, id(font_roboto_medium22), my_black, "Tool Temperature: %.1f°F", id(mqttoctottemp).state);
         it.printf(20, 125, id(font_roboto_medium22), my_black, "Bed Temperature: %.1f°F", id(mqttoctobtemp).state);
         it.printf(20, 155, id(font_roboto_medium22), my_black, "Job Percent %.1f%%", id(mqttoctopercent).state);
      }
# Button to toggle the display backlight
binary_sensor:
  - platform: gpio
    id: M5_BtnB
    pin:
      number: 38
      inverted: true
    on_click:
      then:
        - switch.toggle: backlight
  - platform: gpio
    id: M5_BtnC
    pin:
      number: 39 
      inverted: true
    on_click:
      then:
      - lambda: |-
         if(id(show_page) == 1 )
           {id(show_page = 0);
         }else { 
          (id(show_page) = 1);
         }
    

  - platform: homeassistant
    entity_id: binary_sensor.octoprint_printing
    id: octoprinting
  - platform: homeassistant
    entity_id: binary_sensor.octoprint_printing_2
    id: mqttoctoprinting

  - platform: homeassistant
    entity_id: binary_sensor.octoprint_connected
    id: mqttoctoconnected

# GPIO pin of the display backlight
switch:
  - platform: gpio
    pin: 32
    name: "Backlight"
    id: backlight
    restore_mode: ALWAYS_ON ```

Please post it properly. Please read this How to help us help you - or How to ask a good question

Why .state.state? Isn’t what you want to display the state of the entity, i.e. .state?

Hi, Chris B Thanks for the reply. The state of the entity is not a number or string…it is in a format that I don’t understand. According to the “State Objects” documentation supplied by “Stiltjack”, state.state is defined as “String representation of the current state of the entity”. That’s what I’m interested in, but I’m not sure how or if it can be used in this context. I’m new at this and there’s lots I have to learn.
Again, thanks

Really difficult if you don’t post your yaml as yaml and ignore requests to fix it.

However, what is the state of sensor.octoprint_current_state in home assistant?

I thought I was supposed to surround the code with a backward quotes when I posted it. That I have done. I have no issue if you’d like to, and have the ability to delete this post if it doesn’t follow the rules. I can do more reading and provide a better, more documented, question at a later date. If I could delete the post I would. To answer your question though, the sensor.output_current_state can be “unknown”, “printing” , operational. That’s what I seen.

Three backticks ```. Better now thanks.

The docs pointed to by @Stiltjack refer to HA not Esphome.

Try id(octostate).state.c_str())

That doesn’t work. Error reports the value is “float”.

We don’t have your complete yaml (sorry not meaning to get down again on your posting )

My point is though that I can’t tell whether you are importing the HA sensors as sensor or text_sensor. They should be text_sensor

See Home Assistant Sensor — ESPHome

This component is only for numeral states. If you want to import arbitrary text states from Home Assistant, use the Home Assistant Text Sensor.

Also I am confused by your reference to mqtt in your yaml. The home assistant sensors in esphome only work over the api.

I’m using an M5Stack core to display data from two 3D printers. One unit is attached via Octoprint Add-on and the other is attached via MQTT integration. That’s the reference to mqtt. Everything is working dandy except the sensor.octoprint_current_state. The sensor in question is imported from HA as sensor. Some entities are imported as text, some binary. I think I tried importing as text and got errors…but I’ll give it another shot. In the current code I gave up and removed the code meant to display. I may give up entirely on Octoprint as I understand it won’t support two printers, but that’s another issue. Thanks again, I’ll keep at it