OH3 temperature list widget with dynamic icon color, indoor/outdoor setting and option to show badge

Hi all,

Here’s the code for a custom temperature list item widget that supports different rendering of indoor and outdoor temperatures, with the option to display a badge.

By default the widget will render outdoor temperatures and will use “outdoor grade” temperature intervals. You can change the temperature intervals by setting the “Indoor” parameter to true.

The temperatures have been defined in centigrade (°C):

Temperature range name Outdoor Indoor Color
hot >30°C >25°C red
warm 25 - 30°C 22 - 25°C orange
normal 15 - 25°C 18 - 22°C green
cool 10 - 15°C 16 - 18°C blue
cold 0-10°C 0 - 16°C blue
freezing <0°C <0°C purple

Code

uid: temperature_list
tags:
  - list
  - temperature
props:
  parameters:
    - description: Widget title
      label: Title
      name: title
      required: false
      type: TEXT
    - context: item
      description: Temperature item to display
      label: Item
      name: item
      required: true
      type: TEXT
    - defaultValue: 'false'
      description: Indoor temperature
      label: Indoor
      name: indoor
      required: false
      type: BOOLEAN
    - description: Show badge instead of temperature
      label: Show badge
      name: showBadge
      required: false
      type: BOOLEAN
  parameterGroups: []
timestamp: 'Jun 12, 2021, 10:09:30 AM'
component: oh-label-item
config:
  icon: 'f7:thermometer'
  iconColor: >-
    =(!Number.isFinite(Number.parseFloat(items[props.item].state))) ? "gray" :
    (Number.parseFloat(items[props.item].state) > (props.indoor ? 25 : 30)) ?
    "red" : (Number.parseFloat(items[props.item].state) > (props.indoor ? 22 :
    25)) ? "orange" : (Number.parseFloat(items[props.item].state) >
    (props.indoor ? 18 : 15)) ? "green" :
    (Number.parseFloat(items[props.item].state) > 0) ? "blue" : "purple"
  title: =props.title
  item: =props.item
  action: analyzer
  actionAnalyzerCoordSystem: time
  actionAnalyzerItems: '=[props.item]'
  badgeColor: >-
    =(!Number.isFinite(Number.parseFloat(items[props.item].state))) ? "gray" :
    (Number.parseFloat(items[props.item].state) > (props.indoor ? 25 : 30)) ?
    "red" : (Number.parseFloat(items[props.item].state) > (props.indoor ? 22 :
    25)) ? "orange" : (Number.parseFloat(items[props.item].state) >
    (props.indoor ? 18 : 15)) ? "green" :
    (Number.parseFloat(items[props.item].state) > 0) ? "blue" : "purple"
  badge: >-
    =(!showBadge) ? "" : 
    (!Number.isFinite(Number.parseFloat(items[props.item].state))) ? "error" :
    (Number.parseFloat(items[props.item].state) > (props.indoor ? 25 : 30)) ?
    "hot" : (Number.parseFloat(items[props.item].state) > (props.indoor ? 22 :
    25)) ? "warm" : (Number.parseFloat(items[props.item].state) > (props.indoor
    ? 18 : 15)) ? "normal" : (Number.parseFloat(items[props.item].state) >
    (props.indoor ? 16 : 10)) ? "cool" :
    (Number.parseFloat(items[props.item].state) > 0) ? "cold" : "freezing"

Unfortunately there’s no support yet for defaultValue parameter settings in openHAB3.0.2. By default both BOOLEAN parameters have been defined so that they read false when undefined.

It appears that defaultValue for widget parameters might be supported soon:

Have fun!

3 Likes

Hi,
really great & helpful widget. Somehow I can only insert one item.
Can you tell me how to add multiple ones?

Or do I have to insert the widget multiple times?

Thanks
Stigg