Notification when switch is on after set time

Moderator: leecollings

Post Reply
User avatar
LdV46
Posts: 6
Joined: Thursday 01 October 2015 9:39
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Notification when switch is on after set time

Post 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
lazara007
Posts: 14
Joined: Monday 30 March 2015 14:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Notification when switch is on after set time

Post 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
User avatar
LdV46
Posts: 6
Joined: Thursday 01 October 2015 9:39
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Notification when switch is on after set time

Post by LdV46 »

It worked!
I would not be able to reproduce this from scratch, but hey, it works!

Thanks!
User avatar
LdV46
Posts: 6
Joined: Thursday 01 October 2015 9:39
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Location: Netherlands
Contact:

Re: Notification when switch is on after set time

Post 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?
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Notification when switch is on after set time

Post 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.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Notification when switch is on after set time

Post by jannl »

Either that or use a virtual switch which you also set to prevent double notifications
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests