Sending information by email

I am trying to sent out some information directy out of the veralite.

I can sent an email triggerd by a scedule (once a week)

but how can i sent out the value “gas” “kwh1” and ‘’'kwh2"
and they must be after ‘‘Meterstanden van " … os.date(“%c”)’’

this is what i have already working

your help is highy apprictated

==quote==
local smtp = require(“socket.smtp”)

    local METER_DEV_ID = 139
    local METER1_DEV_ID = 140
    local METER2_DEV_ID = 141

    local gas= luup.variable_get("urn:brutgrink-com:serviceId:dutchSmartMeter", "gas",  METER_DEV_ID )
    local kwh1= luup.variable_get("urn:micasaverde-com:serviceId:EnergyMetering1", "kwh",  METER1_DEV_ID )
    local kwh2= luup.variable_get(" urn:micasaverde-com:serviceId:EnergyMetering1 ", "kwh",  METER2_DEV_ID )

    local SMTP_SERVER = "xxx.xxx.com"
    local SMTP_PORT = "25"
    local USER_SENDING = "<xxxx@xxx.xx>"
    local USER_RECEIVING = "<xxx@xxx.xx>"

    local from = USER_SENDING
    local rcpt = {USER_RECEIVING}

    local mesgt = {
        headers = {
            to = USER_RECEIVING,
            subject = "Meterstanden"
        },
        body = "Meterstanden van "  .. os.date("%c")
        }

    local r, e = smtp.send{
        from = from,
        rcpt = rcpt,
        source = smtp.message(mesgt),
        server = SMTP_SERVER,
        port = SMTP_PORT,
      }

    if (e) then
        luup.log("Yikes " ..  e)
    end

== unquote ==

change the line with the body to something like:

body = "Meterstanden van "  .. os.date("%c") .. ", gas = " .. gas .. ", kwh1 = " .. kwh1 .. ", kwh2 = " .. kwh2

@capjay;

i have tried but it does not work. it does not sent any email

if i reduce it to

body = “Meterstanden van " … os.date(”%c")

it will sent an email with the text
==Meterstanden van Tue Jun 26 08:47:46 2012==

if i change it into
body = "Meterstanden van " … gas

it does not sent nothing

please advise

@huib

Add default values for all the variables you get with luup.variable_get. Some may be nil, in which case you’ll get an error.

    local gas= luup.variable_get("urn:brutgrink-com:serviceId:dutchSmartMeter", "gas",  METER_DEV_ID ) or "0"
    local kwh1= luup.variable_get("urn:micasaverde-com:serviceId:EnergyMetering1", "kwh",  METER1_DEV_ID ) or "0"
    local kwh2= luup.variable_get(" urn:micasaverde-com:serviceId:EnergyMetering1 ", "kwh",  METER2_DEV_ID ) or "0"

@capjay,

i have changed it and recieve now the message as follows;

Meterstanden van Tue Jun 26 10:52:53 2012, gas = 0, kwh1 = 0, kwh2 = 0

so we are getting some where
now to get the value

rgds

Hi huib,

Double check your capitalization, of both the service Id and the variable name. Case matters. I particularly suspect “kwh” should be “KWH”, but don’t take my word for it. Go look at the Advanced tab of the device and see what capitalization is needed.

Edit: Link to thread showing that capitalization was the issue.

also make sure that device IDs are correct…

Problem solved
thanks for the help

[quote=“huib, post:8, topic:171899”]Problem solved
thanks for the help[/quote]

@ Huib
Could you tell us how you did this? I’d like to have a daily mail with the values of the meters (in and export tariff 1 and 2) better would even be the values between the day do this day - previous day equals usage current day.
any idea?

[quote=“JohnVS, post:9, topic:171899”]@ Huib
Could you tell us how you did this? I’d like to have a daily mail with the values of the meters (in and export tariff 1 and 2) better would even be the values between the day do this day - previous day equals usage current day.
any idea?[/quote]

This thread shows a method of creating an email message with values in the body of the message: http://forum.micasaverde.com/index.php/topic,28160.0.html