Page 1 of 1

Lua Script missing email element

Posted: Sunday 08 November 2015 21:19
by noddy119
Hi All

The script below works in full if I set the 'time to run' to a few minutes ahead and watch it execute in the log.

When it runs for real at 07:45 and 15:00 it switches the fan on/off and writes to the log file but misses the e-mail element. Any thoughts??

Code: Select all

--~/domoticz/scripts/lua/script_time_loungedamp.lua
commandArray = {}

--Uservariables

Email1="[email protected]"

amHour=07
amMinute=45
pmHour=15
pmMinute=00
lounge_Humidity=50
file = io.open('/home/graeme/domoticz/scripts/lua/fanlog.txt' , "a")
lounge_Humidity = otherdevices_humidity['lounge Temperature']
Message = 'lounge is damp @ '.. lounge_Humidity .. '% - please open windows'

print('Running Damp Script')

-- Time to run?
time = os.date("*t")
if (time.hour == amHour and time.min == amMinute) or (time.hour == pmHour and time.min == pmMinute) then

	 if  lounge_Humidity > 64 then --if the humidity is high turn on the loft fan
		commandArray['Loft Fan']='On'
		file:write(os.date("%x %X") .. " the humidity in the lounge is high @ " .. lounge_Humidity .. "\n")
		file:close()
		commandArray=['SendEmail']='lounge room report#'.. Message .. '#' .. Email1
	else --if the humidity is low enough turn off the loft fan
		commandArray['Loft Fan']='Off'
		file:write(os.date("%x %X") .. " the humidity in the lounge is low @ " .. lounge_Humidity .. "\n")
		file:close()
	end
end
 
--LUA default
return commandArray

Re: Lua Script missing email element

Posted: Monday 09 November 2015 15:16
by Whatsek
I think that this:

Code: Select all

commandArray=['SendEmail']='lounge room report#'.. Message .. '#' .. Email1
Should be:

Code: Select all

commandArray=['SendEmail']="lounge room report#'.. Message .. '#'..Email1..'"

Re: Lua Script missing email element

Posted: Tuesday 10 November 2015 21:40
by noddy119
Hi Whatsek

According to the wiki the format is:

Code: Select all

commandArray['SendEmail']='subject#body#[email protected]'
I know the format of the line is correct as the e-mail gets sent when I change the pmHour and pmMinute variables to a few minutes ahead. I see in the log 'EventSystem: Script event triggered:' followed by 'Notification sent (Email)'

It is when the script runs at 07:45 and 15:00 that the e-mail does not get sent although bizarrely the switch is triggered and a line written to fanlog.txt

Re: Lua Script missing email element

Posted: Tuesday 10 November 2015 23:43
by Whatsek
I know the format, but you are using variables in that line and didn't close it properly.

Re: Lua Script missing email element

Posted: Tuesday 10 November 2015 23:51
by simonrg
noddy119 wrote:According to the wiki the format is:

Code: Select all

commandArray['SendEmail']='subject#body#[email protected]'
But the line in your script doesn't follow this format and is wrong, so not sure why it is ever working, you have:

Code: Select all

commandArray=['SendEmail']='lounge room report#'.. Message .. '#' .. Email1
You shouldn't have an equal sign (=) after commandArray, as ['SemdEmail'] is the key for that array, so it should be:

Code: Select all

commandArray['SendEmail']='lounge room report#'.. Message .. '#' .. Email1
You are ok without any extra final quotes as Email1 is a string and so when that is concatenated then the total string is a string and so doesn't need further quoting.

Re: Lua Script missing email element

Posted: Wednesday 11 November 2015 11:24
by Whatsek
I also didn`t see the extra "=" nice!