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
Trigger script at specific value
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Trigger script at specific value
Yes. If you share the script I can show you how.
Can you also please state the domoticz / dzVents version you use?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 45
- Joined: Tuesday 03 March 2020 8:15
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Trigger script at specific value
thnx for answering.
Version: 2020.2 (build 12494)
dzVents Version: 3.0.15
here is the script
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
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Trigger script at specific value
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 45
- Joined: Tuesday 03 March 2020 8:15
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Trigger script at specific value
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?
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?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Trigger script at specific value
Yes, Change line 4 toEnz0jacco 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?
Code: Select all
return domoticz.devices(238).active and domoticz.devices(237).actualWatt < 20
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 45
- Joined: Tuesday 03 March 2020 8:15
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Trigger script at specific value
working perfect Waaren thank u so much!
never used the active line before in dzvent but defenitively gonna do it some more!
never used the active line before in dzvent but defenitively gonna do it some more!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Trigger script at specific value
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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest