Sonos volume + and - button Habpanel

Hi,

I want to create a + and - button in Habpanel beside the volume slider for my sonos playbar.

The playbar is added by automatic discovery, I have a dimmer linked to an item for the volume:
SonosPlaybarLivingRoom_Volume

For the Habpanel I made a item to use as a trigger switch for the buttons, so for the + button I made:
SonosPlaybarLivingRoom_Volume_up

I found a rule in another topic who tried to get the same result: Sonos volume increase/decrease rule? [SOLVED]

So I copied > paste that rule and filled out my items, but the only thing that is happening is that the volume get set to 1, this is the log:
2019-11-15 22:33:10.287 [ome.event.ItemCommandEvent] - Item ‘SonosPlaybarLivingRoom_Volume’ received command 1
2019-11-15 22:33:10.292 [nt.ItemStatePredictedEvent] - SonosPlaybarLivingRoom_Volume predicted to become 1

And this is the rule I use:

rule "Sonos volume plus en min"
when
Item SonosPlaybarLivingRoom_Volume_up received command ON
then
var Number V = SonosPlaybarLivingRoom_Volume.state as DecimalType
var Number H = V + 1
if (H>65) H = 65
    postUpdate(SonosPlaybarLivingRoom_Volume, H)
    sendCommand(SonosPlaybarLivingRoom_Volume, H)
end

For some reason the var Number .state from the volume item don’t seem to get stored, any ideas?

Nobody have any idea…? :frowning:

Hello,

got this working with the following code:

rule "Sonos Volume Up"
when
    Item Sonos_Volume_Up received command ON
then
    var Number v = Sonos_Volume.state as Number
    var Number h = v + 1
    if(h > 50) h = 50
    Sonos_Volume.sendCommand(h)
end

Janne

Hi Janne,

Thanks, I will try that rule as well and le you now :wink:
I assume you used the same script for the minus button but then with line: “var Number h = v - 1”
Right?

Hello,

yes, you need to change that line and also “if(h > 50) h = 50” needs to be changed to “if(h < 0) h = 0”

Janne

Thanks Janne, exactly what I was looking for :slight_smile:
I only changed one thing:

rule "Sonos Volume Up"
when
    Item SonosPlaybarLivingRoom_Volume_up changed
then
    var Number v = SonosPlaybarLivingRoom_Volume.state as Number
    var Number h = v + 1
    if(h > 50) h = 50
    SonosPlaybarLivingRoom_Volume.sendCommand(h)
end

Because I use an switch item, the switch in my habpanel first switches to off, then to on, so otherwise I have to click twice to increase the volume by 1, or is there even a beter solution?

Just wondering? :slight_smile: