In an effort to improve the mold indicator integration which I use to turn on my dehumidifier when there is a chance of window condensation forming I have implemented the integration as a template sensor that uses an actual surface temperature from an ESP32 rather than a calibration factor and outside temperature:
template:
- sensor:
- name: Lounge Condensation Chance
unit_of_measurement: "%"
icon: >
{% set chance = states('sensor.lounge_condensation_chance')|float(0) %}
{% if chance == 0 %}
mdi:water-alert-outline
{% elif chance > 70 %}
mdi:water-percent-alert
{% else %}
mdi:water-check-outline
{% endif %}
state_class: measurement
state: >
{# ### CHANGE THESE THREE SENSORS ### #}
{% set room_temp = states('sensor.lounge_room_temperature')|float(0) %}
{% set room_humid = states('sensor.lounge_room_humidity')|float(0) %}
{% set crit_temp = states('sensor.lounge_window_temperature')|float(0) %}
{% set MK2 = 17.62 %}
{% set MK3 = 243.12 %}
{% set alpha = MK2 * room_temp / ( MK3 + room_temp ) %}
{% set beta = MK2 * MK3 / ( MK3 + room_temp ) %}
{% set dewpt = MK3 * ( alpha + log( room_humid / 100 ) ) / ( beta - log( room_humid / 100 ) ) %}
{% set alpha_crit = MK2 * crit_temp / ( MK3 + crit_temp ) %}
{% set beta_crit = MK2 * MK3 / ( MK3 + crit_temp) %}
{% set crit_humidity = ( e ** ( ( dewpt * beta_crit - MK3 * alpha_crit) / ( dewpt + MK3) ) * 100 )|round(0)|int %}
{{ ([0,crit_humidity,100]|sort)[1] }}
availability: >
{# ### CHANGE THESE THREE SENSORS ### #}
{{ has_value('sensor.lounge_room_temperature') and
has_value('sensor.lounge_room_humidity') and
has_value('sensor.lounge_window_temperature') }}
This works very well but it seems a shame to have an ESP32 doing nothing but measuring the temperature of the window. So I thought I could import the lounge temp and humidity into the ESP and calculate the condensation chance in the ESP.
Does anyone know how to convert that template sensor into an ESPHome template sensor?
I got nowhere with the lambda.
ESP config:
esphome:
name: lounge-window-ds1820b
platform: ESP32
board: mhetesp32minikit
wifi:
ssid: 'WAPLO'
password: !secret wifi_pwd
manual_ip:
static_ip: 10.1.1.67
gateway: 10.1.1.1
subnet: 255.255.255.0
api:
encryption:
key: !secret api_encryption_key
logger:
ota:
password: !secret esp_pwd
dallas:
- pin: GPIO16
update_interval: 3s
binary_sensor:
- platform: status
name: "Lounge Window Status"
sensor:
- platform: wifi_signal
name: "Lounge Window WiFi Signal"
update_interval: 4s
filters:
- sliding_window_moving_average:
window_size: 15
send_every: 15
send_first_at: 1
- platform: dallas
address: 0x793351d4437dea28
name: "Lounge Window Temperature"
id: window_temperature
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 10
send_first_at: 1
- platform: homeassistant
id: lounge_temperature
entity_id: sensor.lounge_room_temperature
- platform: homeassistant
id: lounge_humidity
entity_id: sensor.lounge_room_humidity
- platform: template
name: "Lounge Room Condensation Chance"
unit_of_measurement: "%"
lambda: |- # Help!