is there a way to check if a switch has been on for over 30 seconds and after that send a message? Sounds pretty simple but I can't figure it out
Check if switch has been on for x seconds
Moderator: leecollings
-
tapaz
- Posts: 6
- Joined: Thursday 16 November 2017 9:42
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Check if switch has been on for x seconds
Hello,
is there a way to check if a switch has been on for over 30 seconds and after that send a message? Sounds pretty simple but I can't figure it out
I am trying to alert if a door was left open for too long. Of course, if the door is shut before 30 seconds, no alert should be sent.
is there a way to check if a switch has been on for over 30 seconds and after that send a message? Sounds pretty simple but I can't figure it out
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Check if switch has been on for x seconds
I use this for checking if frontdoor (and same for backdoor) is open longer than 5 minutes.
After 5 minutes it sends a message every minute for 5 minutes and write a message to the Domoticz log.
difference > 300 : check after 5 minutes
difference < 600 : check until 10 minutes open (you get a message after 5 minutes. Repeats every minute until 10 minutes)
change these intervals to you're own settings
After 5 minutes it sends a message every minute for 5 minutes and write a message to the Domoticz log.
difference > 300 : check after 5 minutes
difference < 600 : check until 10 minutes open (you get a message after 5 minutes. Repeats every minute until 10 minutes)
change these intervals to you're own settings
Code: Select all
-- script_time_dooropen.lua
t1 = os.time()
s = otherdevices_lastupdate['Sensor - Voordeur']
-- 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['Sensor - Voordeur'] == 'Open' and difference > 300 and difference < 600) then
commandArray['SendNotification']='Voordeur melding#Voordeur staat langer dan 5 minuten open!'
print("Voordeur open")
end
return commandArrayHardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
-
tapaz
- Posts: 6
- Joined: Thursday 16 November 2017 9:42
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Check if switch has been on for x seconds
Many thanks htilburgs! So it seems I have to do it with lua, no problem. I was just wondering if it's possible to do with blockly at all, maybe not 
- htilburgs
- Posts: 464
- Joined: Tuesday 03 November 2015 11:01
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Check if switch has been on for x seconds
In blockly it’s not so easy to use the time difference, so doing it in lua ( or dzVents) is more easy.
Hardware:
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
RPi3 - Aeon Labs Z-Stick GEN5 - Fibaro Dimmer 2 - Fibaro Roller Shutter 2 - Fibaro Smoke Sensor - Yeelight RGBW Led bulb - Yeelight Smart LED Light Strip - Neo Coolcam PIR Motion Sensor - Neo Coolcam PowerPlug - Nest Thermostat v3
-
astrapowerrr
- Posts: 141
- Joined: Tuesday 31 January 2017 20:34
- Target OS: -
- Domoticz version:
- Contact:
Re: Check if switch has been on for x seconds
hi,
im looking for some solutions here.
i copied and edit you lua to this below
but i cant get i to work.
this is my first time working with a script so i hope i can fix this with some help.
what i want to achieve is that when my tapwater switch is active(on) longer then 5 minutes it sets my dummy switch "douche actief"to on.
if tapwater is off before 5 minutes then do nothing...
the next step will be that when tapwater is off i also want to set the switch"douche actief"to off(but that i can do with blocky)
-- script_tapwater douche actief.lua
t1 = os.time()
s = otherdevices_lastupdate['Tapwater']
-- 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['Tapwater'] == 'on' and difference > 300 and difference < 600) then
commandArray['Douche actief']='on'
end
return commandArray
i hope someone can help me with this.....
greets marco
im looking for some solutions here.
i copied and edit you lua to this below
but i cant get i to work.
this is my first time working with a script so i hope i can fix this with some help.
what i want to achieve is that when my tapwater switch is active(on) longer then 5 minutes it sets my dummy switch "douche actief"to on.
if tapwater is off before 5 minutes then do nothing...
the next step will be that when tapwater is off i also want to set the switch"douche actief"to off(but that i can do with blocky)
-- script_tapwater douche actief.lua
t1 = os.time()
s = otherdevices_lastupdate['Tapwater']
-- 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['Tapwater'] == 'on' and difference > 300 and difference < 600) then
commandArray['Douche actief']='on'
end
return commandArray
i hope someone can help me with this.....
greets marco
Who is online
Users browsing this forum: No registered users and 0 guests