HA entity shows up as nan

I’m trying to display numeric HA entities on a display connected to an esphome device. Display works, but it shows up as nan. This is a re-used ESP module and after having a huge amount of trouble getting the encryption key changed, which is a whole other topic and seems to be a recurring one, now it indicates that the HA API is indeed connecting. This seems to be the main issue people are having when this happens, but this is not the case here. Right now encryption is disabled for testing purposes. When polling the entity state, i’m guessing this should show up in the log? It does not.

Config:

esphome:
  name: lcd-5110-1
  friendly_name: LCD-5110-1

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:


ota:
  password: "[redacted]"

spi:
  clk_pin: D5
  mosi_pin: D7
  
font:
  - file: 'Arial.ttf'
    id: font1
    size: 12

sensor:
  - platform: homeassistant
    id: pv_production
    name: "PV production"
    entity_id: sensor.pv_output_pwr_lo
    internal: true
    attribute: state
    state_class: measurement
    accuracy_decimals: 3
    unit_of_measurement: "kW"

display:
  - platform: pcd8544
    reset_pin: D0
    cs_pin: D8
    dc_pin: D1
    contrast: 50
    lambda: |-
      it.printf(0, 0, id(font1), "PV: %.3fkW", id(pv_production).state);

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 172.17.32.201
    # Set this to the IP address of the router. Often ends with .1
    gateway: 172.17.32.253
    # The subnet of the network. 255.255.255.0 works for most home networks.
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lcd-5110-1 Fallback Hotspot"
    password: "[redacted]"

captive_portal:
    
    

Log output from ESP device:

INFO ESPHome 2023.8.2
INFO Reading configuration /config/esphome/lcd-5110-1.yaml...
INFO Starting log output from 172.17.32.201 using esphome API
INFO Successfully connected to 172.17.32.201
[08:16:31][I][app:102]: ESPHome version 2023.8.2 compiled on Sep  5 2023, 08:13:34
[08:16:31][C][wifi:543]: WiFi:
[08:16:31][C][wifi:379]:   Local MAC: C8:C9:A3:06:4A:D4
[08:16:31][C][wifi:380]:   SSID: [redacted]
[08:16:31][C][wifi:381]:   IP Address: 172.17.32.201
[08:16:31][C][wifi:382]:   BSSID: [redacted]
[08:16:31][C][wifi:384]:   Hostname: 'lcd-5110-1'
[08:16:31][C][wifi:386]:   Signal strength: -78 dB ▂▄▆█
[08:16:31][C][wifi:390]:   Channel: 1
[08:16:31][C][wifi:391]:   Subnet: 255.255.255.0
[08:16:31][C][wifi:392]:   Gateway: 172.17.32.253
[08:16:31][C][wifi:393]:   DNS1: 0.0.0.0
[08:16:31][C][wifi:394]:   DNS2: 0.0.0.0
[08:16:31][C][logger:301]: Logger:
[08:16:31][C][logger:302]:   Level: DEBUG
[08:16:31][C][logger:303]:   Log Baud Rate: 115200
[08:16:31][C][logger:305]:   Hardware UART: UART0
[08:16:32][C][spi:125]: SPI bus:
[08:16:32][C][spi:126]:   CLK Pin: GPIO14
[08:16:32][C][spi:128]:   MOSI Pin: GPIO13
[08:16:32][C][spi:130]:   Using HW SPI: YES
[08:16:32][C][pcd_8544:102]: PCD8544
[08:16:32][C][pcd_8544:102]:   Rotations: 0 °
[08:16:32][C][pcd_8544:102]:   Dimensions: 84px x 48px
[08:16:32][C][pcd_8544:103]:   DC Pin: GPIO5
[08:16:32][C][pcd_8544:104]:   Reset Pin: GPIO16
[08:16:32][C][pcd_8544:105]:   Update Interval: 1.0s
[08:16:32][C][captive_portal:088]: Captive Portal:
[08:16:32][C][mdns:112]: mDNS:
[08:16:32][C][mdns:113]:   Hostname: lcd-5110-1
[08:16:32][C][ota:093]: Over-The-Air Updates:
[08:16:32][C][ota:094]:   Address: 172.17.32.201:8266
[08:16:32][C][ota:097]:   Using Password.
[08:16:32][C][api:138]: API Server:
[08:16:32][C][api:139]:   Address: 172.17.32.201:6053
[08:16:32][C][api:143]:   Using noise encryption: NO
[08:16:32][C][homeassistant.sensor:030]: Homeassistant Sensor 'PV production'
[08:16:32][C][homeassistant.sensor:030]:   State Class: 'measurement'
[08:16:32][C][homeassistant.sensor:030]:   Unit of Measurement: 'kW'
[08:16:32][C][homeassistant.sensor:030]:   Accuracy Decimals: 3
[08:16:32][C][homeassistant.sensor:031]:   Entity ID: 'sensor.pv_output_pwr_lo'
[08:16:32][C][homeassistant.sensor:033]:   Attribute: 'state'
[08:16:34][D][api:102]: Accepted 172.17.32.200
[08:16:34][D][api.connection:1031]: Home Assistant 2023.8.4 (172.17.32.200): Connected successfully

Remove this from your sensor config.

https://esphome.io/components/sensor/homeassistant.html
Screenshot 2023-09-05 at 13-31-57 Home Assistant Sensor

Unless your pv_output_pwr_lo sensor actually has an attribute named state.

2 Likes

Right you are. I’m having real trouble reading the mannerisms of the documentation sometimes. When reading that i figured the entity state is indeed what i want, so i can just leave that in.
Thanks a bunch!

1 Like