Openhab ventilation widget

Hi,
Currently I am working on my first widget related to my centralized ventilation system.
Could anybody help me with the following, please?

- component: oh-button
            config:
              visible: "=props.set_pump_item ? true : false"
              iconF7: arrow_up_circle
              iconSize: 35
              action: command
              actionItem: =props.set_pump_item
              actionCommand: =Math.min(Number(items[props.set_pump_item].state.split(' ')[0]) + 5, 100)
              style:
                position: absolute
                color: "#175B88"
                top: 166px
                left: 312px
                height: 35px
                background: transparent
          - component: oh-button
            config:
              visible: "=props.set_pump_item ? true : false"
              iconF7: arrow_down_circle
              iconSize: 35
              action: command
              actionItem: =props.set_pump_item
              actionCommand: =Math.max(Number(items[props.set_pump_item].state.split(' ')[0]) - 5, 0)
              style:
                position: absolute
                color: "#175B88"
                top: 166px
                left: 225px
                height: 35px
                background: transparent
          - component: f7-col
            config:
              class:
                - display-flex
                - flex-direction-column
                - align-items-right
                - fixed-width
            slots:
              default:
                - component: oh-link
                  config:
                    visible: "=props.set_pump_item ? true : false"
                    text: =items[props.set_pump_item].state
                    style:
                      color: "#175B88"
                      font-size: 30px
                      left: 266px
                      top: 40px

I do have 2 buttons here and a number. Something like a stepper card. The first button is the arrow up (works fine). The second button is the arrow down to decrement the set values by 5 with the lowest value of 0. The problem is, that it does not go to 0.
Does anybody have an idea what could be wrong?

This is a subtle problem. The integer 0 is one of the falsy values, which means it can be interpreted as false. A false value for any of the yaml properties means that property is ignored. So, when your actionCommand equals 0, that property is actually ignored and the button is sending no command at all!

Fortunately, you don’t have to send the integer 0 as the command you can send the string '0' just as effectively. So, the workaround here is to make sure that if the math ever equals 0 that the expression returns a string of the character '0' instead of the number. My preferred method here would be an OR statement:

actionCommand: =Math.max(Number(items[props.set_pump_item].state.split(' ')[0]) - 5, 0) || '0'

But, just always converting the result of expression to a string works as well:

actionCommand: =Math.max(Number(items[props.set_pump_item].state.split(' ')[0]) - 5, 0).toString()

thank you

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.