I’ve been at this for awhile and I just can’t figure it out. I have a sensor in Home Assistant called sensor.keg_quarter_percent_remaining. The sensor is a float and shows a percentage. I am trying to display this value on an OLED on an ESPHome device. Whenever I try and display any sensors, I am just seeing “NAN” on the display. Not sure why this is:
Ideally, I would like to show data from sensorA by default but if I enable a toggle (e.g. input_boolean.quaterkeg ) then it shows data from sensorB instead. At this point though, I can’t even get a single sensor to display properly so I’m trying to figure that out first.
Edit: Here are a look at the sensors I am using which are templates from another ESPHome device:
Here is the template where the sensor gets populated by:
[13:31:05][D][homeassistant.text_sensor:017]: 'sensor.atmospheric_pressure_msl': Got state '1026.7'
Note that the value will populate on startup, but it then won’t update until it changes in HA, so if it doesn’t change it won’t get logged. Force the value to change somehow and make sure the ESPHome log updates.
Thanks for the help here. Hrm, yeah, I just changed the value twice and the log didn’t move. It is using the same secrets as the other ESPHome devices I have and connects to the WiFi successfully. Not sure what the problem could be why its not reading the value from Home Assistant… Is there a way to verify connectivity otherwise?
Just changed sensor to text_sensor and rather than “NAN” on the OLED I now get “0.00000000”. I still don’t see anything changing in the logs though. Not sure if this is helpful or not
Out of ideas… It’s probably something obvious we are missing. Maybe change the ESPHome sensor name so it doesn’t match the HA one? Clutching at straws here.
@Troon
I tried changing %f to %s in the printf statement while the sensor was still a text_sensor and it led to the OLED showing what looks like spaces. They are spaces filled in with color, but no value. I changed the text_sensor back to sensor while leaving the %s in place, and I am getting random characters for the value that are constantly changing, very odd.
@thusassistint
I also updated my template to what you said (and reverted to original code mentioned in the post) and I am still getting DATA: NAN unfortunately.
EDIT and side note - I took a different sensor, a living room temperature reading from an Ecobee sensor, and put it in place of the sensor here to see if anything populated on the OLED. I am still getting NAN. It seems like a connection issue between the ESPHome and Home Assistant, but my other devices with the same secrets and similar configs in ESPHome work fine, it is on the same network, and the API connection per the logs is successful. Not sure what is going on. Changed the logging to VERBOSE as well but hasn’t been helpful thus far.
So I changed the sensor category to text_sensor and we are getting data on the OLED! However, the data is incorrect / not what is being shown in Home Assistant…
I adjusted the value and the change happened in Home Assistant but it remained the same on the OLED. Im not sure where that 1.9% is coming from. Does this mean the sensor is being seen as a text sensor? Im in general very confused. The logs remain the same, no activity on value changes. I also added c.str() to the logger line to see if that helped with logging updates but it did not.
Side question - I would like the data to be updated on the OLED when the sensor data changes. I assume this automatically happens periodically?
It has been figured out! When I initially set this device up, I added it under the whole ‘device found’ area in Integrations / ESPHome. For whatever reason, it was removed though, and I had to add it again. The values are now showing properly (as a float or %f). Thanks so much for all of the help here, it is really appreciated. I was pulling my hair out on this.
I never thought that I have to activate the es-home device in Integrations, to receive data (as I was the whole time in HA) It took me forever to find the problem, until I read your solution.