ESPHome: Text Sensor empty, how to debug? (solved)

Hi! This is my first project w/ ESPHome // Home Assistant, sorry if I’m missing something obvious.

I’m trying to pipe a todo list from the Todoist REST API (called by Home Assistant) to a WaveShare E-Ink display, managed by an ESP32.

I can confirm that HomeAssistant has successfully acquired the TODO list:

{{ states.sensor.item0.state }}

displays “Hang projector screen” in the Home Assistant Template editor.

I can also confirm that I can display text to the E-Ink display, if I use static text.

However, when I create a text_sensor in ESPHome to read from Home Assistant, my display lambda sees only an empty string. I wish there were some way to interactively debug this, but some log statements is the best I can find.

ESPHome Config:

text_sensor:
  - platform: homeassistant
    name: "todo0"
    entity_id: sensor.item0
    id: todo0
    on_value:
      then:
        - lambda: |-
            ESP_LOGD("sensor", "value is %s", x.c_str());
  - platform: homeassistant
    name: "To-do List 1"
    entity_id: sensor.item1
    id: todo1

display:
  - platform: waveshare_epaper
    cs_pin: 15
    dc_pin: 27
    busy_pin: 25
    reset_pin: 26
    model: 7.50inV2
    reset_duration: 2ms
    update_interval: 30sec
    lambda: |-
      ESP_LOGI("todolist", "%s", id(todo0).state.c_str());
      it.printf(0, 0, id(font1), "%s", id(todo0).state.c_str());

The display is empty, and the log messages are also empty.

I’m running out of ideas for debugging this. Many thanks!

Post the yaml for the HA sensor you are trying to retrieve.

Or if not defined in yaml a screen shot of it in Developer Tools | States.

sensor:
  - platform: command_line
    name: todo_list
    scan_interval: 30
    command: >
      echo "{\"tasks\":" $(
      curl -X GET https://api.todoist.com/rest/v2/tasks -H 'Authorization: Bearer REDACTED'
      ) "}"
    value_template: > 
      {{ value_json.tasks | length }}
    json_attributes:
      - tasks
    unique_id: 'todoist_tasks'
  - platform: template
    sensors:
      item0: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 0 %} {{states.sensor.todo_list_2.attributes.tasks[0].content }} {% else %} {% endif %}"
      item1: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 1 %} {{states.sensor.todo_list_2.attributes.tasks[1].content }} {% else %} {% endif %}"
      item2: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 2 %} {{states.sensor.todo_list_2.attributes.tasks[2].content }} {% else %} {% endif %}"
      item3: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 3 %} {{states.sensor.todo_list_2.attributes.tasks[3].content }} {% else %} {% endif %}"
      item4: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 4 %} {{states.sensor.todo_list_2.attributes.tasks[4].content }} {% else %} {% endif %}"
      item5: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 5 %} {{states.sensor.todo_list_2.attributes.tasks[5].content }} {% else %} {% endif %}"
      item6: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 6 %} {{states.sensor.todo_list_2.attributes.tasks[6].content }} {% else %} {% endif %}"
      item7: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 7 %} {{states.sensor.todo_list_2.attributes.tasks[7].content }} {% else %} {% endif %}"
      item8:
        value_template: "{% if states.sensor.todo_list_2.state | int > 8 %} {{states.sensor.todo_list_2.attributes.tasks[8].content }} {% else %} {% endif %}"
      item9: 
        value_template: "{% if states.sensor.todo_list_2.state | int > 9 %} {{states.sensor.todo_list_2.attributes.tasks[9].content }} {% else %} {% endif %}"

IDK why, but it’s working now … ? Maybe because I added it as an integration to home assistant?

I’ve written up a summary of the journey here: Building an e-Ink ToDo list | praccu’s blog