Hey there
I did create 3 template sensors. Two of them are running, but 1 shows “not awailable”.
I have no idea why… Here is the code - it’s the third one not running “absoluteluftfeuchtigkeitunterschiedbuero”
template:
- sensor:
# Errechnet aus der relativen Luftfeuchtigkeit und Temperatur außen die absolute Luftfreuchtigkeit in Gramm pro Kubikmeter
- name: "absoluteLuftfeuchtigkeitaussen"
unique_id: "AbsoluteHumidityAussen"
unit_of_measurement: "g/m^3"
state_class: "measurement"
state: >
{{ ( 1000*e**(19.016-(4064.95/(float(states('sensor.teichhalle_temperature'))+236.25)))*100/(461.66*(float(states('sensor.teichhalle_temperature'))+273.15)) * float(states('sensor.teichhalle_humidity'))/100 | float) | round (2) }}
# Errechnet aus der relativen Luftfeuchtigkeit und Temperatur im Innenraum die absolute Luftfreuchtigkeit in Gramm pro Kubikmeter
- name: "absoluteluftfeuchtigkeitbüro"
unique_id: "AbsoluteHumidityBuero"
unit_of_measurement: "g/m^3"
state_class: "measurement"
state: >
{{ ( 1000*e**(19.016-(4064.95/(float(states('sensor.shellyhtbuero_temperature'))+236.25)))*100/(461.66*(float(states('sensor.shellyhtbuero_temperature'))+273.15)) * float(states('sensor.shellyhtbuero_humidity'))/100 | float) | round (2) }}
# Errechnet den Untschied der Luftfeuchte von innen und außen in Gramm pro Kubikmeter
- name: "absoluteluftfeuchtigkeitunterschiedbuero"
unique_id: "AbsoluteHumidityDifferenceBuero"
unit_of_measurement: "g/m^3"
state_class: "measurement"
state: >
{{ ( float(states('sensor.absoluteluftfeuchtigkeitbüro')) - float(states('sensor.absoluteLuftfeuchtigkeitaussen')) ) | float | round (2) }}
When in doubt paste in Developer Tools → Templates
There are some weird things in your code, like putting float infront of the state. But that could be the correct way for all i know
Anyway you need to define default values for when the sensor isnt getting a value. Also in the Dev tools this would show up at once
Thank you guys.
I changed my sensors names as @Troon told me.
And used the code from @Dujith, which is same as @jchh’s Code, but missing a }.
But that was a problem even a beginner like me could solve :o)
jchh
(my username is my initials (and my first name isn't John))
6
I think we both had typos - I was missing a ( before the 2nd states(. However, noticing this made me look closer at the line and you can remove some brackets.
I have split it onto different lines so the remaining bracket stands out as applying the |round(2) filter to the result of the subtraction. No other brackets are needed.