Vocal announcement - Good Morning Script

Moderator: leecollings

jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Vocal announcement - Good Morning Script

Post 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

Last edited by jmleglise on Monday 07 March 2016 22:48, edited 2 times in total.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Vocal announcement - Good Morning Script

Post by georgesattali »

Thanks for your funny script - It's so unfair I 'll have to buy a motion sensor now :D
merci jm.
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: Vocal announcement - Good Morning Script

Post by jmleglise »

I have this one : http://www.aliexpress.com/item/433-MHz- ... 18695.html

It works fine with RFXTRX433

18 days to france
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Vocal announcement - Good Morning Script

Post 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
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Vocal announcement - Good Morning Script

Post 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.
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
thebeetleuk
Posts: 115
Joined: Saturday 21 December 2013 23:50
Target OS: Linux
Domoticz version:
Location: Scotland
Contact:

Re: Vocal announcement - Good Morning Script

Post 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!!
My Setup: Pi, RFXtrx433, HomeEasy: 13 Dimmers & 4 Sockets, 2 motion-sensors, 3 magnetic switches, 1 OWL Electricity Sensor, 3 Oregon Temp Sensor.
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: Vocal announcement - Good Morning Script

Post 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.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Vocal announcement - Good Morning Script

Post 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.
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
thebeetleuk
Posts: 115
Joined: Saturday 21 December 2013 23:50
Target OS: Linux
Domoticz version:
Location: Scotland
Contact:

Re: Vocal announcement - Good Morning Script

Post by thebeetleuk »

OK so basically just the audio out then. Sounds good. I might give this a go to see how I get on :)
My Setup: Pi, RFXtrx433, HomeEasy: 13 Dimmers & 4 Sockets, 2 motion-sensors, 3 magnetic switches, 1 OWL Electricity Sensor, 3 Oregon Temp Sensor.
Scones
Posts: 47
Joined: Wednesday 10 December 2014 16:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Vocal announcement - Good Morning Script

Post 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?
Heisenberg
Posts: 135
Joined: Monday 27 January 2014 14:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Vocal announcement - Good Morning Script

Post by Heisenberg »

Very interesting. Has anyone tried to get the vocal announcement via chromecast (audio) or other wifi speaker?
Raspberry Pi Type B
Raspberry Pi Type B2
RFXCOMtrx433e
Xroads
Posts: 30
Joined: Thursday 25 February 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Vocal announcement - Good Morning Script

Post 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")
Raspberry pi 2
Razberry z-wave module with Fibaro dimmer, relay and pir and Dlink pir.
433mhz RFlink with 5 pcs. on/off switches
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: Vocal announcement - Good Morning Script

Post by JuanUil »

make it timeNow.hour >=8
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
Xroads
Posts: 30
Joined: Thursday 25 February 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Vocal announcement - Good Morning Script

Post by Xroads »

Thank's JuanUil
I'll try that and then we will see tomorrow :D
Raspberry pi 2
Razberry z-wave module with Fibaro dimmer, relay and pir and Dlink pir.
433mhz RFlink with 5 pcs. on/off switches
Heisenberg
Posts: 135
Joined: Monday 27 January 2014 14:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Vocal announcement - Good Morning Script

Post 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?
Raspberry Pi Type B
Raspberry Pi Type B2
RFXCOMtrx433e
Xroads
Posts: 30
Joined: Thursday 25 February 2016 10:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Vocal announcement - Good Morning Script

Post 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.
Raspberry pi 2
Razberry z-wave module with Fibaro dimmer, relay and pir and Dlink pir.
433mhz RFlink with 5 pcs. on/off switches
Heisenberg
Posts: 135
Joined: Monday 27 January 2014 14:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Vocal announcement - Good Morning Script

Post by Heisenberg »

Thnx!
Raspberry Pi Type B
Raspberry Pi Type B2
RFXCOMtrx433e
ldjldj
Posts: 5
Joined: Friday 16 January 2015 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5113
Location: Near Utrecht
Contact:

Re: Vocal announcement - Good Morning Script

Post 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
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: Vocal announcement - Good Morning Script

Post 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 ...
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
ldjldj
Posts: 5
Joined: Friday 16 January 2015 20:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5113
Location: Near Utrecht
Contact:

Re: Vocal announcement - Good Morning Script

Post by ldjldj »

Jmleglise, thanks for the tip.

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

Who is online

Users browsing this forum: No registered users and 1 guest