Hi, how do i setup this calculation as sensor template.
This code ist writen for esp8266
float taupunkt(float t, float r) {
float a, b;
if (t >= 0) {
a = 7.5;
b = 237.3;
} else if (t < 0) {
a = 7.6;
b = 240.7;
}
// Sättigungsdampfdruck in hPa
float sdd = 6.1078 * pow(10, (a*t)/(b+t));
// Dampfdruck in hPa
float dd = sdd * (r/100);
// v-Parameter
float v = log10(dd/6.1078);
// Taupunkttemperatur (°C)
float tt = (b*v) / (a-v);
return { tt };
}
t and r are existing entities of a temperatur and humidity sensor.
Thank you in advance, i am really lost how to write this as template
state: >
{% set t = states('sensor.temperature')|float(0) %}
{% set r = states('sensor.humidity')|float(0) %}
{% if t >= 0 %}
{% set a = 7.5 %}
{% set b = 237.3 %}
{% else %}
{% set a = 7.6 %}
{% set b = 240.7 %}
{% endif %}
{% set sdd = 6.1078 * (10**(a*t)/(b+t))) %}
{% set dd = sdd * (r/100) %}
{% set v = log(dd/6.1078,10) %}
{% set tt = (b*v) / (a-v) %}
{{ tt }}
availability: "{{ has_value('sensor.temperature') and has_value('sensor.humidity') }}"