How to write a lambda to calculate the Abs. Humidity from the LTS temp and Rel. humidity values? #140
-
hi, I've found this formula (as well as the usual psychrometric diagrams, unusable for computer use): Absolute Humidity (grams/m3) = (6.112 × e^[(17.67 × T)/(T+243.5)] × rh × 2.1674)/(273.15+T). I know it would be most efficient to have the Abs Hum to be calculated using a template sensor in HA at data point storage time and then the LTS of them being used for plotting. If it's part of a lambda as well (initially), then I could use the stored LTS values to calculate it on-the-fly, at run-time, also for my historic values. It might be (too) slow, but I think if I keep the number of data points per graph low, it might be feasible. In the meantime, I'll build up my history using the template sensor(s). Unfortunately, I don't know enough about the lambda syntax to convert the formula into working code. For lambdas, I used normally the good old copy-paste-adjust adagio.... Poor me. But it works! Thanks. PS, this is the current result. The colours for Temp and humidity are not matching 100%, but that will be a small fix. The Abs. Humidity will be a 3rd graph, below the current 2: Yes, it's rather cold in the house, but I'm away for 2 weeks, since 9th (evening), so very little natural and no artificial heating, in a 1970's house... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Setting the period to 5minutes (implies statistic: mean) makes the timestamps of both sensor to align perfectly, allowing to easily make mathematical operations using both sensors type: custom:plotly-graph
entities:
- entity: sensor.wintergarten_clima_temperature
period: 5minute
lambda: |-
(ys ,xs) => {
window.temperature = {xs,ys};
return ys;
}
- entity: sensor.wintergarten_clima_humidity
period: 5minute
name: Absolute Hty
unit_of_measurement: g/m³
lambda: |-
(ys, xs) => {
const t = window.temperature;
const h = {xs, ys:ys.map(parseFloat)};
return h.ys.map((rh, i) => {
const T = parseFloat(t.ys[i-1]);
return (6.112 * Math.exp((17.67 * T)/(T+243.5)) * rh * 2.1674)/(273.15+T);
})
}
- entity: sensor.wintergarten_clima_humidity
period: 5minute
hours_to_show: 24
|
Beta Was this translation helpful? Give feedback.
Setting the period to 5minutes (implies statistic: mean) makes the timestamps of both sensor to align perfectly, allowing to easily make mathematical operations using both sensors