Repeat on and off commands every 10 minutes Topic is solved
Moderator: leecollings
-
- Posts: 70
- Joined: Friday 21 September 2018 18:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Repeat on and off commands every 10 minutes
Hello
I have a simple AC whitch which uses 433,92 MHz and uses one way communication. I need a LUA script which will repeat on or off command every 10 minutes untill on or off is pressed.
- A switch in Domoticz is switched on => repeat on command every 10 minutes untill the switch in Domoticz is turned off.
- The switch in Domoticz is switched off => repeat off command every 10 minutes untill the switch in Domoticz is turned on.
This would solve problems like
- there's a transmission error and the first command doesn't come through
- power goes down and the actual AC switch will turn off and won't remember the last state.
I have a simple AC whitch which uses 433,92 MHz and uses one way communication. I need a LUA script which will repeat on or off command every 10 minutes untill on or off is pressed.
- A switch in Domoticz is switched on => repeat on command every 10 minutes untill the switch in Domoticz is turned off.
- The switch in Domoticz is switched off => repeat off command every 10 minutes untill the switch in Domoticz is turned on.
This would solve problems like
- there's a transmission error and the first command doesn't come through
- power goes down and the actual AC switch will turn off and won't remember the last state.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Repeat on and off commands every 10 minutes
Using dzVents it would look like below.
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Code: Select all
return
{
on =
{
timer =
{
'every 10 minutes',
},
},
execute = function(dz)
weakDevices =
{
'device-1', -- Change to name of your device(s)
'device-2',
'device-3',
}
for _, name in ipairs(weakDevices) do
local device = dz.devices(name)
dz.log('Resending ' .. device.state .. ' state to ' .. name, dz.LOG_INFO)
if device.state == 'Off' then
device.switchOff()
else
device.switchOn()
end
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: 70
- Joined: Friday 21 September 2018 18:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Repeat on and off commands every 10 minutes
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Repeat on and off commands every 10 minutes
no need to do anything different with table weakDevices
just this
Code: Select all
return
{
on =
{
timer =
{
'every 10 minutes',
},
},
execute = function(dz)
weakDevices =
{
'device-1', -- Change to name of your device(s)
'device-2',
'device-3',
}
for _, name in ipairs(weakDevices) do
local device = dz.devices(name)
dz.log('Resending ' .. device.state .. ' state to ' .. name, dz.LOG_INFO)
if device.state == 'Off' then
device.switchOff().repeatAfterSec(30, 2) -- again after 30 and after 60 seconds
else
device.switchOn().repeatAfterSec(30, 2)
end
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: 70
- Joined: Friday 21 September 2018 18:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Repeat on and off commands every 10 minutes
I mean that if I don't want to run the script every 10 minutes but just when the state changes.waaren wrote: ↑Sunday 01 December 2019 22:16no need to do anything different with table weakDevices
just this
Code: Select all
return { on = { timer = { 'every 10 minutes', }, }, execute = function(dz) weakDevices = { 'device-1', -- Change to name of your device(s) 'device-2', 'device-3', } for _, name in ipairs(weakDevices) do local device = dz.devices(name) dz.log('Resending ' .. device.state .. ' state to ' .. name, dz.LOG_INFO) if device.state == 'Off' then device.switchOff().repeatAfterSec(30, 2) -- again after 30 and after 60 seconds else device.switchOn().repeatAfterSec(30, 2) end end end }
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Repeat on and off commands when device state is updated
It could then look like below
Code: Select all
local weakDevices =
{
'device-1', -- Change to name of your device(s)
'device-2',
'device-3',
}
return
{
on =
{
devices = weakDevices,
},
execute = function(dz, item)
local delay = 30
local repeats = 5
for repeater = 1, repeats do
local calculatedDelay = delay * repeater
dz.log('Resending ' .. item.state .. ' state to ' .. item.name .. ' after ' .. calculatedDelay .. ' seconds. ', dz.LOG_INFO)
if item.state == 'Off' then
item.switchOff().silent().afterSec(calculatedDelay)
else
item.switchOn().silent().afterSec(calculatedDelay)
end
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: 70
- Joined: Friday 21 September 2018 18:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Repeat on and off commands every 10 minutes
Hellewaaren wrote: ↑Saturday 30 November 2019 17:48Using dzVents it would look like below.
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Code: Select all
return { on = { timer = { 'every 10 minutes', }, }, execute = function(dz) weakDevices = { 'device-1', -- Change to name of your device(s) 'device-2', 'device-3', } for _, name in ipairs(weakDevices) do local device = dz.devices(name) dz.log('Resending ' .. device.state .. ' state to ' .. name, dz.LOG_INFO) if device.state == 'Off' then device.switchOff() else device.switchOn() end end end }
Tanks you for your script. The script has been mostly working ok but some times it fails when repeat and switch on happens at the same time.
Code: Select all
2020-01-01 16:00:02 On
2020-01-01 16:00:02 Off
2020-01-01 15:48:01 Off
2020-01-01 15:36:01 Off
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Repeat on and off commands every 10 minutes
Unfortunately there is nothing dzVents can do to prevent this from happening.
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: 70
- Joined: Friday 21 September 2018 18:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Repeat on and off commands every 10 minutes
Hi
I added a delay just before the for loop.
Code: Select all
os.execute("sleep " .. math.random(5,15))
Code: Select all
2020-01-02 10:48:06 Off
2020-01-02 10:36:10 Off
2020-01-02 10:24:12 Off
2020-01-02 10:12:11 Off
2020-01-02 10:00:13 Off
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Repeat on and off commands every 10 minutes
This will work for switches triggered by other time based scripts but ( although unlikely ) it might fail for manual switched switches.mpx2 wrote: ↑Thursday 02 January 2020 12:53 I added a delay just before the for loop.This will cause a random delay between 5 and 15 seconds. dzVentz script is not triggered at 00.Code: Select all
os.execute("sleep " .. math.random(5,15))
What is worse, is that the sleep command will block the entire event system for 5-15 seconds as the event system is single threaded and therefore will not process other events until this script has finished. You will see some complaining log lines like
If that does not bather you it's OK but a more elegant approach would be to use an async approach with a openURL call or by using a dummy variable or device to re-trigger this script after some seconds.Warning!, lua script /home/pi/domoticz/dzVents/runtime/dzVents.lua has been running for more than 10 seconds
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: 70
- Joined: Friday 21 September 2018 18:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Contact:
Re: Repeat on and off commands every 10 minutes
I'll try thiswaaren wrote: ↑Thursday 02 January 2020 13:15This will work for switches triggered by other time based scripts but ( although unlikely ) it might fail for manual switched switches.mpx2 wrote: ↑Thursday 02 January 2020 12:53 I added a delay just before the for loop.This will cause a random delay between 5 and 15 seconds. dzVentz script is not triggered at 00.Code: Select all
os.execute("sleep " .. math.random(5,15))
What is worse, is that the sleep command will block the entire event system for 5-15 seconds as the event system is single threaded and therefore will not process other events until this script has finished. You will see some complaining log lines likeIf that does not bather you it's OK but a more elegant approach would be to use an async approach with a openURL call or by using a dummy variable or device to re-trigger this script after some seconds.Warning!, lua script /home/pi/domoticz/dzVents/runtime/dzVents.lua has been running for more than 10 seconds
Code: Select all
os.execute("ping -c " .. math.random(10,25)) .. " localhost > NUL")
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Repeat on and off commands every 10 minutes
That will not make it better. It will stil pause the event System but now for 10-25 seconds (the default interval is 1 second between pings)mpx2 wrote: ↑Sunday 05 January 2020 23:40 I'll try thisCode: Select all
os.execute("ping -c " .. math.random(10,25)) .. " localhost > NUL")
It will also create a file called NUL on your system.
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