Blackymas / NSPanel_HA_Blueprint

This allows you to configure your complete NSPanel via Blueprint with UI and without changing anything in the code
1.26k stars 234 forks source link

instead of the NTC sensor #1989

Closed eqasxar closed 2 months ago

eqasxar commented 3 months ago

Enhancement Summary

instead of the NTC sensor

Detailed Description

I want to use an external DS18B20 for the thermostat instead of the NTC sensor (GPIO38). Where do I need to add/change the code so that the thermostat template doesn’t read the sensor as NTS, but as DS18B20?

Additional Context

No response

andythomas commented 3 months ago

I am not 100% sure I follow.

1) You soldered/attached a DS18B20 to the NSPanel and you want to use it as the temperature sensor?! In nspanel_esphome_core.yaml you will find

  ##### INTERNAL TEMPERATURE SENSOR, ADC VALUE #####
  - id: ntc_source
    platform: adc
    pin: 38
    update_interval: 60s
    attenuation: 11db
    samples: 12

  ##### INTERNAL TEMPERATURE SENSOR, adc reading converted to resistance (calculation)#####
  - id: resistance_sensor
    platform: resistance
    sensor: ntc_source
    configuration: DOWNSTREAM
    resistor: 11.2kOhm

  ##### INTERNAL TEMPERATURE SENSOR, resistance to temperature (calculation) #####
  - id: temp_nspanel
    name: Temperature
    platform: ntc
    sensor: resistance_sensor
    unit_of_measurement: °C
    internal: false
    calibration:
      b_constant: 3950
      reference_temperature: 25°C
      reference_resistance: 10kOhm
    filters:
      - lambda: |-
          return x + temperature_correction->state;
    on_value:
      then:
        # Show panel's temperature if API or Wi-Fi are out
        - lambda: display_embedded_temp->execute();

If you want to overwrite that in your yaml, you could utilize

sensor:
  - id: !extend ntc_source
 ...
  - id: !extend resistance_sensor
 ...
  - id: !extend temp_nspanel
 ...

2) However, if you have a completely different temperature sensor independent of the panel, I suggest to integrate it in Home Assistant (I believe it is called 'generic thermostat') and not the panel. It would be more difficult and you would have no benefit, because it would not work either way if Home Assistant or the WiFi is down. Then, you can add that to the blueprint.

edwardtfn commented 3 months ago

Maybe if you share your panel's yaml we will understand better what you are trying. Differently than @andythomas, I understood you have the DS18B20 already set in your system and you want to use that instead, is it correct?

If that is the case, follow the suggestion from @andythomas to overwrite the temp_nspanel only. You can, but don't have to, remove the ntc code. You can even store that in a separated sensor.

Please describe it better and we will do our best. 😉

eqasxar commented 3 months ago

I haven't changed anything in the NSPanel code yet. That's why I'm asking, I'm afraid of breaking the code. I have made a thermostat Sonoff with ESP8266 with typical ESPHome yaml. The goal of my project is to use the NSPanel first as an independent sauna thermostat and spa controller, before connecting it to the Home Assistant. This way I will avoid problems if the server is not available. I agree that it is possible to not break the NTC code and not even use GPIO38. Can use GPIO23, GPIO14, GPIO27. Where to insert the thermostat code with DS18B20?


# Customization area
##### My customization - Start #####
# Here? Insert thermostat code?

sensor:
  - platform: dallas
    name: "dallas_sensor"
    id: dallas_sensor
    address: 0xcb011553a444ff28    

dallas:
  pin: 17 #GPIO14
  update_interval: 60s

# #### My customization - End #### #
edwardtfn commented 3 months ago

That is the right place. 😉

edwardtfn commented 3 months ago

By the way, why are you using bang_bang climate and not the add-on?

eqasxar commented 3 months ago

By the way, why are you using bang_bang climate and not plugin?

