Here is my combined code to test one device. I took your post #24 and the smtptogo info.
This seems to work. If I set the test level to 101, I get an email:
The battery in the Garage 3-in-1 is now at 100%
But when I change it back to a lower test limit of 30, I still get an email with blank battery status:
The battery in the is now at %
Shouldn't the script terminate if it does not pass the test of actual status being greater than the test limit? What am I missing to make it do nothing if the battery is greater than the test limit?
Thanks.
local test_for_below = 30
local room = ""
local level_to_report = ""
local serviceId = "urn:micasaverde-com:serviceId:HaDevice1"
local variableId = "BatteryLevel"
local warning = "The battery in the "
local level
-- duplicate these lines for each device to test
level = luup.variable_get(serviceId, variableId, 8) or "0"
level = tonumber(level)
if (level < test_for_below) then
room = "Garage 3-in-1"
level_to_report = level
end
-- end of duplicated lines
local message_out = warning..room.." is now at "..level_to_report.."%"
local myEmail = "myemailgoeshere"
-- local message_out = "OMG WTF it works!!"
local send_to = myEmail
local sender = myEmail
local subject_out = "Battery Low Notification"
local smtp = require("socket.smtp")
local mesgt = {
headers = {
to = send_to,
from = sender,
subject = subject_out},
body = message_out}
local result = smtp.send {
from = sender,
rcpt = {send_to},
source = smtp.message(mesgt),
server = "smtp2go.com",
port = "2525",
user = myEmail,
password = "smtptogopasswordgoeshere"}