Site map ,slider control for PC Volume

Hi

trying to understand how can i use a slider for exec commands please see beelow commands
how can i set a slider item to control this two?

Thing exec:command:PCVOL_UP [command=“nircmd.exe changesysvolume +5000” ,transform=“REGEX((.*?))”, interval=0, autorun=true,timeout=50 ]

Thing exec:command:PCVOL_DOWN [command=“nircmd.exe changesysvolume -5000” ,transform=“REGEX((.*?))”, interval=0, autorun=true,timeout=50 ]

i also have the optin to send this command
maybe it will better?
nircmd.exe setsysvolume 65535

This is one of the limitations of the Exec2 binding. I think there is an issue open to address it.

The Input and Output channels can only be linked to String Items.

The Slider element only works with Number Items (or other Items that can accept a Number as a command like Dimmer).

So you can’t directly control an Item linked to the Input or Output channel of an Exec2 thing.

Furthermore, a Slider implies an absolute volume level. If I put the slider to the middle, I expect the volume to be at 50% of the max volume. But your commands are all relative. So if you moved the slider up to 75% your volume would only go up by 5000. Eventually the range of volume that the Slider will control will narrow to the point of uselessness.

So you have two choices. You can abandon the use of the Slider and use an Up Down button (i.e. a Switch with a Mapping) or you can send absolute volume values.

The ending of your OP indicates you can send absolute values so let’s do that that.

First of all, you need only one Thing.

Thing exec:command:PCVOL [command="nircmd.exe setsysvolume %2$s, autorun=true ]

Per the docs the %2$s will be replaced with the state of the Item linked to the Input Channel.

Now you need two Items, a Dimmer Item to represent the volume and a String Item linked to the Input channel of PCVOL.

Dimmer PC_Volume "PC Volume"
String PC_Volume_Control { channel="exec:command:PCVOL:input" }

PC_Volume is a Design Pattern: Proxy Item and it the Item you will put on your sitemap and use elsewhere in your OH config to know what volume the PC is set to.

PC_Volume_Control is the Item you will sendCommand to cause the program to run.

Now you need a Rule to take the percent value that PC_Volume will get set to an absolute value to send as the argument to the executable.

rule "PC Volume"
when
    Item PC_Volume changed
then
    val maxVol = 100000 // whatever the max volume value is
    PC_Volume_Control.sendCommand((maxVol / PC_Volume.state as Numer).intValue)
end

But you have one remaining problem. What happens when OH restarts or your machine restarts? All your Items get reset to NULL (i.e. uninitialized) which means that your PC_Volume Item will no longer know what volume your PC is currently set to.

Is there an argument you can pass to nircmd.exe to get the current system volume?

If not you will run into some problems.

wow give me a few days :slight_smile:
i will try this!

what about seeting the input alwys to 50% when openhab starts and than both will be synced

ok i tried it but nothing and as you said… it will not solve all issues
so i will go with up and down

how can i do it with Element Type ‘Setpoint’?
i guess it will be as above but i am not sure what to put in the site map

Items
Dimmer PC_Volume “PC Volume”
String PC_Volume_Control { channel=“exec:command:PCVOL:input” }

Things
Thing exec:command:PCVOL [command=“nircmd.exe changesysvolume %2$” ,transform=“REGEX((.*?))”, interval=0, autorun=true,timeout=50 ]

Rules
rule “PC Volume”
when
Item PC_Volume changed
then
val maxVol = 65535 // whatever the max volume value is
PC_Volume_Control.sendCommand((maxVol / PC_Volume.state as Numer).intValue)
end

Sitemap

Setpoint item=PC_Volume  label= "Dimtest"

Error 21:25:40.205 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘PC Volume’: void

SetPoint will have the same problems as Slider. Using it buys you nothing.

The error is probably caused by PC_Volume not having a state. Add a System started rule to initialize it to 0 or something appropriate.