Page 1 of 1

lua user variable number in email

Posted: Saturday 18 June 2016 21:29
by tiga
a have made 2 micro switches in my mailbox.
one for when the mailman puts something in, and one if i open it to empty it.
i have a counter in the lua script that counts the times the mailman puts something in.
and when i open the mailbox it resets the counter.
i completely "stole" the lua script becouse i am a biginner and i can modify a little but cant create my own.

i created a uservariable that counts the amount of mail
i receive an email when the mailman puts something in but i want the number in the mail as well,but i cant get it to work.

i want something like this: you have (number) pieces of mail


this is the script:

commandArray = {}
x = uservariables["postteller"] + 1
if (otherdevices['brievenbus'] == 'On') then
commandArray['Variable:postteller'] = tostring(x)
print (x)
commandArray['SendEmail']='post#er is post bezorgd#[email protected]'
end

if (otherdevices['brievenbus leeg'] == 'On') then
commandArray['Variable:postteller'] = tostring(0)
print ('brievenbus is geleegd, teller naar 0')
commandArray['SendEmail']='post#de brievenbus is geleegd, teller is gereset#[email protected]'
end
return commandArray

Re: lua user variable number in email

Posted: Sunday 19 June 2016 15:16
by dannybloe
Using dzVents it would be like this (no user variables needed):

Code: Select all

return {
	active = true,
	on = {
		'brievenbus',
		'brievenbus leeg'
	},
	data = {
		postTeller = { initial = 0 }
	},
	execute = function(domoticz, device)
		
		if (device.name == 'brievenbus' and device.state == 'On') then
			-- brievenbus was triggered
			domoticz.data.postTeller = domoticz.data.postTeller + 1
			domoticz.email('Post', 'Er is post bezorgd. Teller: ' .. tostring(domoticz.data.postTeller), '[email protected]')
		elseif (device.state == 'On') then 
			-- brievenbus leeg was triggered
			domoticz.data.postTeller = 0
			domoticz.email('Post', 'De brievenbus is geleegd. Teller is gereset', '[email protected]')
		end			
	end
}

Re: lua user variable number in email

Posted: Sunday 19 June 2016 21:25
by tiga
thanks for your effort but cant i just use my lua script??

a have a second problem.i want to send an email to 2 emailadresses.i do it like this:

commandArray = {}
x = uservariables["postteller"] + 1
if (otherdevices['brievenbus'] == 'On') then
commandArray['Variable:postteller'] = tostring(x)
print (x)
commandArray['SendEmail']='post#er is post bezorgd#[email protected]'
commandArray['SendEmail']='post#er is post bezorgd#[email protected]'
end


what am i doing wrong becouse only the 2nd email adres is getting the email.i tryed to switch the adresses or use an other one but only the 2nd in line gets the email.

Re: lua user variable number in email

Posted: Sunday 19 June 2016 22:03
by jvdz
Try:

Code: Select all

commandArray[1]={['SendEmail']='post#er is post bezorgd#[email protected]' }
commandArray[2]={['SendEmail']='post#er is post bezorgd#[email protected]' }
Jos

Re: lua user variable number in email

Posted: Monday 20 June 2016 8:52
by dannybloe
tiga wrote:thanks for your effort but cant i just use my lua script??

a have a second problem.i want to send an email to 2 emailadresses.i do it like this:

commandArray = {}
x = uservariables["postteller"] + 1
if (otherdevices['brievenbus'] == 'On') then
commandArray['Variable:postteller'] = tostring(x)
print (x)
commandArray['SendEmail']='post#er is post bezorgd#[email protected]'
commandArray['SendEmail']='post#er is post bezorgd#[email protected]'
end


what am i doing wrong becouse only the 2nd email adres is getting the email.i tryed to switch the adresses or use an other one but only the 2nd in line gets the email.
Of course you can use your own Lua script. Just showing you that things can be done a lot easier. Easier to learn, easier to read.
Anyway, you can concatenate strings in Lua like this:

Code: Select all

 commandArray['SendEmail']='post#er is post bezorgd.Teller:' .. tostring(x) .. '#[email protected]'

Re: lua user variable number in email

Posted: Monday 20 June 2016 14:38
by tiga
ok thank you verry much for all your effort!

i will take a look at dcvents maybe that is better for a new person like me ;-)