I am trying to setup a daily report to be emailed to me every day.
I have got it working but instead of showing “0” or “1” for the door status I want it to show “open” or “closed”
Any ideas how to do this?
local SMTP_SERVER = “smtp2go.com”
local SMTP_PORT = “2525”
local USER = “josh.hartley@hotmail.com”
local PASS = “mypassword”
local USER_SENDING = “josh.hartley1@bigpond.com”
local USER_RECEIVING = “josh.hartley@hotmail.com”
local INSIDETEMP = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature”, 135)
local OUTSIDETEMP = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature”, 172)
local FRONTDOOR = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, 104)
local GARAGEDOOR = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, 57)
if (FRONTDOOR == “0”) then
local FRONTDOORSTRING = “closed” I tried adding this with no luck
local smtp = require(“socket.smtp”)
local from = USER_SENDING
local rcpt = {USER_RECEIVING}
local subject_out = “Daily Report from Vera”
local message_out = “Inside Temp is currently “…INSIDETEMP…” Outside Temp is currently “…OUTSIDETEMP…” Front Door is “…FRONTDOORSTRING…” Garage Door is “…GARAGEDOOR…””
local mesgt = {
headers = {
to = USER_RECEIVING,
from = from,
subject = subject_out
},
body = message_out
}
local r, e = smtp.send{ from = from,
rcpt = rcpt,
source = smtp.message(mesgt),
server = SMTP_SERVER,
port = SMTP_PORT,
user = USER,
password = PASS
}
You are declaring the variable in the scope of your if
Try this
local FRONTDOORSTRING = "open"
if(FRONTDOOR == "0") then
FRONTDOORSTRING = "closed"
end
Thank you very much, That works a treat!!!
Can you send this to multiple email addresses or just one?
You can send it to multiple if you like.
Delcare 2 email adresses as local variables
local USER_RECEIVING = "Address1@account.com"
local USER_RECIEVING2 = "Address2@account.com" [/code]
Then add them to the email body
[code]local rcpt = {USER_RECEIVING; USER_RECIEVING2}[/code]
Have a look at the code I use to send a daily report
[code]--DAILY REPORT FOR JOSH FROM VERA--
--RUN AT LUNCH TIME (12PM) EACH DAY AND AT NIGHT TIME
--UPDATED 21-6-16 JH
--LOCAL VARIABLES
local SMTP_SERVER = "smtp2go.com"
local SMTP_PORT = "2525"
local USER = "YOurusername@hotmail.com"
local PASS = "Yourpassword"
local USER_SENDING = "Sender@bigpond.com"
local USER_RECEIVING = "Receipt1@hotmail.com"
local MADDI_RECIEVE = "Reciept2@bigpond.com"
local DATE = (os.date("%A, %d %B %Y %I:%M %p"))
local INSIDETEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 243)
local OUTSIDETEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 235)
local RAMBOTEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 211)
local FRONTDOOR = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 104)
local FRONTDOORLOCK = luup.variable_get("urn:micasaverde-com:serviceId:DoorLock1", "Status", 257)
local GARAGEDOOR = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 174)
--LOCAL STRINGS DEPENDING ON RETURN FROM VARIABLE
local FRONTDOORSTRING = "Open"
if(FRONTDOOR == "0") then
FRONTDOORSTRING = "Closed"
end
local GARAGEDOORSTRING = "Open"
if(GARAGEDOOR =="0") then
GARAGEDOORSTRING = "Closed"
end
local FRONTDOORLOCKSTRING = "Locked"
if(FRONTDOORLOCK=="0") then
FRONTDOORLOCKSTRING = "Unlocked"
end
--GET BATTERY LEVEL FROM ALL BATTERY DEVICES
local bDevNames = "BATTERY STATUS (%):\n-----------------------------"
for deviceNo,d in pairs(luup.devices) do
local bDev = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1","BatteryLevel",deviceNo)
if(bDev ~= Nil) then--check for existence of device
bDev = tonumber(bDev)
if(bDev <= 101) then--threshold value
bDevName = d.description or "NONDESCRIPT"
bDevNames = bDevNames.."\n"..bDevName.. " : " .. bDev.. "%"
end
end
end
--VARIABLES FROM RAINSENSOR
local RAINSENSOR = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 249)
local RAINAMOUNT = luup.variable_get("urn:upnp-org:serviceId:RainSensor1","CurrentTRain", 251)
local RAINYEST = luup.variable_get("urn:upnp-org:serviceId:VContainer1", "Variable2" , 251)
local RAIN3DAYS = luup.variable_get("urn:upnp-org:serviceId:VContainer1", "Variable3" , 251)
local RAIN4DAYS = luup.variable_get("urn:upnp-org:serviceId:VContainer1", "Variable4" , 251)
local RAIN5DAYS = luup.variable_get("urn:upnp-org:serviceId:VContainer1", "Variable5" , 251)
local SENSORSTATE = "Tripped"
if (RAINSENSOR == "0") then
SENSORSTATE = "Not Tripped"
end
--CALCULATE TOTAL RAINFALL OVER 5 DAYS
local TOTALRAIN5DAYS = RAINAMOUNT+RAINYEST+RAIN3DAYS+RAIN4DAYS+RAIN5DAYS
--CALCULATE AVERAGE RAINFALL OVER 5 DAYS
local AVERAGERAINFALL = (RAINAMOUNT+RAINYEST+RAIN3DAYS+RAIN4DAYS+RAIN5DAYS) /5
--EMAIL BODY
local smtp = require("socket.smtp")
local from = USER_SENDING
local rcpt = {USER_RECEIVING; MADDI_RECIEVE}
local subject_out = "Daily Report from Vera"
local message_out = "\n"..DATE.."\n-----------------------------\n\nTEMPS\n-----------------------------\nInside Temp is currently "..INSIDETEMP.." DegC\nOutside Temp is currently "..OUTSIDETEMP.." DegC\nVinnies Room Temp is currently "..RAMBOTEMP.." DegC\n\nLOCKS\n-----------------------------\nFront Door is "..FRONTDOORSTRING.." and "..FRONTDOORLOCKSTRING.."\nGarage Door is "..GARAGEDOORSTRING.."\n\nRAINFALL\n-----------------------------\nTotal Rainfall Today is currently "..RAINAMOUNT.."mm\nYesterdays Rainfall was "..RAINYEST.."mm\nTotal Rain over last 5 days is "..TOTALRAIN5DAYS.."mm\nAverage Daily Rainfall over last 5 days is "..AVERAGERAINFALL.."mm\nRain Sensor is "..SENSORSTATE.."\n\n"..bDevNames..""
local mesgt = {
headers = {
to = USER_RECEIVING,
from = from,
subject = subject_out
},
body = message_out
}
local r, e = smtp.send{ from = from,
rcpt = rcpt,
source = smtp.message(mesgt),
server = SMTP_SERVER,
port = SMTP_PORT,
user = USER,
password = PASS
}
Maybe you can tell me where I’ve messed this up. I edited your script to read :
–LOCAL VARIABLES
local SMTP_SERVER = “smtp.gmail.com”
local SMTP_PORT = “587”
local USER = “myaddress@gmail.com”
local PASS = “gmailpassword”
local USER_SENDING = “myaddress@gmail.com”
local USER_RECEIVING = “myaddress@gmail.com”
local MADDI_RECIEVE = “myaddress@gmail.com”
local DATE = (os.date(“%A, %d %B %Y %I:%M %p”))
local POOLTEMP = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature”, 45)
–EMAIL BODY
local smtp = require(“socket.smtp”)
local from = USER_SENDING
local rcpt = {USER_RECEIVING; MADDI_RECIEVE}
local subject_out = “Pool Temperature”
local message_out = “\n”…DATE…“\n-----------------------------\n\nTEMPS\n-----------------------------\nPool Temp is currently “…POOLTEMP…””
local mesgt = {
headers = {
to = USER_RECEIVING,
from = from,
subject = subject_out
},
body = message_out
}
local r, e = smtp.send{ from = from,
rcpt = rcpt,
source = smtp.message(mesgt),
server = SMTP_SERVER,
port = SMTP_PORT,
user = USER,
password = PASS
}
The 45 is the device number of the sensor I am trying to read. I can send email from a Python script using the same information for server, port, and user information. I put the code in a scene (manually triggered for now) and it says it ran successfully but I get no email…
You have got nTemps still in the message out but there is no nTemp variable. Try removing that.
Unless I’m wrong, the TEMPS that you’re looking at is part of the message body and not actually a variable. the \n is a carriage return.
I’ll give it a go though…
You are quite right actually!!! Sorry I read it to quickly.
I just tested it myself only changing the Dev ID of the temp sensor and the SMTP Settings and it worked so im guessing it is something wrong with the SMPT settings. Maybe try a different port
I think you need to use port 465 and a secure connection.
I’m doing some other research but like I pointed out in the original question, these settings work fine from a Python script… I’m sure Google is hiding the answer, I just have to find it. I’d like the Vera to take on the duties of notifying the wife and I of the pool temp every afternoon. Worse case scenario, the RPi continues to do it. That little gem isn’t going away as it’s integrated into other control features of the house…
GMail requires TLS/SSL. Apparently, Vera does not give us access to this. I guess that explains VeraAlerts…