Need help with luup for SONOS-morning rutine.

Jens, thanxs for the explanation it would help if one (me) would look a little harder ::slight_smile: Yea I realized my error whilst doing google translate (Danish vs Dutch ) and made the corrected in my original post. Mike

There are two improvements that can be done. I will look into it later tonight or tomorrow.

  1. A procedure can be made with the if’s so I dont have to dublicate them.
  2. The current temperature like 6.7 is “translated” to 6 7 when used by the TTS.
    I have found the solution in this post http://forum.micasaverde.com/index.php/topic,48324.0.html
    I just need to implement it.

I will post an update when I have made it.

Best regards,
Jens

Hi.
Now with a updated version

  1. Function for making the temperature with no decimal
  2. Function for the if’s
  3. Removed the dual “fog”
local AV_DEV =55 -- Sonos Device ID within Vera
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local LS_ZONES ="All" -- Valid GroupZones = "All", "Kitchen", "Patio", "Living Room", "Master Bedroom"
local WEATHER_ID = 34
local WEATHER_SID = "urn:upnp-micasaverde-com:serviceId:Weather1"
local TEMP_ID = 35
local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"

local time = os.date('klokken er %H:%M.')
local weatherCurrCondition = luup.variable_get(WEATHER_SID, "Condition", WEATHER_ID)
local weatherForecast           = luup.variable_get(WEATHER_SID, "Forecast.0.Condition", WEATHER_ID)
local weatherLow                  = luup.variable_get(WEATHER_SID, "Forecast.0.LowTemperature", WEATHER_ID)
local weatherHigh                 = luup.variable_get(WEATHER_SID, "Forecast.0.HighTemperature", WEATHER_ID)
local outsideTemp = luup.variable_get(TEMP_SID, "CurrentTemperature", TEMP_ID)

local function convertTextInteger(val)
    return (("%+0.0f"): format (val): gsub("^.", "%1 "))
end

local function translateCondition(Condition)
	if (Condition=="Partly Cloudy") then
		Condition="Delvist overskyet"
	elseif (Condition=="Clear") then
		Condition="klart vejr"
	elseif  (Condition=="Partly Sunny")  then
		Condition="delvist solrigt"
	elseif  (Condition=="Rain") then
		Condition="regnvejr"
	elseif  (Condition=="Cloudy") then
		Condition="overskyet"	
	elseif  (Condition=="Flurries") then
		Condition="Snevejr"		
	elseif  (Condition=="Fog") then
		Condition="t?get"
	elseif  (Condition=="Sunny") then
		Condition="Solskind"
	elseif  (Condition=="Mostly Cloudy") then
		Condition="Mest overskyet"
	end
	return Condition
end

outsideTemp=convertTextInteger(outsideTemp)

local hour=tonumber(os.date('%H'))
local greeting=""
if  hour < 12  then
    greeting = "God morgen"
elseif hour < 17 then
    greeting = "God dag"
elseif hour < 21 then
    greeting = "God aften"
else
    greeting = "Goo nat"
end

weatherCurrCondition=translateCondition(weatherCurrCondition)
weatherForecast=translateCondition(weatherForecast)

local weather1 = "Det aktuelle vejr er " .. weatherCurrCondition .. ". Temperaturen er " .. outsideTemp .. "grader"
local weather2 = "Vejret i dag bliver" ..  weatherForecast .. ".Temperaturen bliver mellem " .. weatherLow  .. " og " .. weatherHigh .."grader"

	
luup.call_action(LS_SID, "Say", {Text= greeting .. ". " .. time .. weather1, Language="da", Volume=30}, AV_DEV)
luup.call_action(LS_SID, "Say", {Text= weather2, Language="da", Volume=30}, AV_DEV)

Jens, That was quick…

I attempted to run your latest by changing the AV_DEV, Weather_ID and TEMP_ID values to reflect mine. when I run the LUA I can see the command being issued (via PLEG) but no sound or error being reported when I run your LUA. I have verified that I’m able to get TTS sounds through the specific SONOS speaker via testing with another working LUA code.

What version of Firmware and GUI are you using? I’m using Edge with GUI UI7, version 1.7.2607, Mike

[glow=red,2,300]PS[/glow] fix in your greeting “Goo nat” to “God nat” I think your having it say Good Night?

Like any “good” developer will say… It works on my machine :slight_smile:

I’m running UI7 1.7.2608

I dont think its that. I have seen this before I think it when one of the variables are empty. I don’t know anything about PLEG so I cant help you there.
Try run in here Apps->Develop Apps->Test Luup Code (LUA) that way we can rule out PLEG.

Be aware that the WeatherID and the TEMP_ID is two different devices. I think you already have figured that out but just to be sure.

If it still not working I would put in a say command different places in the code to see where it fails. It may not be the best way to debug code but its the only way I know :slight_smile:

Best regards,
Jens

Well I took the LUA snipit and ran via the Apps->Develop Apps->Test Luup Code (LUA) and received the following;
“Success, Code sent successfully.” but I’ve had this kind of results in the past where the Test Luup Code route doesn’t flag everything.

WeatherID and the TEMP_ID is two different devices. I assigned the parent World Weather Device ID in my case #5 to WeatherID and World Weather Child Device ID in my case #6 to TEMP_ID which is the same as my original LUA snipit.

You make note of the empty variables which ones are your referring to?