Lua Script missing email element

Moderator: leecollings

Post Reply
noddy119
Posts: 12
Joined: Sunday 19 July 2015 14:27
Target OS: Linux
Domoticz version: 3.5837
Location: Norfolk, UK
Contact:

Lua Script missing email element

Post 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
Whatsek
Posts: 16
Joined: Saturday 31 May 2014 23:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest B
Location: Hilversum, The Netherlands
Contact:

Re: Lua Script missing email element

Post 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..'"
noddy119
Posts: 12
Joined: Sunday 19 July 2015 14:27
Target OS: Linux
Domoticz version: 3.5837
Location: Norfolk, UK
Contact:

Re: Lua Script missing email element

Post 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
Whatsek
Posts: 16
Joined: Saturday 31 May 2014 23:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest B
Location: Hilversum, The Netherlands
Contact:

Re: Lua Script missing email element

Post by Whatsek »

I know the format, but you are using variables in that line and didn't close it properly.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Lua Script missing email element

Post 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.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
Whatsek
Posts: 16
Joined: Saturday 31 May 2014 23:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest B
Location: Hilversum, The Netherlands
Contact:

Re: Lua Script missing email element

Post by Whatsek »

I also didn`t see the extra "=" nice!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest