Hi All,
First off i apologise if this is in the wrong section of forum, wasn’t sure if this is a 3rd party issue or a ha dashboard issue.
Got a bit of a strange bug / error / confusion going on with an NTC Thermistor and the dashboard…
I have setup a 10k NTP Thermistor module attached to ESP8266 [NodeMCU] , Runs lovely & give a great accurate reading after a few tweaks to the default code on ESPHome & some calibrations.
I have placed a card on my HA DEV Dashboard linking to the NTC Sensor which turns on & updates the temperature every 15 seconds. This works great if i have the logs of the ESP8266 [NodeMCU] from ESPHome running on a different screen as seen in FIG1 . The moment i close the log screen down the dashboard card displays a different reading… see FIG 2 . Its as if it looses connection & guesses at a figure.
Images
FIG1 - Works with logs open
FIG2 - Bug after closing logs
any help with this would be greatly appreciated.
Here is my code for the NTC Thermistor module & ESP8266.
[ ALL IDENTIFYING INFO HAS BEEN PURGED ]
Code
####################################################################################################
####################################### Startup & Setup Code #######################################
####################################################################################################
########## MCU / Board Type ##########
esp8266:
board: esp01_1m
########## Hostnames ##########
esphome:
name: REDACTED-esp8266-dev
friendly_name: REDACTED-ESP8266-DEV
########## Enable logging ##########
logger:
########## Home Assistant API Hostname ##########
api:
encryption:
key: !secret API-REDACTED-ESP8266-DEV
########## System OTA ##########
ota:
- platform: esphome
password: !secret OTA-REDACTED-ESP8266-DEV
########## System WIFI ##########
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret wifi_domain
fast_connect: true
########## System IPV4 Address ##########
manual_ip:
static_ip: 10.9.0.151
gateway: 10.9.0.254
subnet: REDACTED
dns1: 10.9.0.254
########## Captive Portal, Fallback hotspot ##########
ap:
ssid: "FIX_ME-REDACTED-ESP8266-DEV"
password: !secret AP_password
captive_portal:
####################################################################################################
######################################### Main System Code #########################################
####################################################################################################
########## NTC Calibration Data ##########
sensor:
- platform: ntc
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: NTC Temperature
########## NTC Configuration ##########
- platform: resistance
id: resistance_sensor
sensor: source_sensor
configuration: DOWNSTREAM
resistor: 10kOhm
reference_voltage: 3.3V
name: Resistance Sensor
- platform: adc
id: source_sensor
pin: A0
filters:
- multiply: 3.3
update_interval: never
########## NTC Self Heating Prevention ##########
switch:
- platform: gpio
pin:
number: GPIO4
id: ntc_vcc
interval:
- interval: 15s
then:
- switch.turn_on: ntc_vcc
- component.update: source_sensor
- switch.turn_off: ntc_vcc
@ tom_l
Thank you for the category Change i wasn’t sure.
tom_l
June 25, 2024, 1:22am
3
No worries. Unfortunately I’m not sure why this is happening and there are no open issues for the NTC component.
You could try adding another sensor like the wifi signal strength sensor to see if it is just the NTC component or a general sensor issue:
@tom_l ,
I did have a look for an issue but was unable to locate any myself, Forgot to mention that
Ill have a play round with the Wifi Signal Sensor later today and get back.
@tom_l . Apologies being rather dumb here [ Might have something to do with being awake so late ]
How does the WiFi Signal Sensor help?.,
tom_l
June 25, 2024, 1:52am
6
It’s a test to see if it is an NTC component issue or a more general one.
Does the Wifi sensor stop updating when you close the log as well?
Yes → ESPHome issue
Or is it only the NTC sensor that stops updating?
Yes → NTC component issue.
@tom_l - I See I see… Me being dumb
I have integrated the Sensor code int my code & can confirm its an NTC Component issue.
See FIG1 & FIG2 Attached below.
Images
FIG1 - With log screen open all working as should
FIG2 - BUG Returns
Here is the code updated for the NTC Thermistor module & Wifi Sensor
[ ALL IDENTIFYING INFO HAS BEEN PURGED ]
Code
####################################################################################################
####################################### Startup & Setup Code #######################################
####################################################################################################
########## MCU / Board Type ##########
esp8266:
board: esp01_1m
########## Hostnames ##########
esphome:
name: REDACTED-esp8266-dev
friendly_name: REDACTED-ESP8266-DEV
########## Enable logging ##########
logger:
########## Home Assistant API Hostname ##########
api:
encryption:
key: !secret API-REDACTED-ESP8266-DEV
########## System OTA ##########
ota:
- platform: esphome
password: !secret OTA-REDACTED-ESP8266-DEV
########## System WIFI ##########
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret wifi_domain
fast_connect: true
########## System IPV4 Address ##########
manual_ip:
static_ip: 10.9.0.151
gateway: 10.9.0.254
subnet: REDACTED
dns1: 10.9.0.254
########## Captive Portal, Fallback hotspot ##########
ap:
ssid: "FIX_ME-REDACTED-ESP8266-DEV"
password: !secret AP_password
captive_portal:
####################################################################################################
######################################### Main System Code #########################################
####################################################################################################
########## NTC Calibration Data ##########
sensor:
- platform: ntc
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: NTC Temperature
########## WiFi Signal Sensor ##########
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 15s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "Strength %"
entity_category: "diagnostic"
device_class: ""
########## NTC Configuration ##########
- platform: resistance
id: resistance_sensor
sensor: source_sensor
configuration: DOWNSTREAM
resistor: 10kOhm
reference_voltage: 3.3V
name: Resistance Sensor
- platform: adc
id: source_sensor
pin: A0
filters:
- multiply: 3.3
update_interval: never
########## NTC Self Heating Prevention ##########
switch:
- platform: gpio
pin:
number: GPIO4
id: ntc_vcc
interval:
- interval: 15s
then:
- switch.turn_on: ntc_vcc
- component.update: source_sensor
- switch.turn_off: ntc_vcc
— UPDATE —
Trying to eliminate variables with my setup i have discovered the following…
if i supply a constant 3.3v to this NTC Module [ Eliminating the Self Heating Prevention of the code ], my calibrations go out of whack but the readout on the dashboard stabilises +/- 1C closer to the actual temperature. Having logs open or closed does not make any difference.
Later today i will attempt to eliminate further by removing all the NTC from the sensor module & breadboarding it incase the comparator is interfering.
Here is the code updated for the NTC Thermistor module & removal of heating prevention
[ ALL IDENTIFYING INFO HAS BEEN PURGED ]
Code
####################################################################################################
####################################### Startup & Setup Code #######################################
####################################################################################################
########## MCU / Board Type ##########
esp8266:
board: esp01_1m
########## Hostnames ##########
esphome:
name: REDACTED-esp8266-dev
friendly_name: REDACTED-ESP8266-DEV
########## Enable logging ##########
logger:
########## Home Assistant API Hostname ##########
api:
encryption:
key: !secret API-REDACTED-ESP8266-DEV
########## System OTA ##########
ota:
- platform: esphome
password: !secret OTA-REDACTED-ESP8266-DEV
########## System WIFI ##########
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret wifi_domain
fast_connect: true
########## System IPV4 Address ##########
manual_ip:
static_ip: 10.9.0.151
gateway: 10.9.0.254
subnet: REDACTED
dns1: 10.9.0.254
########## Captive Portal, Fallback hotspot ##########
ap:
ssid: "FIX_ME-REDACTED-ESP8266-DEV"
password: !secret AP_password
captive_portal:
####################################################################################################
######################################### Main System Code #########################################
####################################################################################################
########## NTC Calibration Data ##########
sensor:
- platform: ntc
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: NTC Temperature
########## WiFi Signal Sensor ##########
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 15s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "Strength %"
entity_category: "diagnostic"
device_class: ""
########## NTC Configuration ##########
- platform: resistance
id: resistance_sensor
sensor: source_sensor
configuration: DOWNSTREAM
resistor: 10kOhm
reference_voltage: 3.3V
name: Resistance Sensor
- platform: adc
id: source_sensor
pin: A0
filters:
- multiply: 3.3
update_interval: 15s
Try a delay before the sensor update
@walberjunior - Thank you !!! - Give that person a pay rise & pint !!!, putting in a delay line in the Self heating Prevention & adjusting the value [ I can successfully get away with 10ms ] the NTC Module now reads correctly regardless of log state.
Here is the code updated for the NTC Thermistor module & adjustment of heating prevention. This code has also had an update to the Startup [ WiFi - as my network configuration has changed ].
[ ALL IDENTIFYING INFO HAS BEEN PURGED ]
Code
MrSJDDevelopments:
####################################################################################################
####################################### Startup & Setup Code #######################################
####################################################################################################
########## MCU / Board Type ##########
esp8266:
board: esp01_1m
########## Hostnames ##########
esphome:
name: REDACTED-esp8266-dev
friendly_name: REDACTED-ESP8266-DEV
########## Enable logging ##########
logger:
########## Home Assistant API Hostname ##########
api:
encryption:
key: !secret API-REDACTED-ESP8266-DEV
########## System OTA ##########
ota:
- platform: esphome
password: !secret OTA-REDACTED-ESP8266-DEV
########## System WIFI ##########
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
hidden: true
domain: !secret wifi_domain
fast_connect: true
output_power: 20.5
########## System IPV4 Address ##########
manual_ip:
static_ip: 10.9.0.151
gateway: 10.9.0.254
subnet: REDACTED
dns1: 10.9.0.254
########## Captive Portal, Fallback hotspot ##########
ap:
ssid: "FIX_ME-REDACTED-ESP8266-DEV"
password: !secret AP_password
captive_portal:
####################################################################################################
######################################### Main System Code #########################################
####################################################################################################
########## NTC Calibration Data ##########
sensor:
- platform: ntc
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: NTC Temperature
########## WiFi Signal Sensor ##########
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db
update_interval: 15s
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "Strength %"
entity_category: "diagnostic"
device_class: ""
########## NTC Configuration ##########
- platform: resistance
id: resistance_sensor
sensor: source_sensor
configuration: DOWNSTREAM
resistor: 10kOhm
reference_voltage: 3.3V
name: Resistance Sensor
- platform: adc
id: source_sensor
pin: A0
filters:
- multiply: 3.3
update_interval: never
########## NTC Self Heating Prevention ##########
switch:
- platform: gpio
pin:
number: GPIO4
id: ntc_vcc
interval:
- interval: 15s
then:
- switch.turn_on: ntc_vcc
- delay: 10ms
- component.update: source_sensor
- switch.turn_off: ntc_vcc
I have to ask, what gave you the idea for the fix ?.
I have used a rain sensor in the past and to avoid corrosion it is suggested to use the same method of turning off the GPIO.
In my tests I noticed a strange variation without the delay.
Without the delay I believe that the esp takes the reading before the component is properly energized.
I just don’t know why in your case it’s only happening with the log screen closed.
tom_l
June 25, 2024, 10:09pm
13
Writing to the log slowing down the main loop execution perhaps?
Not the same issue but the same reasons… This would explain the randomness of the reading, as during today i had notice it would sometime ping back to normal and then go loopy again.
potentially… Just enough for the ESP to manage a complete read.
I Thank you both for the help Rapid responses, & Solution. This one had me thinking a little bit to the extent i disassembled the module down to the NTC & created a circuit on a breadboard. if i could buy u both pints i would
Last query, that you know of is there any way i could live adjust the calibration without recompile of the firmware?. Adjust through HA Dashboard?.
tom_l
June 25, 2024, 10:41pm
15
The NTC sensor configuration options do not support templates.
You could do it with a lambda filter that takes inputs from template numbers and applies them to a linear equation ( y = mx +c):
sensor:
- platform: ntc
sensor: resistance_sensor
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: NTC Temperature
filters:
- lambda: return x * id(slope).state + id(constant).state;
number:
- platform: template
name: "Slope"
id: "slope"
optimistic: true
restore_value: true
min_value: -100
max_value: 100
step: 0.1
icon: mdi:slope-uphill
- platform: template
name: "Constant"
id: "constant"
optimistic: true
restore_value: true
min_value: -100
max_value: 100
step: 0.1
icon: mdi:alpha-c-box
EDIT: just realised you are not using an ESP32 so the number values will be forgotten after a restart unless you enable restore from flash: ESP8266 Platform — ESPHome
Thats where you loose me , I need to play around with lambdas & understand them more before i’m comfortable using them.
tom_l
June 25, 2024, 10:58pm
17
Using the above config Slope and Constant will appear as number helpers in Home Assistant. I have set them to a range of +/-100 with an adjustment step of 0.1 above but you can change this if needed.
Setting the slope to 1 and the constant to 0 will remove all adjustments.
Adjusting the constant number will increase or decrease your output by a constant amount (like the offset filter). So a constant of -2 will subtract two from all your sensor outputs.
Adjusting the slope number will change the proportional response. So a value of 2 will double your output. A value of 0.5 will halve it (equivalent to the multiply filter).
Using a combination of these two values you can fit your NTC output to any straight line response.