HabPanel - Switch Dashboard When Media Playing

Hey wonderful openHab users!

I had an idea for a rule and wonered if anyone could point me in the right direction.

Essentially I have 2 different music sources that I use in my house. I use sonos on my main floor, and use an amazon echo for the basement, and outside.

I have a tablet running habpanel on the main floor, and one in the basement.

My plan was to clone each dashboard, but switch the media controls to control to other music source.

I was wondering if it would be possible with a rule to switch dashboards depending on which device is playing audio.

This is my sudo code, and looking for feedback if this would be the best way to implement, or if there is a cleaner way, as I tend to over-engineer rules :wink:

Also not sure if there is a variable for media player of “is playing” rather than recived command “Play”

rule "set dashboard based on media player active upstairs"
when
    Item SonosPlay1KitchenSpeakers_MediaControl received command
then
    
    if( receivedCommand == "PLAY"  ) {

        activepanel.sendCommand(UpperMediaControl)
        
    }

    

end

rule "set dashboard based on media player active basement"
when
    Item BasementEcho_Player received command
then
    
    if( receivedCommand == "PLAY" ) {

        activepanel.sendCommand(LowerMediaControl)
        
    }

    if( receivedCommand == "PAUSE" ) {

        activepanel.sendCommand(UpperMediaControl)
        
    }

end    

Lets me know if I am on the right track or not, or if I didnt explain that well enough please :slight_smile:
Thanks all!

Hey Matt,

I am not sure about the Sonos part since I do not own devices from them.
So I can’t tell you much about recognition of the music source.

But you can definitely switch dashboards from openHAB.
Habpanel uses a string item which you can define in the global setting.
You can then set the string item to a dashboard name.

In your case you would change the item based in your media situation.

Check out the habpanel settings.
I would provide a screenshot, but I am on my mobile phone currently.

1 Like

Thanks for the comments. I figured it out. there were a few different states the player could have so its a little funny looking but fairly simple:

rule "Upper Music Dash"
when
    Item SonosPlay1KitchenSpeakers_MediaControl received command PLAY or Item SonosPlay1KitchenSpeakers_MediaControl changed from PAUSE to PLAY or Item SonosPlay1KitchenSpeakers_State changed from PAUSED_PLAYBACK to PLAYING or Item SonosPlay1KitchenSpeakers_State changed from UNDEF to PLAYING or Item SonosPlay1KitchenSpeakers_MediaControl changed from UNDEF to PLAY
then

    BasementEcho_Player.sendCommand(PAUSE)
    OutsideAndBasement_Player.sendCommand(PAUSE)
    
    if( ActivePanel.state == "LowerMediaControl" ) {
    ActivePanel.postUpdate("Home") 
    }
    

end

rule "Lower Music Dash Dash"
when
    Item BasementEcho_Player received command PLAY or Item BasementEcho_Player changed from PAUSE to PLAY or Item OutsideAndBasement_Player changed from PAUSE to PLAY or Item OutsideAndBasement_Player received command PLAY
then

    SonosPlay1KitchenSpeakers_MediaControl.sendCommand(PAUSE)

    if( ActivePanel.state == "Home" ) {
    ActivePanel.postUpdate("LowerMediaControl") 
    }
    

end
1 Like