absent present notification

Moderator: leecollings

Post Reply
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

absent present notification

Post by tiga »

hello, im a complete idiot with lua but a copy/paste a little script together
i ping a couple of phones on the network with a crontab and it switches on/off virtual devices.
i want to get a notification when someone leaves or comes home.

Code: Select all

commandArray = {}

if (devicechanged['phone 1'] == 'On' and otherdevices['my phone'] == 'Off') then
        commandArray[1]={['SendEmail']='Phone 1#phone 1 is home#[email protected]' }
end
if (devicechanged['phone 1'] == 'Off' and otherdevices['my phone'] == 'Off') then
        commandArray[1]={['SendEmail']='Phone 1#phone 1 is gone#[email protected]' }
end



if (devicechanged['phone 2'] == 'On' and otherdevices['my phone'] == 'Off') then
        commandArray[1]={['SendEmail']='Phone 2#phone 2 is home#[email protected]' }
end
if (devicechanged['phone 2'] == 'Off' and otherdevices['my phone'] == 'Off') then
        commandArray[1]={['SendEmail']='Phone 2#phone 2 is gone#[email protected]' }
end
return commandArray
this works fine, i get a notification only when i am gone.
but when we leave toghether i also get the notification.

so the question is:can i "activate" the notification only when my Phone is gone for more then lets say 10 minutes?
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: absent present notification

Post by jvdz »

Something like this? ;)

Code: Select all

commandArray = {}

-- Function to return the number of seconds the device was last changed
function datetimedifferencenow(s)
	year = string.sub(s, 1, 4)
	month = string.sub(s, 6, 7)
	day = string.sub(s, 9, 10)
	hour = string.sub(s, 12, 13)
	minutes = string.sub(s, 15, 16)
	seconds = string.sub(s, 18, 19)
	t1 = os.time()
	t2 = os.time{year = year, month = month, day = day, hour = hour, min = minutes, sec = seconds}
	difference = os.difftime(t1, t2)
	return difference
end


if (otherdevices['my phone'] == 'Off' and datetimedifferencenow('my phone') > 600) then
	if (devicechanged['phone 1'] == 'On') then
		commandArray[1] = {['SendEmail'] = 'Phone 1#phone 1 is home#[email protected]' }
	elseif (devicechanged['phone 1'] == 'Off') then
		commandArray[1] = {['SendEmail'] = 'Phone 1#phone 1 is gone#[email protected]' }
	end

	if (devicechanged['phone 2'] == 'On') then
		commandArray[1] = {['SendEmail'] = 'Phone 2#phone 2 is home#[email protected]' }
	elseif (devicechanged['phone 2'] == 'Off') then
		commandArray[1] = {['SendEmail'] = 'Phone 2#phone 2 is gone#[email protected]' }
	end
end
return commandArray
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: absent present notification

Post by tiga »

Thanks Jos looks good.
I try it tomorrow
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: absent present notification

Post by tiga »

i copie/paste your code in my lua and adjusted the device names and when my Phone is going offline:

Code: Select all

2017-03-29 21:16:23.558 Error: EventSystem: in present test: [string "commandArray = {}..."]:12: field 'day' missing in date table
how to fix this issue??
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest