I've tried to make an event/lua which sends out a Telegram message to either my own alarm group which only contains some family members or to a different Telegram group which also contains neighbours, depending on the parameter given to the bash script (based on the presence of a resident).
The bash script is working fine, but I can't get the LUA part working.
The error in the log is:
Code: Select all
2017-11-04 11:05:39.127 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_SmokeAlarm.lua: /home/pi/domoticz/scripts/lua/script_device_SmokeAlarm.lua:8: syntax error near 'then'
Code: Select all
print('Smoke alarm! Sending out alerts.')
commandArray = {}
if (devicechanged['Smokealarm'] == 'Panic' and otherdevices['Phone1'] == 'Off' and otherdevices['Phone2'] == 'Off') then
print("Smoke alarm and nobody is home, sending to neighbours group")
os.execute("bash /home/pi/domoticz/scripts/SmokeAlarm neighbours")
else (devicechanged['Smokealarm'] == 'Panic' and otherdevices['Phone1'] == 'On' or otherdevices['Phone2'] == 'On') then
print("Smoke alarm but someone is home, only sending to own group")
-- commandArray['MyOtherDeviceName']='On'
os.execute("bash /home/pi/domoticz/scripts/SmokeAlarm alarm")
end
return commandArray

Any pointers would be much appriciated, or other clever ways to send a different parameter depending on a presence.
Cheers,
/void
PS: The bash script, in case anyone is curious:
Code: Select all
#!/bin/sh
date=`/bin/date '+%d-%m-%Y'`;
time=`/bin/date '+%H-%M-%S'`;
today=`/bin/date '+%d-%m-%Y %H:%M:%S'`;
secstat=`curl -s -i -H "Accept: application/json" "http://192.168.x.y:8080/json.htm?type=command¶m=getsecstatus" | grep -oP '(?<="secstatus" :).*(?=,)'`
if [ "$1" = neighbour ] ; then
/usr/bin/curl --data chat_id=-<NEIGHBOURGROUP> --data-urlencode "text=$today Smoke alarm at <MYNAME>!" "https://api.telegram.org/bot<ID>:<APIKEY>/sendMessage"
exit
elif [ "$1" = alarm ] ; then
/usr/bin/curl --data chat_id=-<PERSONALGROUP> --data-urlencode "text=$today Smoke alarm!" "https://api.telegram.org/bot<ID>:<APIKEY>/sendMessage"
exit
else
echo 'No parameter given, please either use "neighbour" to send to the Alarm <NEIGHBOURGROUP> Telegram group or "alarm" to send to own Telegram group.'
exit
fi