Page 1 of 1
Script limit notifications
Posted: Friday 15 January 2021 19:22
by Nefsolive
Hello,
the script I send below, verifies an energy value and sends a message by pushover.
The problem is that if the value is always above, every minute sends a notification! Is there any way to send in this script for example, 3 notifications max ? And not minute by minute.
Ty
Code: Select all
return {
on =
{
timer =
{
'every minute',
}
},
execute = function(domoticz)
local floatFormat = '%d*%.*%d*'
local rawEnergiaConsumida = domoticz.devices('Energia Consumida').rawData[1]
local EnergiaConsumida = tonumber(string.match(rawEnergiaConsumida, floatFormat))
if EnergiaConsumida >= 3200 then
local textmensagem = "A voltagem " .. EnergiaConsumida .. " Watt, está muito ALTA! O disjuntor pode disparar!"
domoticz.notify("⚡ VOLTAGEM ELECTRICA", textmensagem , domoticz.PRIORITY_HIGH, domoticz.SOUND_COSMIC, "" , domoticz.NSS_PUSHOVER)
end
end
}
Re: Script limit notifications
Posted: Friday 15 January 2021 20:46
by waaren
Nefsolive wrote: Friday 15 January 2021 19:22
the script I send below, verifies an energy value and sends a message by pushover.
One way to solve that is in below example
Code: Select all
return {
on =
{
timer =
{
'every minute',
}
},
data =
{
notificationCounter =
{
initial = 0,
},
lastNotification =
{
initial = 0,
},
},
execute = function(domoticz)
local floatFormat = '%d*%.*%d*'
local rawEnergiaConsumida = domoticz.devices('Energia Consumida').rawData[1]
local EnergiaConsumida = tonumber(string.match(rawEnergiaConsumida, floatFormat))
if EnergiaConsumida >= 3200 and ( domoticz.data.lastNotification < ( os.time() + 900 )) then -- max once per 15 minutes
local textmensagem = "A voltagem " .. EnergiaConsumida .. " Watt, está muito ALTA! O disjuntor pode disparar!"
domoticz.notify("⚡ VOLTAGEM ELECTRICA", textmensagem , domoticz.PRIORITY_HIGH, domoticz.SOUND_COSMIC, "" , domoticz.NSS_PUSHOVER)
domoticz.data.lastNotification = os.time()
domoticz.data.notificationCounter = domoticz.data.notificationCounter + 1
if domoticz.data.notificationCounter > 3 then
domoticz.data.lastNotification = os.time() + 3600 * 12 -- Delay next message for 12 hours
domoticz.data.notificationCounter = 0
end
end
end
}
Re: Script limit notifications
Posted: Friday 15 January 2021 22:00
by Nefsolive
waaren wrote: Friday 15 January 2021 20:46
Nefsolive wrote: Friday 15 January 2021 19:22
the script I send below, verifies an energy value and sends a message by pushover.
One way to solve that is in below example
Code: Select all
return {
on =
{
timer =
{
'every minute',
}
},
data =
{
notificationCounter =
{
initial = 0,
},
lastNotification =
{
initial = 0,
},
},
execute = function(domoticz)
local floatFormat = '%d*%.*%d*'
local rawEnergiaConsumida = domoticz.devices('Energia Consumida').rawData[1]
local EnergiaConsumida = tonumber(string.match(rawEnergiaConsumida, floatFormat))
if EnergiaConsumida >= 3200 and ( domoticz.data.lastNotification < ( os.time() + 900 )) then -- max once per 15 minutes
local textmensagem = "A voltagem " .. EnergiaConsumida .. " Watt, está muito ALTA! O disjuntor pode disparar!"
domoticz.notify("⚡ VOLTAGEM ELECTRICA", textmensagem , domoticz.PRIORITY_HIGH, domoticz.SOUND_COSMIC, "" , domoticz.NSS_PUSHOVER)
domoticz.data.lastNotification = os.time()
domoticz.data.notificationCounter = domoticz.data.notificationCounter + 1
if domoticz.data.notificationCounter > 3 then
domoticz.data.lastNotification = os.time() + 3600 * 12 -- Delay next message for 12 hours
domoticz.data.notificationCounter = 0
end
end
end
}
Hello Waaren,
thanks for your reply!
I try and i have this error on log;
Code: Select all
scripts/dzVents/generated_scripts/Msg Potência Watt.lua:27: attempt to perform arithmetic on a function value (field 'time')
Re: Script limit notifications
Posted: Friday 15 January 2021 22:03
by waaren
Nefsolive wrote: Friday 15 January 2021 22:00
I try and i have this error on log;
Code: Select all
scripts/dzVents/generated_scripts/Msg Potência Watt.lua:27: attempt to perform arithmetic on a function value (field 'time')
If you change os.time to os.time() it should work.
Re: Script limit notifications [Solved]
Posted: Friday 15 January 2021 22:14
by Nefsolive
waaren wrote: Friday 15 January 2021 22:03
Nefsolive wrote: Friday 15 January 2021 22:00
I try and i have this error on log;
Code: Select all
scripts/dzVents/generated_scripts/Msg Potência Watt.lua:27: attempt to perform arithmetic on a function value (field 'time')
If you change os.time to os.time() it should work.
Waaren thanks,
os.time() Works!
And script, works like a charm!
Ty for always helping.