Help with Dynamic Volume Source Selection in Widget

Hi everyone,

I’ve created a widget to control the volume for different audio sources (e.g., media, ringtone, alarm, system), where I’d like to select the volume source dynamically using a variable. However, I keep encountering an undefined error when I try to set the source variable.

Here’s my current code:

uid: audio_volume_control_widget
tags: []
props:
  parameters:
    - context: item
      label: Media Volume Item
      name: mediaVolumeItem
      required: false
      type: TEXT
    - context: item
      label: Ringtone Volume Item
      name: ringtoneVolumeItem
      required: false
      type: TEXT
    - context: item
      label: Alarm Volume Item
      name: alarmVolumeItem
      required: false
      type: TEXT
    - context: item
      label: System Volume Item
      name: systemVolumeItem
      required: false
      type: TEXT
component: f7-card
config:
  title: Volume Control
slots:
  default:
    - component: oh-list-item
      config:
        title: Select Audio Source
        action: options
        actionOptions: media, ringtone, alarm, system
        actionVariable: selectedSource
    - component: oh-slider
      config:
        label: Volume
        min: 0
        max: 100
        step: 1
        unit: "%"
        item: "=vars.selectedSource === 'media' ? props.mediaVolumeItem :
          vars.selectedSource === 'ringtone' ? props.ringtoneVolumeItem :
          vars.selectedSource === 'alarm' ? props.alarmVolumeItem :
          vars.selectedSource === 'system' ? props.systemVolumeItem : ''"

Issue:
The vars.selectedSource variable seems to be undefined when I try to change it, which causes the slider element not to have a valid item to control.

Question:
Does anyone have ideas on how to correctly set the selectedSource variable or handle the undefined error to make the slider work correctly? Or is there a better way to set up the source selection?

Thanks a lot in advance for any help!

I don’t believe the options action works with variables. As far as I know it only works with items.

Unfortunately, there’s no shortcut here. If you want to set a variable to a list of options, and you want that to look like the default OH action sheet you’re going to have to build that action sheet yourself. There’s a small example in this recent thread: