Humidity-Calculator [5.2.0.0;5.9.9.9]

material-symbols--dew-point

  1. Calculator → Calculate absolute humidity, dew point, vapor pressure, or wet-bulb temperature from temperature and relative humidity.
  2. Comparison → Compares absolute humidity or dew point between two locations using their temperature and humidity sensors. Writes the difference (positive if Location 1 exceeds Location 2) to a target item, either as a percentage or in Kelvin/°C.
    Language: JS Scripting Scripting with openhab-js 5.18.2

Dependencies:
openhab-js 5.18.2 or later

Changelog

Version 0.1.1

  • when comparing ( dew point control) no unit is supplied.

Version 0.1

  • initial release

Bug reports and improvement suggestions are highly encouraged.

Resources

version: 1

ruleTemplates:
  oh-Humidity-Calculator:
    label: oh-Humidity-Calculator
    description: Calculate absolute humidity, dew point, vapor pressure, or wet-bulb temperature from temperature and relative humidity.
    tags:
      - Version_0.1
    configDescriptions:
      Temp:
        label: temperature
        description: Number Item with unit °C/°F
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Hum:
        label: relative humidity
        description: Number Item with percent
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Pressure:
        label: pressure
        description: "<b>Optional</b> Improved accuracy for wet-bulb"
        context: item
        required: false
        default: 'undefined'
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Ziel:
        label: target Item
        description: Item for return value. OH handles the conversion to the desired unit.
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Parameter:
        label: Parameter
        required: false
        defaultValue: Humidity
        type: TEXT
        options:
          - label: 'absolute humidity g/m³'
            value: 'Humidity'
          - label: 'dew point °C/°F'
            value: 'dewPoint'
          - label: 'vapor pressure hPa'
            value: 'vaporPressure'
          - label: 'wet-bulb °C/°F'
            value: 'wetBulb'
    triggers:
      - id: Temp_trigger
        config:
          itemName: "{{Temp}}"
        type: ItemChanged
      - id: Hum_trigger
        config:
          itemName: "{{Hum}}"
        type: ItemChanged
    actions:
      - id: "oh-Humidity-calculator_action"
        label: "oh-Humidity-calculator"
        description: Created with Rule Templates
        type: Script
        config:
          type: javascript
          script: |
            'use wrapper=true'
            function fTaupunkt(r, t, press) {
                if (isNaN(r) || isNaN(t)) {
                  return { dewPoint: 'NaN', Humidity: 'NaN', vaporPressure: 'NaN', wetBulb: 'NaN' };
                }
                const mw = 18.016; 
                const gk = 8314.3;     
                const t0 = 273.15; 
                const tk = t + t0;    
                const a = (t >= 0) ? 7.5 : 7.6;
                const b = (t >= 0) ? 237.3 : 240.7;
                const sdd = 6.1078 * Math.pow(10, (a * t) / (b + t)); 
                const dd = sdd * (r / 100);
                const af = (Math.pow(10, 5) * mw / gk) * (dd / tk);    
                const v = Math.log10(dd / 6.1078);
                const tt = (b * v) / (a - v);
                // Stull-Basisformel (für Standarddruck kalibriert)
                let tw = t * Math.atan(0.151977 * Math.pow(r + 8.313659, 0.5)) +
                    Math.atan(t + r) -
                    Math.atan(r - 1.676331) +
                    0.00391838 * Math.pow(r, 1.5) * Math.atan(0.023101 * r) -
                    4.686035;
                // Einfache empirische Druckkorrektur (Näherung)
                // Bei niedrigerem Druck verdunstet Wasser leichter -> tw sinkt leicht
                const pruckKorrektur = (1013.25 - press) * 0.0008;
                tw = tw - pruckKorrektur;
                return { 
                  InputTemp: `${t.toFixed(2)} °C`, 
                  InputHum: `${r.toFixed(2)} %`, 
                  dewPoint: `${tt.toFixed(2)} °C`, 
                  Humidity: `${af.toFixed(2)} g/m³`, 
                  vaporPressure: `${dd.toFixed(2)} hPa`, 
                  wetBulb: `${tw.toFixed(2)} °C`
                };
            }
            const getPressureValue = (itemName) => {
              if (!itemName || itemName === 'undefined' || itemName === '') {
                return 1013.25;
              }
              try {
                const qState = items.getItem(itemName)?.quantityState;
                const value = qState ? qState.toUnit('hPa')?.float : NaN;
                return !isNaN(value) ? value : 1013.25;
              } catch {
                return 1013.25;
              }
            };
            const getTempValueCelsius = (itemName) => {
              const qState = items.getItem(itemName).quantityState;
              return qState.toUnit('°C').float;
            };
            const outcome = fTaupunkt(
                items.getItem('{{Hum}}').numericState,
                getTempValueCelsius('{{Temp}}'),
                getPressureValue('{{Pressure}}')
            );
            // console.warn('E= ', outcome);
            items['{{Ziel}}'].postUpdate(outcome.{{Parameter}});
  oh-Humidity-Comparison:
    label: oh-Humidity-Comparison
    description: Calculates the humidity difference between two Location
    tags:
      - Version_0.1.1
    configDescriptions:
      Temp1:
        label: Location 1 - temperature
        description: Number Item with unit °C/°F
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Hum1:
        label: Location 1 - relative humidity
        description: Number Item with percent
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Temp2:
        label: Location 2 - temperature
        description: Number Item with unit °C/°F
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Hum2:
        label: Location 2 - relative humidity
        description: Number Item with percent
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Ziel:
        label: target Item
        description: Item for return value. The result is positive if the humidity in Location 1 > Location 2.
        context: item
        required: true
        type: TEXT
        filterCriteria:
          - name: type
            value: Number
      Parameter:
        label: Parameter
        description: Set the unit for the dew point item to K or °C. Converting not meaningful.
        required: false
        defaultValue: Humidity
        type: TEXT
        options:
          - label: 'absolute humidity, Return difference in %'
            value: 'Humidity'
          - label: 'dew point, Return difference in K'
            value: 'dewPoint'
    triggers:
      - id: Temp_trigger1
        config:
          itemName: "{{Temp1}}"
        type: ItemChanged
      - id: Hum_trigger1
        config:
          itemName: "{{Hum1}}"
        type: ItemChanged
      - id: Temp_trigger2
        config:
          itemName: "{{Temp2}}"
        type: ItemChanged
      - id: Hum_trigger2
        config:
          itemName: "{{Hum2}}"
        type: ItemChanged
    actions:
      - id: "oh-Humidity-Comparison_action"
        label: "oh-Humidity-Comparison"
        description: Created with Rule Templates
        type: Script
        config:
          type: javascript
          script: |
            'use wrapper=true'
            let outcome_Ziel = '';
            function fTaupunkt(r, t) {
                if (isNaN(r) || isNaN(t)) {
                  return { dewPoint: 'NaN', Humidity: 'NaN'};
                }
                const mw = 18.016; 
                const gk = 8314.3;     
                const t0 = 273.15; 
                const tk = t + t0;    
                const a = (t >= 0) ? 7.5 : 7.6;
                const b = (t >= 0) ? 237.3 : 240.7;
                const sdd = 6.1078 * Math.pow(10, (a * t) / (b + t)); 
                const dd = sdd * (r / 100);
                const af = (Math.pow(10, 5) * mw / gk) * (dd / tk);    
                const v = Math.log10(dd / 6.1078);
                const tt = (b * v) / (a - v);
                return { 
                  InputTemp: `${t.toFixed(2)} °C`, 
                  InputHum: `${r.toFixed(2)} %`,  
                  dewPoint: tt, 
                  Humidity: af
                };
            }
            let getTempValueCelsius = (itemName) => {
              let qState = items.getItem(itemName).quantityState;
              return qState.toUnit('°C').float;
            };
            const outcome_1 = fTaupunkt(
                items.getItem('{{Hum1}}').numericState,
                getTempValueCelsius('{{Temp1}}')
            );
            const outcome_2 = fTaupunkt(
                items.getItem('{{Hum2}}').numericState,
                getTempValueCelsius('{{Temp2}}')
            );
            if ('{{Parameter}}' == 'Humidity'){
                outcome_Ziel = ((outcome_1.Humidity - outcome_2.Humidity) / outcome_2.Humidity * 100).toFixed(3) + ' %';
            }else{
                outcome_Ziel = (outcome_1.dewPoint - outcome_2.dewPoint).toFixed(3);
            }
            // console.warn('E=', outcome_Ziel, '; L1=', outcome_1, '; L2=', outcome_2 );
            items['{{Ziel}}'].postUpdate(outcome_Ziel);

My example versioning were wrong. The open ended versioning like this won’t work. Change your title to use [5.2.0.0;5.9.9.9] to have the entry show up properly in the Add-on store.

But thanl you for posting a tempalte! I’ve been trying to get more people to do so for years.