Page 1 of 4

Vocal announcement - Good Morning Script

Posted: Sunday 06 March 2016 22:32
by jmleglise
EDIT : 7/3/2016. Minor changes in the script

Hi,

Just for fun, this is a piece of code to let Domoticz wake up the house.

I use VoiceRSS web service. (I have updated the wiki https://www.domoticz.com/wiki/Talking_D ... spBerry_Pi)

I trigger it when the first motion sensor goes ON.

It includes :
- Temperature sensor
- Weather Alert
- Weather Forecast for the day
- Trash day (A mess between Vegetables, glass, recycling, bulky waste / odd and even week ...)

And you ? What is your GoodMorning Script ?

Code: Select all


indexCommand=1
commandArray = {}

local timeNow= os.date("*t")

if devicechanged['Motion Salon'] == 'On' and --Motion sensor Living Room     ManualLaunchScript
	timeNow.hour >6   and
	string.sub(uservariables_lastupdate['goodMorning'], 9, 10) ~= os.date("%d") -- Only one time per day
then
	local sentence="Bonjour, nous sommes aujourd'hui le "..tonumber(os.date("%d"))  -- Good morning, today we are the ..
	
-- #############  TEMPERATURE & WEATHER FORECAST  #################	
	sentence=sentence..". La température extérieure est de "..otherdevices_svalues['Sonde Solaire2'].." degré." -- outdoor temperature 

	json = (loadfile "/home/pi/domoticz/scripts/lua/json.lua")() 
	local city = "Paris"
	local wuAPIkey = "xxxx" -- Your Weather Underground API Key
	local file=assert(io.popen('curl http://api.wunderground.com/api/'..wuAPIkey..'/forecast/lang:FR/q/France/'..city..'.json'))   
	local raw = file:read('*all')
	file:close()	
	local jsonForecast = json:decode(raw)	
	prevision=jsonForecast.forecast.txt_forecast.forecastday[1].fcttext_metric  -- complete prevision
	--prevision=jsonForecast.forecast.simpleforecast.forecastday[1].conditions  -- small forecast 

	if tonumber(string.sub(otherdevices_svalues['Alerte Meteo'], 1, 1))==3 then -- Only for FRANCE. Weather Vigilance  http://domogeek.entropialux.com/static/doc/index.html#api-Domogeek-GetVigilance
		sentence=sentence.."La météo est en vigilance orange :".. string.sub(otherdevices_svalues['Alerte Meteo'], 11) 
	elseif tonumber(string.sub(otherdevices_svalues['Alerte Meteo'], 1, 1))==4 then 
		sentence=sentence.."La météo est en vigilance rouge :".. string.sub(otherdevices_svalues['Alerte Meteo'], 11)  
	end
	sentence=sentence.."Le temps de la journée sera "..prevision

-- #############  TRASH DAY #################
	month=tonumber(os.date("%m"))
	day=tonumber(os.date("%d"))

-- TRash day : Mardi vegetaux & ordure / jeudi recyclage &  encombrant (pair) ou  verre (impair) / samedi ordure

	numOfWeek=tonumber(os.date("%V"))
	numOfDay=os.date("%w")

	if (numOfDay == '4')  then -- thursday

	if (numOfWeek % 2 ==0)  then
		sentence=sentence.."Les encombrants et la poubelle jaune sont rammassés ce matin."  --pair
	else 
		sentence=sentence.."Le verre et la poubelle jaune sont rammassés ce matin."  --impair
	end

	elseif (numOfDay == '2')  then -- Tuesday
	if 	(month==3 and day>=15) or -- Vegetables trash between the 15 March and the 15 december
		(month==12 and day<=15) or 
		(month>3 and month<12)
	then   
		sentence=sentence.."Les vegetaux et "
	end
	sentence=sentence.."les poubelles sont ramassées ce matin."
	elseif (numOfDay == '6')  then -- Saturday
		sentence=sentence.."les poubelles sont ramassées ce matin."
	end

    --print("talk:"..sentence)

	os.execute ("/usr/bin/tts "..sentence.." &")	
	
	commandArray[indexCommand]={['Variable:goodMorning']="On"}  -- something to update "lastupdate"
	indexCommand=indexCommand+1
	
end
return commandArray


Re: Vocal announcement - Good Morning Script

Posted: Monday 07 March 2016 21:18
by georgesattali
Thanks for your funny script - It's so unfair I 'll have to buy a motion sensor now :D
merci jm.

Re: Vocal announcement - Good Morning Script

Posted: Monday 07 March 2016 22:56
by jmleglise
I have this one : http://www.aliexpress.com/item/433-MHz- ... 18695.html

It works fine with RFXTRX433

18 days to france

Re: Vocal announcement - Good Morning Script

Posted: Sunday 13 March 2016 21:39
by georgesattali
Bonjour JM,
sur le forum français, quelqu'un demande un PIR pour RFLink (que j'ai moi aussi).
http://easydomoticz.com/forum/viewtopic.php?f=22&t=1614

Pourrait tu nous indiquer (ou ici et je reporterai) comment ton PIR est reconnu par RXFCOM et je vérifierai s'il est compatible avec le RFLink ?
Merci, Geo

Re: Vocal announcement - Good Morning Script

Posted: Monday 14 March 2016 20:27
by deennoo
Please guys speak english here or come on our french forum, easydomoticz.com

I'm an RFLink user and got a clone of this, is reconize well, just have to set a off delay.

Protocole is Chuango like.

Re: Vocal announcement - Good Morning Script

Posted: Monday 14 March 2016 20:48
by thebeetleuk
This is great but where are you playing the voice from? In my setup I dont have my pi connected to anything. So I would need to send the voice to something. Thinking out loud now (sort of). So would I use the movement sensor to detect the room with movement and then cast the voice to that room (using chromecast)? hmmm. if only I had more time!!

Re: Vocal announcement - Good Morning Script

Posted: Monday 14 March 2016 22:45
by jmleglise
One step at a time :-)

I use simply this : http://www.amazon.fr/AmazonBasics-A100- ... 00GHY5F3K/ plugged to my RPi in the livingRoom.

Of course multiroom would be great, but on the other hand, I watch my electricity consumption. And I do not like the idea of having several audio systems always on.

Re: Vocal announcement - Good Morning Script

Posted: Tuesday 15 March 2016 8:20
by deennoo
On my side i'm using this one :
http://www.aliexpress.com/store/product ... 59023.html

When plug to RPI's USB this is reconize as an USB soundcard.

Pi's USB are good enought to charge it, and use it on the same time.

And when goes to holiday this bring you a good waterproof BT speaker and a camping light.

Re: Vocal announcement - Good Morning Script

Posted: Tuesday 15 March 2016 13:08
by thebeetleuk
OK so basically just the audio out then. Sounds good. I might give this a go to see how I get on :)

Re: Vocal announcement - Good Morning Script

Posted: Tuesday 15 March 2016 14:46
by Scones
I've got a MAX2PLAY Squeezebox / LMS multi-room setup at home using RPi's as both the server and room players (using PiCorePlayer)

Can anyone say whether this would play nicely with the server?
My server is in the kitchen, and is also our main player.
I would like to use this system for pre-recorded messages too such as "Garage door opening"
Would this interfere with music if it's being played?
Would it be possible to send the voice output to the audio jack/PC speakers while still listening to the music via the HiFiBerry DAC+/BOSE?

Re: Vocal announcement - Good Morning Script

Posted: Sunday 10 April 2016 11:50
by Heisenberg
Very interesting. Has anyone tried to get the vocal announcement via chromecast (audio) or other wifi speaker?

Re: Vocal announcement - Good Morning Script

Posted: Tuesday 12 April 2016 9:20
by Xroads
jmleglise I need your help.
I have copied your script and it's working perfectly, only thing is that it runs 1 hour to late.
I have set it to run if time is > than 8, but then it will run after 9 o'clock.

Code: Select all

timeNow.hour >8 and
   string.sub(uservariables_lastupdate['goodMorning'], 9, 10) ~= os.date("%d")

Re: Vocal announcement - Good Morning Script

Posted: Tuesday 12 April 2016 10:18
by JuanUil
make it timeNow.hour >=8

Re: Vocal announcement - Good Morning Script

Posted: Tuesday 12 April 2016 10:41
by Xroads
Thank's JuanUil
I'll try that and then we will see tomorrow :D

Re: Vocal announcement - Good Morning Script

Posted: Wednesday 13 April 2016 10:59
by Heisenberg
Hi guys,

I connected an old speaker to my rpi. on CLI "tts Hello World" is working fine.
However, (I couldn't find it in the Wiki) where do you put the script and how to assign it to a PIR sensor?

Re: Vocal announcement - Good Morning Script

Posted: Wednesday 13 April 2016 11:27
by Xroads
Hi Heisenberg
I have put it as "script_device_Goodmorning.lua" in scripts/lua, then you only need to put the name of your pir in this line

Code: Select all

if devicechanged['YourPirName'] == 'On' and --Motion sensor Living Room
And then it should work, just remember to make a uservariable with the name of "goodMorning" and as string.

Re: Vocal announcement - Good Morning Script

Posted: Wednesday 13 April 2016 11:51
by Heisenberg
Thnx!

Re: Vocal announcement - Good Morning Script

Posted: Sunday 17 April 2016 12:43
by ldjldj
Hello,

Verry funny script indeed. But I'm stuck on the "tts" part. I can't get the sentence to be announced.

print("talk:"..sentence)
** Sentence is correct as also shown in log

os.execute ("/usr/bin/tts "..sentence.." &")
** No reaction or sound

os.execute ("/usr/bin/tts Test" )
** (Bluetooth-)Speakers produce the word Test

What I'm doing wrong?
Something to do with rights on the raspberry?

Could someone help me?

With kind regards,

Leo

Re: Vocal announcement - Good Morning Script

Posted: Sunday 17 April 2016 20:56
by jmleglise
Hi, it seems that the script doesn't like your sentence !

To be sure, just replace this line os.execute ("/usr/bin/tts "..sentence.." &")

by this :

Code: Select all

sentence ="test" 
os.execute ("/usr/bin/tts "..sentence.." &")
If this works, you must have a weird car in the sentence.

show us your sentence ...

Re: Vocal announcement - Good Morning Script

Posted: Monday 18 April 2016 15:47
by ldjldj
Jmleglise, thanks for the tip.

I feel stupid that I didn' think of this check. Will try when I'm at home.