Lua script - send notification when button is open for 30 seconds
Moderator: leecollings
-
- Posts: 29
- Joined: Saturday 19 March 2016 23:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Lua script - send notification when button is open for 30 seconds
Hi
I have problem to make script to send notification to mail or pushover only when my fridgedoor is open longer than 30s.
Mayby You guys will help me?
Best regards
I have problem to make script to send notification to mail or pushover only when my fridgedoor is open longer than 30s.
Mayby You guys will help me?
Best regards
- heggink
- Posts: 972
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
Dummy switch with on delay? Won't switch on until after 30 seconds..
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
-
- Posts: 29
- Joined: Saturday 19 March 2016 23:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
Thx for answer but I don't understand
Maybe You can write it more precisely ?
Best regards
Edit:
Ok. I know what You mean
It doesn't work
I think maybe becouse my Fridge Door switch is "contact" type
Maybe there is some simple way to do that in lua script?
Maybe You can write it more precisely ?
Best regards
Edit:
Ok. I know what You mean
It doesn't work
I think maybe becouse my Fridge Door switch is "contact" type
Maybe there is some simple way to do that in lua script?
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
How does domoticz currently get the information about the refrigerator door status (Open/Close)?
Is it simply a swith is Domoticz of which you want to test whether it is in the Open status for 30 seconds?
Jos
Is it simply a swith is Domoticz of which you want to test whether it is in the Open status for 30 seconds?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 14
- Joined: Thursday 24 November 2016 12:14
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
script_time_demo.lua
-
- Posts: 331
- Joined: Sunday 22 February 2015 12:19
- Target OS: Linux
- Domoticz version: 2020.x
- Location: Netherlands
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
That's not going to work: it ignores "Off" commands during that period so it will switch on after 30 seconds even if the door was closed again within that time.heggink wrote:Dummy switch with on delay? Won't switch on until after 30 seconds..
- heggink
- Posts: 972
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
That's why I suggested a dummy device: a contact device does not have an on/off delay so create a dummy device that has an on delay of 30 seconds and a script behind it. Then build a lua/blocky that switches this device On on open and Off on closed. If the door gets closed before the dummy switches on then the dummy gets switched off and never switches on (the on delay is reset). I just tested it and it works as expected (open window, dummy switches on after 10 secs in my case, close window within 10 secs and the dummy never switches on). I used 2 simple blockies to switch the dummy based on the window sensor.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
-
- Posts: 331
- Joined: Sunday 22 February 2015 12:19
- Target OS: Linux
- Domoticz version: 2020.x
- Location: Netherlands
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
A contact device indeed does nog have a delay, but you could change it to a regular on/of switch. Then however it does not work because, like I mentioned the device itself seems to ignore the "off" command during its delay time. It does however work - as you suggested - with an additional dummy switch which has a delay.
This script works fine:
This script works fine:
Code: Select all
local Notification = 'TestSwitch'
-- set your delay at the switch properties of the 'TestSwitch'
local TestContact = 'TestContact'
commandArray = {}
if devicechanged[TestContact] == 'On'
then
commandArray[Notification]='On'
end
if devicechanged[TestContact] == 'Off'
then
commandArray[Notification]='Off'
end
if devicechanged[Notification] == 'On'
then
print('Door was open too long!')
end
return commandArray
- heggink
- Posts: 972
- Joined: Tuesday 08 September 2015 21:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 12451
- Location: NL
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
Never tried to switch a 'contact as a regular switch' with a delay. Good to know it does not work that way.
For me, I typically use dummy devices as it allows more granular understanding of where things go wrong in my scripts (I can see the states independently and I can test manually before tying to a real device). Downside is that I have a LOT of dummy devices and probably not so good programming skills that I need all this debugging .
For me, I typically use dummy devices as it allows more granular understanding of where things go wrong in my scripts (I can see the states independently and I can test manually before tying to a real device). Downside is that I have a LOT of dummy devices and probably not so good programming skills that I need all this debugging .
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
-
- Posts: 16
- Joined: Tuesday 12 April 2016 17:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
If you use the Fuction time diff you may be able to do it without a a dummy switch but you would need a variable if you didnt want to be constantly notified. I dont have any contacts so not sure how they report back but using below you should be able to get it working.
Code: Select all
-- script_Fridge.lua
function timedifference(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
commandArray = {}
if (otherdevices['Fridge Conact'] == 'Off' and timedifference(otherdevices_lastupdate['Fidge Contact']) > 30) then
commandArray['SendNotification']='Fridge Open for more than 30 Seconds'
end
return commandArray
-
- Posts: 29
- Joined: Saturday 19 March 2016 23:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
Hi
I try Your script but I don't know how to define variable and add it to script.
When I use Your script without variable Domoticz hangs and I receive notification all the time.
I will try version with Dummy switch.
EDIT:
Thx for Dummy switch idea but I have strange problem. I made Dummy switch named (Lodówka1). My Fridge door switch is (Drzwi - Lodówka). I made two Blocky Scripts but everytime I activate them and try opem my fridge my Dummy switch do nothing. When I open my Blocky scripts page my new two script are Purple colour and deactivated (mayby someone had this problem - I see Purple colour for he first time)
Thanks Everyone for help
Best regards
I try Your script but I don't know how to define variable and add it to script.
When I use Your script without variable Domoticz hangs and I receive notification all the time.
I will try version with Dummy switch.
EDIT:
Thx for Dummy switch idea but I have strange problem. I made Dummy switch named (Lodówka1). My Fridge door switch is (Drzwi - Lodówka). I made two Blocky Scripts but everytime I activate them and try opem my fridge my Dummy switch do nothing. When I open my Blocky scripts page my new two script are Purple colour and deactivated (mayby someone had this problem - I see Purple colour for he first time)
Thanks Everyone for help
Best regards
- Attachments
-
- lodowka.jpg (151.32 KiB) Viewed 6900 times
-
- Posts: 16
- Joined: Tuesday 12 April 2016 17:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
Not seen purple before but a quick look on Events Wiki - "Purple = Disabled because a missing device was used [ Domoticz stops this Blockly automatic! ]"
Both devices showing in switches ok?
Once sorted you probably want to change the drop down on the right from "All" to "Device" and you could use a else if for the off statement too for the off statement.
If you want to use the time one. Create a variable under Setup > More Options > User Variables > give it a name, type = integer, Value = 0
Both devices showing in switches ok?
Once sorted you probably want to change the drop down on the right from "All" to "Device" and you could use a else if for the off statement too for the off statement.
If you want to use the time one. Create a variable under Setup > More Options > User Variables > give it a name, type = integer, Value = 0
Code: Select all
- script_Fridge.lua
function timedifference(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
commandArray = {}
if (uservariables['Variable name'] == 0 and otherdevices['Fridge Conact'] == 'Open' and timedifference(otherdevices_lastupdate['Fidge Contact']) > 30) then
commandArray['SendNotification']='Fridge Open for more than 30 Seconds'
commandArray['Variable:Variable name'] = '1'
elseif (uservariables['Variable name'] == 1 and otherdevices['Fridge Conact'] == 'Closed' then
commandArray['Variable:Variable name'] = '0'
end
return commandArray
-
- Posts: 29
- Joined: Saturday 19 March 2016 23:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
Thx a lot for help
I changed All to Device and now everythong works!:)
I will also try Your script some time later and write if works.
EDIT:
It works like a charm:)
There was one bracket missing in Your code (in this line - elseif (uservariables['fridge'] == 1 and otherdevices['Drzwi - Lodówka']) == 'Closed' then - but it works! Thank You very much!
Best regards
I changed All to Device and now everythong works!:)
I will also try Your script some time later and write if works.
EDIT:
It works like a charm:)
There was one bracket missing in Your code (in this line - elseif (uservariables['fridge'] == 1 and otherdevices['Drzwi - Lodówka']) == 'Closed' then - but it works! Thank You very much!
Best regards
-
- Posts: 65
- Joined: Saturday 22 April 2017 17:35
- Target OS: Windows
- Domoticz version:
- Contact:
Re: Lua script - send notification when button is open for 30 seconds
Please post your script. I need a similar option. I have a magnetic switch on a gate. I like a notification when the gate if open for more than 30 sec without closing.
I do have a device script that triggers when the gate opens. But where should I put the timer?
When I change the event to a ALL or TIME it will fire up every minute, but the devicechanged command gives a NIL.
And furthermore the interval should be less that the 1 minute for the TIME scripts.
I do have a device script that triggers when the gate opens. But where should I put the timer?
When I change the event to a ALL or TIME it will fire up every minute, but the devicechanged command gives a NIL.
And furthermore the interval should be less that the 1 minute for the TIME scripts.
Who is online
Users browsing this forum: No registered users and 1 guest