Page 1 of 1

Notification when switch is on after set time

Posted: Wednesday 17 February 2016 13:50
by LdV46
Hi! I've searched on the forum to find the question I'm about to ask but could not find it. If it is already somewhere, please lead me!

On the attic I have a room where I do not come often. As I have found out, I sometimes forget te switch off the light and only see this the next time I come up there. This ofcourse is a waste of energy. I know I can send an automatic off-command after a set amount of time in the switch itself. I prefer to get a notification if the light is left on after a set amount of time so the light is not switcht off when I'm working there.

My idea is (in Blockly for I do not know LUA (yet)):

If the attic light is on for # minutes send notification with text "ABC".

Does anyone have an idea that works?

Kind Regards,

Robbert van der Gaag

Re: Notification when switch is on after set time

Posted: Wednesday 17 February 2016 14:30
by lazara007
This Lua script will work:

-- script_time_garagedoor.lua
t1 = os.time()
s = otherdevices_lastupdate['Garagedoor']
-- returns a date time like 2013-07-11 17:23:12

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)

commandArray = {}

t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (otherdevices['Garagedoor'] == 'Open' and difference > 600 and difference < 700) then
commandArray['SendNotification']='Garage door alert#The garage door has been open for more than 10 minutes!'
end

return commandArray

Re: Notification when switch is on after set time

Posted: Wednesday 17 February 2016 23:16
by LdV46
It worked!
I would not be able to reproduce this from scratch, but hey, it works!

Thanks!

Re: Notification when switch is on after set time

Posted: Thursday 18 February 2016 12:02
by LdV46
I have an additional question about this one, maybe there is some documentation that describes this?

You chose to set the difference to 100 seconds (1 minute 40 seconds). I tested and it worked but I received 2 push-notifications. I changed the difference to 30 seconds and now I do not receive a single one.. What is the minimal difference?

Re: Notification when switch is on after set time

Posted: Thursday 18 February 2016 12:19
by Westcott
It is a 'time' script (script_time_garagedoor.lua) so it runs every 60 seconds.
A 30 second difference might not be caught. 50% chance?
Whereas a 100 second difference can be caught twice.

Re: Notification when switch is on after set time

Posted: Thursday 18 February 2016 14:45
by jannl
Either that or use a virtual switch which you also set to prevent double notifications