Page 1 of 1

LUA script that talk to me when a virtual switch is ON

Posted: Saturday 06 September 2014 23:07
by blaisabcde
Let me share one of my LUA script that talk to me when a virtual switch is ON :

Code: Select all

-- Replace "Garbage" by your virtual lightswitch device name
-- Make sure http://www.domoticz.com/wiki/Talking_Domoticz is installed

commandArray = {}
if (devicechanged['Garbage'] == 'On') then
	os.execute('espeak "Bring the garbage out"')
end
return commandArray


Feel free to do some improvement to it and post it on the forum =)

The next step would be to create a script that tell me the current weather via espeak.

Re: LUA script that talk to me when a virtual switch is ON

Posted: Sunday 07 September 2014 1:28
by Pjedr
My text to speech script by google via Internet, really good audio:
(Limit = 100 characters)

Code: Select all

#!/bin/bash
if [ -e "/var/ramdrive/domoticz" ]; then TEMPDIR="/var/ramdrive"; else TEMPDIR="/home/peter/"; fi; echo "`date` $*" >> ${TEMPDIR}/${0##*/}.log;
exec 200>${TEMPDIR}/${0##*/}.lock || exit 1; flock -x 200 || { echo "ERROR: flock() failed." >&2; exit 1; }
say() { local IFS=+;/usr/bin/mplayer -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?tl=nl&q=$*"; }; say $*; flock -u 200
I included locking mechanism, cause muliple messages were at the same time.

Re: LUA script that talk to me when a virtual switch is ON

Posted: Sunday 07 September 2014 1:35
by Pjedr
Just call the script with the text as parameters from your lua or domoticz_main as below.

Code: Select all

if [ "$status" = "On" ]; then                                                                                                                  nohup ${SCRIPTSDIR}/Speech.sh "${devname} is aangezet" 2>/dev/null &
 nohup ${SCRIPTSDIR}/JSTxWrapper.sh "Domoticz OSD melding: ${devname} is aangezet" 6 2>/dev/null &
 nohup ${SCRIPTSDIR}/Telegram.sh $msgto "Domoticz melding: ${devname} is aangezet" 2>/dev/null &                                               #espeak -v nl "${devname} is aangezet"
exit; fi;                                                                                                                                     if [ "$status" = "Off" ]; then                                                                                                                 nohup ${SCRIPTSDIR}/Speech.sh "${devname} is uitgezet" 2>/dev/null &
 nohup ${SCRIPTSDIR}/JSTxWrapper.sh "Domoticz OSD melding: ${devname} is uitgezet" 6 2>/dev/null &
 nohup ${SCRIPTSDIR}/Telegram.sh $msgto "Domoticz melding: ${devname} is uitgezet" 2>/dev/null &
 #espeak -v nl "${devname} is uitgezet"
exit; fi;
espeak, telegram, jstx lines can be removed, you need only speech.sh,nohup and & is used to start it in separate silent processes so domoticz does not slow down. Jstx is used to send the text to my philips tv screen.

Re: LUA script that talk to me when a virtual switch is ON

Posted: Monday 08 September 2014 4:09
by blaisabcde
Thank, indeed your solution is much better and the voice as well.

Re: LUA script that talk to me when a virtual switch is ON

Posted: Saturday 05 March 2016 17:04
by jmleglise
google voice is not usable any more.
New solution here : https://www.domoticz.com/wiki/Talking_Domoticz

Re: LUA script that talk to me when a virtual switch is ON

Posted: Thursday 03 August 2017 0:23
by EdddieN
Is there a way to send the "text" as part of the script, rather than having to do individual scripts per device?

For example, edit a button when it goes ON it calls a script like this: scriptt://espeak "something in on"

I tried but says it cannot find a script. I thought about linking to espeak inside the script folder but couldn't find the espeak file that executes... any ideas welcome.