only run once

Moderator: leecollings

Post Reply
foscolino
Posts: 20
Joined: Monday 02 November 2020 18:38
Target OS: Windows
Domoticz version: 2.20
Location: Italy
Contact:

only run once

Post by foscolino »

Hello, i have this script to check if light is on every first, second, third hours and after send mail notification, but the problems is a "time trigger" and run every minutes. :?
is it possible run this script only run once, not every minutes!
thanks a lot.

Code: Select all

if (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference > 3600 and difference < 7200) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 1 ora!'
   print('Luce Antibagno accesa da più di 1 ora')
elseif (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference > 3600 and difference < 10800) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 2 ore!'
   print('Luce Antibagno accesa da più di 2 ora')
elseif (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference > 3600 and difference < 14400) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 3 ore!'
   print('Luce Antibagno accesa da più di 3 ore')
end
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: only run once

Post by waaren »

foscolino wrote: Wednesday 18 November 2020 7:51 Hello, i have this script to check if light is on every first, second, third hours and after send mail notification, but the problems is a "time trigger" and run every minutes. :?
is it possible run this script only run once, not every minutes!
It is not possible to prevent the triggering of a time based classic Lua script but you can prevent that the notifications are send and/or the prints going to the log by using the logic from the code below.

Code: Select all


local atMinute = '07'

if os.date('%M') ~= atMinute then
    print ('no execution required')
    return commandArray
end

print ('I will process rest of the script logic now')

if (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference > 3600 and difference < 7200) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 1 ora!'
   print('Luce Antibagno accesa da più di 1 ora')
elseif (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference > 3600 and difference < 10800) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 2 ore!'
   print('Luce Antibagno accesa da più di 2 ora')
elseif (otherdevices['S1 - Antibagno - 192.168.20.73'] == 'On' and difference > 3600 and difference < 14400) then
   commandArray['SendNotification']='Luce Antibagno#Attenzione, Luce accesa da più di 3 ore!'
   print('Luce Antibagno accesa da più di 3 ore')
end

return commandArray

.. or use the dzVents Lua framework where you can set the script to only execute once per hour , -day ,-week, etc..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
foscolino
Posts: 20
Joined: Monday 02 November 2020 18:38
Target OS: Windows
Domoticz version: 2.20
Location: Italy
Contact:

Re: only run once

Post by foscolino »

Hi waaren, thank you very much for your feedback, but I don't understand the logic you wrote :?

local atMinute = '07' is a random value?

if the date minutes is about or equal to seventh minute the script not work, correctly ? ;)
thanks for you support
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: only run once

Post by waaren »

foscolino wrote: Wednesday 18 November 2020 9:03 local atMinute = '07' is a random value?
Yes atMinute can be anything from '00' to '59'
if the date minutes is about or equal to seventh minute the script not work, correctly ? ;)
No. If the date minutes = '07' the rest of the script will be executed. If the date minutes are not '07' the script will stop without executing the rest of the script
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
foscolino
Posts: 20
Joined: Monday 02 November 2020 18:38
Target OS: Windows
Domoticz version: 2.20
Location: Italy
Contact:

Re: only run once

Post by foscolino »

Hi waaren,
thank you very much, now I understand ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest