Semantic features, Filter and air humidity

Block2508GroupTags

representing the Semantic features of an openHAB Item to Blockly
simple filter functions,
and
a calculator for humidity

Semantic-Blocks

Parents of Item

return equipment and location as a Item

Type of …

return a String

Whether the Item is a …

return a Boolean

Filter-Blocks

return a List (Array)

Care blocks for groups and tags

Block2508GroupTags

Carelessly swapping tags can damage the semantic-model. Therefore, always make a fresh backup beforehand.

Calculator for air humidity

Calculated based on this Function absolute air humidity, dew point, vapor pressure and wet-bulb.
Input only in Units % and °C. The Unit for Output Is included.

Changelog

Version 0.6

  • new Blocks for map and removes duplicate

Version 0.5

  • the filter for semantic-group-item can now also be used for location with all equipment
  • new Blocks for care groups and tags

Version 0.4

  • simple calculation wet-bulb with deviation < +/- 1 C°
  • simple filter functionsVersion 0.4

Version 0.3

  • Fine-tuning code

Version 0.2

  • Optical changes

Version 0.1

  • first published version

Ressourcen

-requires JavaScript (ECMAScript 2022+/GraalJS)

uid: Semantic_Humidity
tags:
  - marketplace:164297
props:
  parameters: []
  parameterGroups: []
timestamp: Aug 20, 2025, 6:12:18 PM
component: BlockLibrary
config:
  name: Semantic, Filter & Humidity
slots:
  blocks:
    - component: BlockType
      config:
        args0:
          - name: optSemantic
            options:
              - - Equipment
                - equipment
              - - Location
                - location
            type: field_dropdown
          - align: right
            name: semanticItem
            type: input_value
        colour: 0
        helpUrl: https://openhab.github.io/openhab-js/items.ItemSemantics.html
        message0: semantic %1 parent of item %2
        output: ""
        tooltip: equipment/location of Item. In for_each use get_name_of_item if
          necessary
        type: SemanticItem
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: items.getItem({{input:semanticItem}}).semantics.{{field:optSemantic}}
        toolbox:
          - component: PresetInput
            config:
              name: semanticItem
              shadow: true
              type: oh_item
    - component: BlockType
      config:
        args0:
          - name: optSemantic
            options:
              - - Equipment
                - equipmentType
              - - Location
                - locationType
              - - Point
                - pointType
              - - Property
                - propertyType
              - - Semantic
                - semanticType
            type: field_dropdown
          - align: right
            name: semanticItem
            type: input_value
        colour: 165
        helpUrl: https://openhab.github.io/openhab-js/items.ItemSemantics.html
        message0: semantic %1 type of item %2
        output: String
        tooltip: Type of equipment/location/point/property/semantic. Return string
        type: SemanticString
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: items.getItem({{input:semanticItem}}).semantics.{{field:optSemantic}}
        toolbox:
          - component: PresetInput
            config:
              name: semanticItem
              shadow: true
              type: oh_item
    - component: BlockType
      config:
        args0:
          - name: optSemantic
            options:
              - - Equipment
                - isEquipment
              - - Location
                - isLocation
              - - Point
                - isPoint
            type: field_dropdown
          - align: right
            name: semanticItem
            type: input_value
        colour: 210
        helpUrl: https://openhab.github.io/openhab-js/items.ItemSemantics.html
        message0: semantic is %1 ? of item %2
        output: Boolean
        tooltip: Is Equipment/Location/Point? Return Boolean
        type: semanticBoolean
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: items.getItem({{input:semanticItem}}).semantics.{{field:optSemantic}}
        toolbox:
          - component: PresetInput
            config:
              name: semanticItem
              shadow: true
              type: oh_item
    - component: BlockType
      config:
        args0:
          - name: optFilterMember
            options:
              - - members
                - members
              - - descendents
                - descendents
            type: field_dropdown
          - align: left
            name: semanticItem
            type: input_value
          - name: optFilterGroup
            options:
              - - Name
                - name
              - - Label
                - label
              - - Tags
                - tags
              - - Type
                - type
              - - MetadataName
                - getMetadata()
              - - LocationType
                - semantics.locationType
              - - SemanticType
                - semantics.semanticType
              - - PropertyType
                - semantics.propertyType
              - - EquipmentType
                - semantics.equipmentType
              - - PointType
                - semantics.pointType
            type: field_dropdown
          - name: suchtext
            type: input_value
        colour: 260
        inputsInline: true
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        message0: in %1 of semantic-group-item %2 filter %3 include %4
        output: Array
        tooltip: method checks if a specific value exists. Return List of items
        type: filterGroup
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: items.getItem({{input:semanticItem}}).{{field:optFilterMember}}.filter(
                x => {{utility:fFilterBlock}}(x.{{field:optFilterGroup}},
                {{input:suchtext}}))
        toolbox:
          - component: PresetInput
            config:
              name: semanticItem
              shadow: true
              type: oh_item
          - component: PresetInput
            config:
              fields:
                TEXT: text
              name: suchtext
              shadow: true
              type: text
    - component: BlockType
      config:
        args0:
          - align: left
            name: Dummy
            type: input_dummy
          - name: optFilterGroup
            options:
              - - Name
                - name
              - - Label
                - label
              - - Tags
                - tags
              - - Type
                - type
              - - MetadataName
                - getMetadata()
              - - LocationType
                - semantics.locationType
              - - SemanticType
                - semantics.semanticType
              - - PropertyType
                - semantics.propertyType
              - - EquipmentType
                - semantics.equipmentType
              - - PointType
                - semantics.pointType
            type: field_dropdown
          - name: suchtext
            type: input_value
        colour: 260
        inputsInline: true
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        message0: in all items %1 filter %2 include %3
        output: Array
        tooltip: method checks if a specific value exists. Return List of items
        type: filterAll
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: items.getItems().filter( x =>
                {{utility:fFilterBlock}}(x.{{field:optFilterGroup}},
                {{input:suchtext}}))
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: text
              name: suchtext
              shadow: true
              type: text
    - component: BlockType
      config:
        args0:
          - align: left
            name: itemList
            check: Array
            type: input_value
          - name: optFilterGroup
            options:
              - - Name
                - name
              - - Label
                - label
              - - Tags
                - tags
              - - Type
                - type
              - - MetadataName
                - getMetadata()
              - - LocationType
                - semantics.locationType
              - - SemanticType
                - semantics.semanticType
              - - PropertyType
                - semantics.propertyType
              - - EquipmentType
                - semantics.equipmentType
              - - PointType
                - semantics.pointType
            type: field_dropdown
          - name: suchtext
            type: input_value
        colour: 260
        inputsInline: true
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        message0: in List of items %1 filter %2 include %3
        output: Array
        tooltip: method checks if a specific value exists. Return List of items
        type: filterList
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{input:itemList}}.filter( x =>
                {{utility:fFilterBlock}}(x.{{field:optFilterGroup}},
                {{input:suchtext}}))"
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: text
              name: suchtext
              shadow: true
              type: text
    - component: BlockType
      config:
        args0:
          - align: left
            name: itemList
            check: Array
            type: input_value
          - name: optFilterState
            options:
              - - state
                - state
              - - numericState
                - numericState
              - - Name
                - name
            type: field_dropdown
          - name: Comparison
            options:
              - - ==
                - ==
              - - "!="
                - "!="
              - - <
                - <
              - - <=
                - <=
              - - ">"
                - ">"
              - - ">="
                - ">="
            type: field_dropdown
          - name: ValueComparison
            type: input_value
        colour: 260
        inputsInline: true
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        message0: in List of items %1 compare %2 %3  %4
        output: Array
        tooltip: Compare the values. Return List of items
        type: filterVergleich
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{input:itemList}}.filter((i => i.{{field:optFilterState}}
                {{field:Comparison}} {{input:ValueComparison}}))"
    - component: BlockType
      config:
        args0:
          - align: left
            name: itemList
            check: Array
            type: input_value
          - name: map
            options:
              - - Name
                - name)
              - - Label
                - label)
              - - LocationLabel
                - semantics.location).label
              - - state
                - state)
              - - numericState
                - numericState)
            type: field_dropdown
        colour: 260
        inputsInline: true
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        message0: List of items %1 map %2
        output: Array
        tooltip: reduces the output to a property of the objects. Return List of value
        type: mapList
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{input:itemList}}.map( x => (x.{{field:map}})"
    - component: BlockType
      config:
        args0:
          - align: left
            name: itemList
            check: Array
            type: input_value
        colour: 260
        inputsInline: true
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        message0: Set List %1 unique
        output: Array
        tooltip: removes duplicate from the list. Return list.
        type: DuplicateEX
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "[...new Set({{input:itemList}})]"
    - component: BlockType
      config:
        args0:
          - align: left
            name: semanticItem
            type: input_value
          - check: Array
            name: itemList
            type: input_value
        colour: 0
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        inputsInline: true
        message0: add list of items %2 to groupItem %1
        nextStatement: ""
        previousStatement: ""
        tooltip: adds a list of items to a group
        type: addGroups
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{input:itemList}}.forEach(i => i.addGroups({{input:semanticItem}}))"
        toolbox:
          - component: PresetInput
            config:
              name: semanticItem
              shadow: true
              type: oh_item
    - component: BlockType
      config:
        args0:
          - align: left
            name: semanticItem
            type: input_value
          - name: oldTags
            type: input_value
          - name: newTags
            type: input_value
        colour: 0
        helpUrl: https://community.openhab.org/t/semantic-features-filter-and-air-humidity/
        inputsInline: true
        message0: replace Tags from %2 to %3 of item %1
        nextStatement: ""
        previousStatement: ""
        tooltip: swaps old tags for new ones, multiple values separated by commas
          possible. Backup first.
        type: ReplaceTag
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: ({{utility:fReplaceTags}}({{input:semanticItem}}, {{input:oldTags}},
                {{input:newTags}}))
        toolbox:
          - component: PresetInput
            config:
              name: semanticItem
              shadow: true
              type: oh_item
          - component: PresetInput
            config:
              fields:
                TEXT: old
              name: oldTags
              shadow: true
              type: text
          - component: PresetInput
            config:
              fields:
                TEXT: new
              name: newTags
              shadow: true
              type: text
    - component: BlockType
      config:
        args0:
          - name: Ausgabe
            options:
              - - Humidity g/m3
                - af
              - - dew point °C
                - tt
              - - vapor pressure hPa
                - dd
              - - wet-bulb °C
                - tw
            type: field_dropdown
          - name: relativ
            type: input_value
          - align: right
            name: temp
            type: input_value
        colour: 60
        helpUrl: https://www.smarthome-tricks.de/iobroker-scriptsammlung/taupunkt-berechnen/
        lastDummyAlign0: right
        message0: "%1 from rel. humidity % %2 and temperature °C %3"
        output: Number
        tooltip: calculates values for humidity
        type: Humidity
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{utility:fTaupunkt}}({{input:relativ}},{{input:temp}}).{{field:Ausg\
                abe}}"
        toolbox:
          - component: PresetInput
            config:
              fields:
                NUM: 50
              name: relativ
              shadow: true
              type: math_number
          - component: PresetInput
            config:
              fields:
                NUM: 15
              name: temp
              shadow: true
              type: math_number
  utilities:
    - component: UtilityFunction
      config:
        code: >
          function {{name}}(rel ,temp) {
            // Block Humidity
            var r = parseFloat(rel);
            var t = parseFloat(temp);
            var mw = 18.016; var gk = 8314.3;     
            var t0 = 273.15; var tk = t + t0;    
            var a, b;     
            if (t >= 0) {
              a = 7.5; b = 237.3;
            } else if (t < 0) {
              a = 7.6; b = 240.7;
            }    
            var sdd = 6.1078 * Math.pow(10, (a*t)/(b+t)); 
            var dd = sdd * (r/100);
            var af = Math.pow(10,5) * mw/gk * dd/tk;    
            var v =  Math.log(dd/6.1078)/ 2.302585092994046;
            var tt = (b*v) / (a-v);
            var tw = -5.809 + 0.058 * r + 0.697 * t + 0.003 * r * t; //kuehlgrenzeEinfach
            return { tt: tt.toFixed(4) + ' °C', af: af.toFixed(4) + ' g/m³', dd: dd.toFixed(4) + ' hPa', tw: tw.toFixed(4) + ' °C'};
          }
        name: fTaupunkt
    - component: UtilityFunction
      config:
        code: >
          function {{name}}(arg, such) {
            if (!arg) return false;
            if (typeof arg === 'object' && arg !== null && !Array.isArray(arg)) {
              return Object.prototype.hasOwnProperty.call(arg, such);
            }
            if (typeof arg.includes === 'function') {
              return arg.includes(such);
            }
            return false;
          }
        name: fFilterBlock
    - component: UtilityFunction
      config:
        code: >
          function {{name}}(itemName, oldTags, newTags) {
            const i = items[itemName];
            const toArray = tags => Array.isArray(tags) ? tags : String(tags).split(',').map(t => t.trim()).filter(Boolean);
            toArray(oldTags).forEach(tag => i.removeTags(tag));
            toArray(newTags).forEach(tag => i.addTags(tag));
          }
        name: fReplaceTags

Beginner with bad English skills. Sorry.
Error messages (and solutions?) Are expressly desired.

2 Likes

I was always jealous of the filter functions in “old school” text codes. With the new blocks from version 0.4, the long route via for_each_Loop should be necessary a little less often.

Example of a rule with humidity sensor as trigger

and

  • the first filter-block can now search not only the children but all descendants.
  • During the milestone-discussion, there was a suggestion to create a block for dipping tags. I stole this idea. :face_in_clouds: The group block, for example, could also be used as a precursor.

the map function is added and because rooms can sometimes appear twice, another block is added to kill duplicates