Tag Archives: intertechno

HowTo: FHEM: Remote Control a SONOS Speaker with an Intertechno Remote

If you have a Sonos Loudspeaker, you know that you have to control them with your smartphone or tablet. But sometimes I don’t want to get my phone out to do some basic tasks like play/pause, volume up/down or next/previous track. I had an Intertechno Remote as leftover lying around and decided to use it as an remote control for my Sonos Play:1.
A prerequisite for this is, that you have already defined your Sonos Play:1 in FHEM and are able to fully control it. Because i found it very practically i decided to share the script with you.

I defined the buttons with their name staring the same and appended the row number at the end.

IT_Remote FHEM
IT_Remote FHEM

Then I wrote this script to control my Sonos Play:1:

define ny_IT_Remote1 notify IT_Remote1.* {
 my $r1 = "_1";
 my $r2 = "_2";
 my $r3 = "_3";
 my $r4 = "_4";
 my $dev = "[YOUR SONOS DEVICE]";
 my $sleepincr = 900;
 my $sleeptimer;
 my @sleeparray;
 my $sleepseconds;
 my $row = substr($NAME,-2);
 if ($row eq $r1) {
  if ($EVENT eq "off") {
   fhem("set " . $dev . " VolumeU");
  } else {
   fhem("set " . $dev . " VolumeD");
  }
 } elsif ($row eq $r2) {
  if ($EVENT eq "off") {
   fhem("set " . $dev . " Next");
  } else {
   fhem("set " . $dev . " Previous");
  }
 } elsif ($row eq $r3) {
  if ($EVENT eq "off") {
   $sleeptimer = ReadingsVal($dev,"SleepTimer","off");
   if ($sleeptimer ne "off") {
    @sleeparray = split /:/, $sleeptimer;
    $sleepseconds = int($sleeparray[0]) * 3600 + int($sleeparray[1]) * 60 + int($sleeparray[2]) + $sleepincr;
   } else {
    $sleepseconds = $sleepincr;
   }
   fhem("set " . $dev . " SleepTimer +" . $sleepseconds);
   fhem("set " . $dev . " speak +0 en Sleeptimer is set to " . int($sleepseconds / 60) . " minutes");
  } else {
   fhem("set " . $dev . " SleepTimer off");
   fhem("set " . $dev . " speak +0 en Sleeptimer disabled");
  }
 } elsif ($row eq $r4) {
  if (ReadingsVal($dev,"transportState","PLAYING") eq "PLAYING") {
   fhem("set " . $dev . " Pause");
  } else {
   fhem("set " . $dev . " Play");
  }
 }
}

This means, that i use the first row of buttons to change the volume, the second one to skip to the previous/next song and the “ALL OFF”-Button for play/pause. Also, I use the third row to set the sleep timer, the left one to turn the sleep timer off and the right one to increase it for 900($sleepincr) seconds. I like to know if the sleep timer was set correctly, so I use sonosspeak to let the speaker tell me the minutes left on the sleep timer.