Page 1 of 1
Trigger script at specific value
Posted: Wednesday 25 November 2020 21:39
by Enz0jacco
Hey guys
I would like to turn of my tv plug when there is no usage.
I wrote a script and it’s working but the script checks every 10sec or so because the plug sends its usage every 10sec.
Is there a way to trigger the script only when the usage value is below let’s say 20 Watts?
Thnx Jacco
Sent from my iPad using Tapatalk
Re: Trigger script at specific value
Posted: Wednesday 25 November 2020 22:43
by waaren
Enz0jacco wrote: ↑Wednesday 25 November 2020 21:39
Is there a way to trigger the script only when the usage value is below let’s say 20 Watts?
Yes. If you share the script I can show you how.
Can you also please state the domoticz / dzVents version you use?
Re: Trigger script at specific value
Posted: Wednesday 25 November 2020 23:57
by Enz0jacco
thnx for answering.
Version: 2020.2 (build 12494)
dzVents Version: 3.0.15
here is the script
Code: Select all
return {
on = {
variables = {17},
devices = {237},
},
execute = function(dz, item)
local STEKKER = dz.devices(238)
local TVverbruik = dz.devices(237).actualWatt
local TVstatusvariable = dz.variables(17)
if item.isDevice and
TVverbruik < 20 and
TVstatusvariable.value ~= 'Off' then
dz.openURL('http://127.0.0.1:8084/json.htm?type=command¶m=updateuservariable&idx=17&vname=TV&vtype=2&vvalue=Off').afterSec(30)
dz.log('TV gaat uit over 30 sec')
elseif item.isDevice and
TVverbruik > 20 and
TVstatusvariable.value ~= 'On' then
TVstatusvariable.set('On')
cancelQueuedCommands()
dz.log('TV is AAN')
elseif item.isVariable and
TVstatusvariable.value == 'Off' then
STEKKER.switchOff().checkFirst()
dz.log('Stroom TV uit')
end
end
}
Re: Trigger script at specific value
Posted: Thursday 26 November 2020 1:23
by waaren
Enz0jacco wrote: ↑Wednesday 25 November 2020 23:57
Version: 2020.2 (build 12494) / dzVents Version: 3.0.15
Below script should do it. Don't know if you use the TVstatusvariable elsewhere so I left it in but script can do the same without it
using
Code: Select all
STEKKER.switchOff().afterSec(delay)
Code: Select all
return
{
active = function(domoticz)
return domoticz.devices(237).actualWatt < 20
end,
on =
{
variables =
{
17,
},
devices =
{
237,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all OK
marker = 'TV control',
},
execute = function(dz, item)
local STEKKER = dz.devices(238)
local TVstatusvariable = dz.variables(17)
local delay = 30
if item.isDevice and TVstatusvariable.value ~= 'Off' then
local offTime = dz.time.addSeconds(delay).rawTime
TVstatusvariable.set('Scheduled for Off at ' .. offTime)
TVstatusvariable.set('Off').afterSec(delay)
dz.log('TV gaat uit over ' .. delay .. ' seconden (' .. offTime .. ').', dz.LOG_DEBUG )
elseif item.isVariable and TVstatusvariable.value == 'Off' then
STEKKER.switchOff().checkFirst()
dz.log('Stroom TV uit', dz.LOG_DEBUG )
end
end
}
Re: Trigger script at specific value
Posted: Thursday 26 November 2020 9:51
by Enz0jacco
thnx for the quick reply Waaren!
it is working but now when the tv is off and thus the usage is less than 20W the script is still triggered every 10sec.
is it possible that the script just triggers once and then finished until tv is back on/off again?
Re: Trigger script at specific value
Posted: Thursday 26 November 2020 9:57
by waaren
Enz0jacco wrote: ↑Thursday 26 November 2020 9:51
thnx for the quick reply Waaren!
it is working but now when the tv is off and thus the usage is less than 20W the script is still triggered every 10sec.
is it possible that the script just triggers once and then finished until tv is back on/off again?
Yes, Change line 4 to
Code: Select all
return domoticz.devices(238).active and domoticz.devices(237).actualWatt < 20
Re: Trigger script at specific value
Posted: Thursday 26 November 2020 14:42
by Enz0jacco
working perfect Waaren thank u so much!
never used the active line before in dzvent but defenitively gonna do it some more!
Re: Trigger script at specific value
Posted: Thursday 26 November 2020 15:10
by waaren
Enz0jacco wrote: ↑Thursday 26 November 2020 14:42
... but definitively gonna do it some more!
It's there to help you but please be aware that the function code used in the active segment is executed every minute and at every device change in the system so best to limit yourself and don't put a lot of logic in that function.