Page 1 of 1
SOLVED Run dzVents script every 10 seconds? [Solved]
Posted: Saturday 29 May 2021 19:31
by McJohn
Is it possible to run the script below every 10 seconds?
The problem is that when the Aeotec Home Energy Meter (HEM) doesn't has power,
Domoticz still keeps holding the last values (for example 230V / 16.2 Watt / 0.2 A).
Ands that's unfortunately a fault in Domoticz I think because when there is no power all the Devices have to say/set to 0.
So, we are working with a script but this script fires only every minute. So, when the power is gone (or back again) it takes a full minute before Domoticz can do/say something. (And sometimes are 60 seconds a very loong time in a human life).
So, Is it possible to run the script below every 10 seconds?
The HEM Z-Wave Device data refreshes every 5 seconds.
So, the most beautiful solution is a Trigger when the HEM data doesn't refresh after >10 seconds. (Or is Life back again).
Thanks for all the support!
John
Code: Select all
return {
on = {
timer = { 'every minute' }},
execute = function( dz )
local voltage = dz.devices('Voltage')
local power= dz.variables('Power')
local function setvar(var, to)
if var.value ~= to and dz.startTime.secondsAgo > 60 then var.set(to) end
end
if voltage.lastUpdate.secondsAgo > 60 then
setvar(power,'Off')
else
setvar(power,'On')
end
end
}
Re: Run dzVents script every 10 seconds?
Posted: Saturday 29 May 2021 20:23
by waaren
McJohn wrote: ↑Saturday 29 May 2021 19:31
Is it possible to run the script below every 10 seconds?
Could look like below.
Code: Select all
local scriptVar = 'every10Seconds'
return
{
on =
{
timer =
{
'every minute',
},
customEvents =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function( dz, item )
if item.isTimer then
for delay = 10, 50, 10 do
dz.emitEvent(scriptVar).afterSec(delay)
end
end
local voltage = dz.devices('Voltage')
local power= dz.variables('Power')
local function setvar(var, to)
if var.value ~= to and dz.startTime.secondsAgo > 60 then var.set(to) end
end
if voltage.lastUpdate.secondsAgo > 60 then
setvar(power,'Off')
else
setvar(power,'On')
end
end
}
Re: Run dzVents script every 10 seconds?
Posted: Saturday 29 May 2021 20:59
by McJohn
Thank you so much for the very quick reply!
The script is much faster now when the power is back; within 10 seconds the Variable is ON. Perfect.
But when the power is off, there is still a delay of ~60 seconds.
Isn't that strange?
Re: Run dzVents script every 10 seconds?
Posted: Saturday 29 May 2021 23:11
by waaren
McJohn wrote: ↑Saturday 29 May 2021 20:59
But when the power is off, there is still a delay of ~60 seconds.
Isn't that strange?
No not really. You check for 60 seconds so it should not come as a surprise...
If you want it quicker then change line
Code: Select all
if voltage.lastUpdate.secondsAgo > 60 then
to
Code: Select all
if voltage.lastUpdate.secondsAgo > 9 then
Re: Run dzVents script every 10 seconds?
Posted: Sunday 30 May 2021 10:55
by McJohn
Thank you very much for your answer.
It’s working now, perfect!
Last questions:
When these kind of scripts are running every 10 seconds:
- Ist that an heavy load for Domoticz?
- When this script is running every 10 seconds, can this affect the operation/execution of other scripts at that moment?
- What happens when 5 scripts are running every 10 seconds?
Sorry for all the questions, I appreciate your help!
Re: Run dzVents script every 10 seconds?
Posted: Sunday 30 May 2021 16:58
by waaren
McJohn wrote: ↑Sunday 30 May 2021 10:55
- Ist that an heavy load for Domoticz?
it depends on the size of your system and any other apps executed on that system
- When this script is running every 10 seconds, can this affect the operation/execution of other scripts at that moment?
Yes. Only one event script can be executed simultaniously. So when this script executes. Others have to wait.
- What happens when 5 scripts are running every 10 seconds?
30 scripts will run every minute.
Re: Run dzVents script every 10 seconds?
Posted: Sunday 30 May 2021 19:20
by McJohn
Thanks for all the interesting information and your patience.
In our case it's a Raspberry Py3 B+ with only Domoticz running.
Is there a way (via a Dummy switch) to switch On and Off these kind of scripts?
With 2 separate dzVents scripts?
Re: Run dzVents script every 10 seconds?
Posted: Sunday 30 May 2021 20:41
by waaren
McJohn wrote: ↑Sunday 30 May 2021 19:20
Is there a way (via a Dummy switch) to switch On and Off these kind of scripts?
You could check on the state of a dummy swithch to decide if you want to trigger the script the extra 5 times.
Re: Run dzVents script every 10 seconds?
Posted: Monday 31 May 2021 8:59
by McJohn
Thanks for the explanation.
Could you please adjust the script top here with the status of the switch "powercheck" ?
(On = script=On , Off = script disabled)
(Math is not my best side..)
Thanks in advance.
John
Re: Run dzVents script every 10 seconds?
Posted: Monday 31 May 2021 9:50
by waaren
McJohn wrote: ↑Monday 31 May 2021 8:59
Thanks for the explanation.
Could you please adjust the script top here with the status of the switch "powercheck" ?
Could look like below
Code: Select all
local scriptVar = 'every10Seconds'
return
{
on =
{
timer =
{
'every minute',
},
customEvents =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_ERROR,
marker = scriptVar,
},
execute = function( dz, item )
if dz.devices('powercheck').state == 'Off' then return end -- If powercheck device state is Off the script will not do anything,
if item.isTimer then
for delay = 10, 50, 10 do
dz.emitEvent(scriptVar).afterSec(delay)
end
end
local voltage = dz.devices('Voltage')
local power= dz.variables('Power')
local function setvar(var, to)
if var.value ~= to and dz.startTime.secondsAgo > 60 then var.set(to) end
end
if voltage.lastUpdate.secondsAgo > 60 then
setvar(power,'Off')
else
setvar(power,'On')
end
end
}
Re: Run dzVents script every 10 seconds?
Posted: Monday 31 May 2021 16:56
by McJohn
Yes, it's working!
Thank you very much, also for all your time and patience.
I've learned a lot from you these days!
Case closed.