Need help copying "level" in a piston


1) Give a description of the problem
(I’d like to copy the “level” from a virtual dimmer switch and copy it to the level of an actual device)

2) What is the expected behaviour?
(When I adjust the level on the virtual dimmer the piston copies that level to an actual different device. I’m creating the virtual dimmer since the actual Device Handler does not show up in Action Tiles. I have to creat a virtual device to show up in action tiles so I can control the amp.)

3) What is happening/not happening?
(nothing right now)

4) Post a Green Snapshot of the pistonimage


5) Attach logs after turning logging level to Full

If a solution is found for your question then please mark the post as the solution.


From reading your post, it sounds like you want:

Dimmer 1 changing to on = Turn on Music
Dimmer 1 changing to off = Turn off Music
Dimmer 1 changing levels = Change volume

Am I right?


Hi WCmore. That is correct. I have the ‘on’ and ‘off’ working fine. I just don’t know how to get the Dimmer 1 levels to change volume on Music Player 2.



I would create a new piston that only monitors the level of the Simulated Dimmer.
(the highlighted code below is entirely optional)

A couple of important notes:
There is a one second buffer in the piston above, so the best strategy is to make a change to the SimDim’s level, and then stall a second while it syncs. If you need more or less volume, then repeat. (it will not be instant like a real volume dial)

Also, the synchronization only goes in one direction. The Amp will align with the SimDimmer, but the SimDimmer will not change if you manually adjust your Amp’s volume.


I think I got it.

So if I change the Dimmer 1 level manually then this piston will wait 1 second for me to finish adjusting and then carry over that adjustment to the “Music Player’s” Volume control.

Do the ranges for each “dimmer level” need to be the same? I think the music players volume level’s range is 0-37. I’m not sure how to adjust the range in the virtual dimmer switch (Dimmer 1)

It’s ok that it’s one way. I’ll only be making adjustments to this amp through ST or Alexa and I’m ok with it being on direction.

Thanks for the help on this. This is great. I’ll try it out

On a side note, on a Google search it looks like you helped someone else out with the same issue as me. I’m trying to do the exact same thing. Would this piston work for my use as well?


Yes, perfect description.

In other words, whatever level the SimDim is on at the end of the one second, will be the level that will be set on your Amp.

You can either:
(A) Only use SimDim’ level 1-37
— or—
(B) Do a math conversion so level 100 = volume 37 (for example)

If you want to go route (B), I can help with the math conversion if you can tell me for sure what your min & max volumes are for your Amp. (also, integers or decimals?)


From what I can tell from the Amps Device Hander, the zone volume has a range of 00-38

  • Zone Volume level (00 - 38)

I do not know what the actual range is on the amp. I’d have to dig into that. If the Piston is doing the match for percentages based on range then I suppose it might translate but it seems to make sense to make both level ranges the same for the virtual dimmer and the device handler.

It would be great to make the virtual device range 00-38 but i’m at loss for doing that.

Making 100=38 would work I suppose. Thanks for the help with all this.


Good point. To do a proper conversion we only need the min/max for the device handler.
(plus knowing if it accepts decimals, or must it be entirely integers)


Here’s the entire section for volume control in the DH.


  • Zone Volume level (00 - 38)
    if (evt.containsKey(“volume”)) {
    log.debug “setting volume to ${volume - 1}”
    sendEvent(name: “volume”, value: evt.volume)

And here’s the DH section for the design description.

// Row 1
controlTile(“volume”, “device.volume”, “slider”, height: 1, width: 6, range:"(0…38)") {
state “volume”, label: “Volume”, action:“music Player.setLevel”, backgroundColor:"#00a0dc"

So it looks like the Amps DH wants a range or 00-38. The Amps range is definitely 00-38 so that makes sense.

So how would one translate the dimmers 00-99 range to the DH 00-38 range without a lot of math?

Keep in mind, I’m not using a custom DH for the virtual dimmer. It’s the ST stock virtual dimmer


It’s gonna take math. I am working on it now, although I am doing it for 1-99%, not zero. To turn it off, you should use the switch, (other piston) and not a level 0.

Be back in a few


I really need to know if it will accept a decimal command though before I can share this with you. The coding will be quite different based on your answer.

Try a test command to the Amp:

Set level to 12.9
and confirm if it worked or not


Thanks. I’m wondering if even matters since the piston is translating the number value of the volume slider 00-99 to a percentage. Therefore. if I make the virtual dimmer 50, the piston sees that as 50% and then tells the amp DH to adjust volume to 50% within that DH handler range of 00-38. Which would be 19. Therefore, in the DH/Amp world, that would be half the volume. Does that makes sense?

I can test this when I’m home and can see the commands it sends to the amp. I’ll slide the virtual dimmer to a number and see what the piston does and how that translates to the amp. The amp cannot take decimals. Only whole numbers between 00-38. It’s taking ASCII commands over serial. That’s a whole different scenario I won’t get into.


Cool… IF a webCoRE command:
Set Amp volume to 50
actually makes the volume 19, then no additional math will be required

I will put my partial math on the back burner for now until you have time to confirm.


On the “volume=0” thing, you could put an additional test in the piston that says If the volume=0, then with Music Player turn Off. Of course, it would probably retain the volume so you wouldn’t hear anything when you turn it back on :frowning:


That’s the thing though… He already has a turn on and off piston… In addition, often a “Set level to 0” is not seen as a level change. It is often seen as an off command, thereby activating the other piston.

The same applies to 100%… It is usually not seen as a level change.

Because of this, when it comes to changing levels as a trigger, I only program for 1-99


My preliminary math is working good, should you need it…


The first number is the Amp volume, the last number is the Dimmer level


Ok. So I have some info. The value sent to the receiver is the actual value on the Dimmer Value. So if I set the slider to 19, that sets the volume level on the amp to 19. Which means that any number above 38 on the virtual dimmer slider will send a max volume level to the receiver. That’s dangerous! So, it looks like I either have to
A. Use a custom device handler for the virtual dimmer that designates the slider value to be from 00-38 or
B. Work some math magic to translate the virtual dimmer numbers to Amp DH numbers.

What do you think?


“Math magic” is the way to go! I already have a test piston ready for you:

Sample results are shown in my last post

With this piston, you can set the level to an intuitive number, so for example, 50% on the SimDimmer would set the Amp volume to 19

(approx 5% on the Dimmer = 2 notches on the volume)


Wow! That’s amazing. I will implement and report back. Thanks for this. Really appreciate it. Have to say, this kind of feedback and help really makes WebCoring fun.


Glad to be able to help. Don’t forget the short pause between tests