Using numerical point (channel) in page layout

Hi there,
When migrating a simple OH2 sitemap (which I could conveniently use in the OH app on my mobile)…

… I thought about building a simple page layout in OH4. I came across the list card which I deemed useful for this use case.

I am now facing an issue while implementing the channel numerical switch (LP1 active [0,1]) into the list.
I thought I can use a toggle list item. But nowhere (in the GUI at least) can I configure what values to use when toggling. The documentation only describes the same config elements which I can find in the GUI. I wonder what the code behind does for toggling? Is it fixed on “ON/OFF”?

In the OH2 sitemap, I used a simple mapping [0=“off”, 1=“on”], but not sure where to put this in the case of a list toggle…

When I use the numerical item, I get an immediate Communication Error popup when toggling the switch. Strangely enough, I don’t get consistent log entries, sometimes I get:

2023-09-04 13:18:55.589 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: undefined

I then (just for testing purposes) configured a slider list item with range 0 to 1 and this works fine but isn’t really what I wanted to use.

When I move the LP1 active slider from 0 to 1, the LP1 active toggle switch also changes to the active position. When moving the slider to 0, this also works (and deactivates the toggle switch). So in a way, as a readout, the toggle button is working, I just don’t seem to be able to actively use it. Any idea what I am doing wrong? Maybe I cannot use a toggle button for a numerical item but then I wonder what else to use for this?

I tried finding forum topics with a similar issue (using a numerical item in a toggle switch) but couldn’t find anything even close to this (which surprises me a bit, I hope I didn’t do a bad job in researching this).

I did find some documentation on using a widget and configuring a button this way, but that would significanlty change the clean list layout which I wanted to aim for. Therefore I would prefer to understand whether it is possible to use a list card for readouts and a suitable switch for a numerical 0,1 item.

  • Platform information:
    • Hardware: Intel Celeron
    • OS: Debian 12 on unraid virtual environment (VM)
    • Java Runtime Environment: OpenJDK Runtime Environment (build 17.0.8+7-Debian-1deb12u1)
    • openHAB version: OH 4.0.2

For the oh-toggle and it’s derivative -card and -item components, yes. There are a few workarounds for this, several would involve having a secondary item which is a switch item but with profiles to convert the switch states to number. However there is a fairly simple entirely UI based workaround.

Any component that can access the OH actions has access to the toggle action which allows you to custom define what two commands get toggled back and forth. In this case all the -item components are based on the oh-list-item basic component and if you look in the docs for that you will find the actions and specifically the toggle action. If you configure the toggle action for the oh-toggle-item then clicking anywhere on that list item will toggle the state of the item back and forth between 1 and 0. The only quirk with this is that the one place you can’t click is on the switch itself, because that click is passed to the toggle and not the overall item.

The config would look something like this:

- component: oh-toggle-item
  config:
    title: Toggle a number item
    action: toggle
    actionCommand: "1"
    actionCommandAlt: "0"
    actionItem: NumberItem
    item: NumberItem
    noChevron: true

*the noChevron property gets rid of the > that appears on the right end of a list item when you add an action

If you want to interact with just the smaller component and are happy with the dual button that you have on your sitemap then that can also be down with just a little more configuration. You’ll have to add button components to the after slot of an oh-list-item. That would look something like this:

- component: oh-list-item
  config:
    title: Toggle a number item
  slots:
    after:
      - component: f7-segmented
        config:
          round: true
          raised: true
        slots:
          default:
            - component: oh-button
              config:
                round: true
                action: command
                actionCommand: "0"
                actionItem: NumberItem
                text: Off
                active: =@@'NumberItem'=="0"
            - component: oh-button
              config:
                round: true
                action: command
                actionCommand: "1"
                actionItem: NumberItem
                text: On
                active: =@@'NumberItem'=="1"