Sonos HTTP Api questions

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!
Post Reply
leecollings
Posts: 111
Joined: Tuesday 30 June 2015 18:09
Target OS: Raspberry Pi
Domoticz version: 3.5021
Location: Essex, United Kingdom
Contact:

Sonos HTTP Api questions

Post by leecollings » Tuesday 10 January 2017 2:53

Hi everyone,

So I've just taken a look at the Sonos HTTP API as on https://github.com/jishi/node-sonos-http-api

I have a few questions, that I would just like to hear ideas from other users to get what I want to be able to do.

I would like this sequence of events to happen on the trigger of the doorbell switch:

1. Pause all sonos speakers
2. Play an MP3 file
3. Resume any players that were paused (ignoring any that were paused in the first place)

So I've been able to run individual json requests via HTTP (in a browser window), but I'd like to know how I can incorporate the three events above into a script or blockly (or whatever is best), to run as possible the 'ON' action of the doorbell switch?

kalinkamaen
Posts: 72
Joined: Sunday 04 January 2015 16:57
Target OS: Windows
Domoticz version:
Contact:

Re: Sonos HTTP Api questions

Post by kalinkamaen » Thursday 12 January 2017 14:19

Hello sir.

I can see that not many have given you an answear. This is not an directly answear to your question.
I am doing the exact same thing with my mail box. I am doing this with Eventghost. You can do this
without any script at all with sonos plugin for Eventghost.

leecollings
Posts: 111
Joined: Tuesday 30 June 2015 18:09
Target OS: Raspberry Pi
Domoticz version: 3.5021
Location: Essex, United Kingdom
Contact:

Re: Sonos HTTP Api questions

Post by leecollings » Thursday 12 January 2017 20:06

That doesn't help, and I'm not sure if you're a spam bot or not... firstly I'm not downloading a windows based program for many reasons!

I don't run Windows so that's not helpful. Also, that has no relevance to what I'm asking.


Sent from my iPhone using Tapatalk

leecollings
Posts: 111
Joined: Tuesday 30 June 2015 18:09
Target OS: Raspberry Pi
Domoticz version: 3.5021
Location: Essex, United Kingdom
Contact:

Re: Sonos HTTP Api questions

Post by leecollings » Thursday 12 January 2017 22:07

Anyone got any ideas to help me create a script?


Sent from my iPhone using Tapatalk

ferryversteeg
Posts: 1
Joined: Monday 12 December 2016 10:24
Target OS: Linux
Domoticz version: Stable
Location: Netherlands
Contact:

Re: Sonos HTTP Api questions

Post by ferryversteeg » Saturday 14 January 2017 15:34

Hi,

Using this site: https://github.com/duncan3dc/sonos

I made a php script thats doing what you want for one sonos speaker.
The script below saves the current state, plays the doorbell mp3 and restores the state.

Cheers,

Ferry

-------------------------------
#!/usr/bin/php
<?php

require_once "vendor/autoload.php";
use duncan3dc\Sonos\Network;
use duncan3dc\Sonos\Controller;
$sonos = new Network(new \Doctrine\Common\Cache\ArrayCache);

$controller = $sonos->getControllerByIP("10.1.1.140");
$state = $controller->exportState(true);
$queue = $controller->getQueue();
$queue->clear();
$queue->addTrack("http://10.1.1.14:8080/faralley/doorbell.mp3");
$controller->useQueue();

if ($argc > 1) {
$controller->setVolume($argv[1]);
} else {
$controller->setVolume(10);
}

$controller->play();

while (true) {
sleep(1);
if ($controller->getState() !== Controller::STATE_PLAYING) {
break;
}
}

$controller->restoreState($state);

?>

bsmeding
Posts: 38
Joined: Tuesday 28 October 2014 19:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Sonos HTTP Api questions

Post by bsmeding » Monday 16 January 2017 14:37

If you upload your (doorbell.)mp3 file to the folder : static/clips
then you can create a script to call to these three URLS:
  • curl http://server:port/pauseall/
    curl http://server:port/clipall/doorbell.mp3
    curl http://server:port/resumeall/
so in domoticz/scripts folder create : doorbell.sh
in you doorbell switch create run script and point this to your script : script://home/pi/domoticz/scripts/doorbell.sh

leecollings
Posts: 111
Joined: Tuesday 30 June 2015 18:09
Target OS: Raspberry Pi
Domoticz version: 3.5021
Location: Essex, United Kingdom
Contact:

Re: Sonos HTTP Api questions

Post by leecollings » Thursday 26 January 2017 18:16

Just an update to this, it works out that I was trying to over think it, and that I didn't need two of the calls, as the clipall function pauses and resumes all the speakers anyway.

So just the single URL used in the 'On' action has worked a treat.

In fact, I have used this same thing, and added a pause command to the bedroom speaker when the 'All Off' button of my lightwave mood switch is pressed, which stops the speaker along with turning the lights off.

Post Reply

Who is online

Users browsing this forum: patj71 and 7 guests