Hey everyone,
A little while back I did a proof of concept video on integrating Sonos with Vera (here if you’re interested: Sonos and Home Automation using Vera - YouTube). I had a couple of people ask for a video on how to set it all up so, here it is if you’re interested: Configuring and Automating the Vera Sonos App (How To) - YouTube
I basically walk through how to set up the app and after the setup is complete I walk through a couple of different ways to automate. They are:
- Play a Sonos Favorite when a door is unlocked
- Add a Sonos to a group that is already playing when motion is detected in a room. This has the effect of playing music that is already playing on another Sonos just by walking into a room.
- Saying the weather when I walk into the kitchen every morning
I have attached the PLEG conditions I used if you’re interested and here is the LUUP Code I used for the weather announcement (compiled from this awesome thread: http://forum.micasaverde.com/index.php/topic,12408.0.html):
[code]–Make sure to update the code to work with your environment. Notes are below.
url = require(“socket.url”)
local t = os.date(‘*t’)
local AV_DEV = 178 --ID of Sonos Plugin
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
local TEMP_SID = “urn:upnp-org:serviceId:TemperatureSensor1” --Used for my outdoor thermometer
local WUNDER_SID = “urn:upnp-micasaverde-com:serviceId:Weather1” --Wunderground plugin
local outsideTemp = luup.variable_get(TEMP_SID,“CurrentTemperature”, 58) --Numbers are the Device #. You will need to change to your device
local highTemp = luup.variable_get(WUNDER_SID,“Forecast.0.HighTemperature”, 45)
local lowTemp = luup.variable_get(WUNDER_SID,“Forecast.0.LowTemperature”, 45)
local weatherCondition = luup.variable_get(WUNDER_SID,“Forecast.0.Condition”, 45)
local weatherPrecip = luup.variable_get(WUNDER_SID,“Forecast.0.POP”, 45)
local weatherRainDay = luup.variable_get(WUNDER_SID,“Forecast.0.QPFDay”, 45)
local weatherRainNight = luup.variable_get(WUNDER_SID,“Forecast.0.QPFNight”, 45)
local weatherSnowDay = luup.variable_get(WUNDER_SID,“Forecast.0.SnowDay”, 45)
local weatherSnowNight = luup.variable_get(WUNDER_SID,“Forecast.0.SnowNight”, 45)
weatherPrecip = tonumber(weatherPrecip)
weatherRainDay = tonumber(weatherRainDay)
weatherRainNight = tonumber(weatherRainNight)
weatherSnowDay = tonumber(weatherSnowDay)
weatherSnowNight = tonumber(weatherSnowNight)
local precip = “”
local current_second = t.hour * 3600 + t.min * 60 – number of sec since midnight
local morning = 0 * 3600 + 0 * 60 – 00:00
local afternoon = 12 * 3600 + 0 * 60 – 12:00
local evening = 18 * 3600 + 0 * 60 – 18:00
local timeOfDay = “”
if (current_second > morning and current_second < afternoon) then
timeOfDay = "Good Morning! "
else
if (current_second > afternoon) and (current_second < evening) then
timeOfDay = "Good Afternoon! "
else
timeOfDay = "Good Evening! "
end
end
–precipitation
if (weatherPrecip == 0) then
precip = “There is no precipitation forecast”
else
precip = “There is a " …weatherPrecip …” percent chance of precipitation"
if (weatherRainDay > 0) then
precip = precip … " with " …weatherRainDay …" inches of rain"
if(weatherSnowDay > 0) then
precip = precip … " and " … weatherSnowDay … " inches of snow"
end
precip = precip … " during the day"
else
if(weatherSnowDay > 0) then
precip = precip … " with " …weatherSnowDay …" inches of snow during the day"
end
end
–NIGHT
if (weatherRainNight > 0) then
if(weatherRainDay > 0 or weatherSnowDay > 0) then
precip = precip … " and"
end
precip = precip … " with " …weatherRainNight …" inches of rain"
if(weatherSnowNight > 0) then
precip = precip … " and " … weatherSnowNight … " inches of snow"
end
precip = precip … " during the night"
else
if(weatherSnowNight > 0) then
if(weatherRainDay > 0 or weatherSnowDay > 0) then
precip = precip … " and"
end
precip = precip … " with " …weatherSnowNight …" inches of snow during the night"
end
end
end
–print(precip)
luup.call_action(LS_SID, “Say”, {Text = string.format(“%s It is currently %s degrees outside. It is forecast to be %s with a high temperature of %s and a low of %s. %s”, timeOfDay, outsideTemp, weatherCondition, highTemp, lowTemp, precip), Language=“en”, Volume=40}, AV_DEV)
[/code]