It `s my mistake. I skimmed through the comments. If in the code leave a description with NTC for the sensor. Describe the Dallas sensor as a separate sensor and change the thermostat code to refer to the Dallas sensor.

nspanel_esphome_addon_climate_base.yaml

climate:
  - platform: thermostat
    name: Thermostat
    id: thermostat_embedded
    sensor: dallas_sensor # **temp_nspanel  <- change here**

nspanel_esphome_addon_climate_heat.yaml

substitutions:
  ### Local thermostat defaults ##
  temp_max: "80"  #  **<- change here**

nspanel_esphome_core.yaml

### NEW INSERT:

  ## DALLAS EXTERNAL TEMPERATURE SENSOR, ADC VALUE 

sensor:
  - platform: dallas
    name: "dallas_sensor"
    id: dallas_sensor
    address: 0xcb011553a444ff28    

dallas:
  pin: 17 #GPIO14
  update_interval: 60s

  ##   CAN IT BE LEFT HERE UNCHANGED? But this should no longer affect the operation of the thermostat ? :

  ## INTERNAL TEMPERATURE SENSOR, ADC VALUE ##
  - id: ntc_source
    platform: adc
    pin: 38
    update_interval: 60s
    attenuation: 11db
    samples: 12

  ## INTERNAL TEMPERATURE SENSOR, adc reading converted to resistance (calculation)##
  - id: resistance_sensor
    platform: resistance
    sensor: ntc_source
    configuration: DOWNSTREAM
    resistor: 11.2kOhm

  ## INTERNAL TEMPERATURE SENSOR, resistance to temperature (calculation) ##
  - id: temp_nspanel
    name: Temperature
    platform: ntc
    sensor: resistance_sensor
    unit_of_measurement: °C
    internal: false
    calibration:
      b_constant: 3950
      reference_temperature: 25°C
      reference_resistance: 10kOhm
    filters:
      - lambda: |-
          return x + temperature_correction->state;
    on_value:
      then:
        # Show panel's temperature if API or Wi-Fi are out

        - lambda: display_embedded_temp->execute();
edwardtfn commented 3 months ago

You don't have to edit nspanel_esphome_addon_climate_base.yaml or nspanel_esphome_core.yaml, just add everything on your panel's yaml, so you don't have to repeat the customization on every release.

In your panel's yaml will be like this:

# Customization area
##### My customization - Start #####

sensor:
  - platform: dallas
    name: "dallas_sensor"
    id: dallas_sensor
    address: 0xcb011553a444ff28    

dallas:
  pin: 17 #GPIO14
  update_interval: 60s

climate:
  - id: !extend thermostat_embedded
    sensor: dallas_sensor

# #### My customization - End #### #

Alternatively, you can replace the internal thermometer's entity. This will probably be more transparent to the system, so you will have the right temperature shown on the screen when Wi-Fi is out, temperature correction, etc. And in this case you don't have to change anything on the climate.

Something like this:

# Customization area
##### My customization - Start #####

sensor:
  - id: !extend temp_nspanel
    platform: dallas
    address: 0xcb011553a444ff28
    calibration: !remove
    sensor: !remove

dallas:
  pin: 17 #GPIO14
  update_interval: 60s

# #### My customization - End #### #

This is basically changing the existing temperature entity to use your new sensor instead of ntc.

eqasxar commented 3 months ago

yes Thank you very much. Of course, I wouldn't want to edit the code after every update. Using dalls instead of NTC would be most convenient programmatically. R21 still needs to be shortened. It is physically more convenient to use the unused pin of GPIO23 RY3.

eqasxar commented 2 months ago

only after using pin:25 #GPIO16 validate was successful. but the installation failed [.pioenvs/nspanel/src/esphome/components/ntc/ntc.o] Source src/esphome/components/ntc/ntc.cpp' not found, needed by target.pioenvs/nspanel/src/esphome/components/ntc/ntc.o'.

dallas:
  #pin: 14 #GPIO38 NTC ->>>> dallas: [source /config/esphome/nspanel.yaml:14] ***Pin 14 is used in multiple places.
  #pin: 36 #GPIO23 RY3  ->>>> GPIO36 (34-39) does not support output pin mode.
  #pin: 17 #GPIO14         ->>>> Pin 17 is used in multiple places.
  #pin: 16 #GPIO27          ->>>> Pin 16 is used in multiple places.
  pin: 25 #GPIO16
  #pin: 27 #GPIO17
  update_interval: 60s

sensor:
  - id: !extend temp_nspanel
    platform: dallas
    address: 0xcb011553a444ff28
    calibration: !remove
    sensor: !remove
gbeleris commented 2 months ago

Hello, how would I go about replacing the sensor of the thermostat from the climate addon with the temperature sensor from a xiaomi sensor flashed to pass on data to HA via BT proxies? Or perhaps a zigbee sensor for that matter.

Ideally, what I am trying to achieve is to have the panel be as a BT proxy and the xiaomi sensor to provide measurments. The built in sensor is quite inaccurate I find and heats up easy when the panel gets more use. Many thanks!

edwardtfn commented 2 months ago

Please take a look at those: