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

Moderator: leecollings

Post Reply
blaisabcde
Posts: 4
Joined: Sunday 15 June 2014 22:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
Pjedr
Posts: 38
Joined: Friday 27 December 2013 3:13
Target OS: Linux
Domoticz version: Beta
Location: Friesland
Contact:

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

Post 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.
Pjedr
Posts: 38
Joined: Friday 27 December 2013 3:13
Target OS: Linux
Domoticz version: Beta
Location: Friesland
Contact:

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

Post 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.
blaisabcde
Posts: 4
Joined: Sunday 15 June 2014 22:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by blaisabcde »

Thank, indeed your solution is much better and the voice as well.
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

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

Post by jmleglise »

google voice is not usable any more.
New solution here : https://www.domoticz.com/wiki/Talking_Domoticz
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
User avatar
EdddieN
Posts: 510
Joined: Wednesday 16 November 2016 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Scotland
Contact:

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

Post 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.
11101101 - www.machinon.com
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest