Hi,
For several days I have been trying to solve the problem of analyzing the data (history) variable.
I have several devices that report their activity to the STATUS global variable.
The following reports look like this:
DEVICE1
STOP
DEVICE 2
STOP
DEVICE 3
STOP
DEVICE 2
STOP
The content of the variable changes from time to time. Never work two devices at the same time.
Now I want to analyze and make a decision based on the operating time of the devices:
1. If device works for more than 2 minutes do: domoicz.devices(123).switchOff().forSec(10)
2. If the same device has stopped working for less or equal than 5 seconds, skip the break and include it in the timer above and perform the above action.
3. If the next device ~ = previous device start timer 2 minutes again.
4. If the interval between the operation of the same device is longer than 5 seconds, start the timer 2 minutes again.
I made the script triggered by changing the STATUS variable.
I added a device that was triggered by a 2-minute timer. Unfortunately - it doesn't work properly. Maybe your experience will tell you how to solve this problem.
Tom
Getting data variables (timer) [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Getting data variables (timer)
Happy to help but I don't fully understand what you try to achieve.tomes wrote: Thursday 09 April 2020 9:33 I made the script triggered by changing the STATUS variable.
I added a device that was triggered by a 2-minute timer. Unfortunately - it doesn't work properly. Maybe your experience will tell you how to solve this problem.
Maybe if you describe in more detail what the real life situation is, share the script you have sofar and point to he first point in the script that you face your issue with. Also domoticz log with log lines generated by your script could prove useful.
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
-
tomes
- Posts: 33
- Joined: Saturday 07 July 2018 22:08
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Poland
- Contact:
Re: Getting data variables (timer)
Thank you for your answer. I'm sending my script. It doesn't report any errors, but it doesn't work either. Probably fatigue and little experience do not allow me to see obvious mistakes or look at the problem completely differently.
Code: Select all
on = {
variables = { 'ONAIR' },
devices = { 294 } -- device switch TIME_OUT to trigger
},
data = { status = { history = true, maxItems = 3 } },
execute = function(domoticz, device)
local onair = domoticz.variables('ONAIR').value
local max_time = 120 -- maxwork time
local max_break = 10 -- time to switch on device - to stop all devices reporting to variable 'ONAIR'
if (device.isVariable) then
domoticz.data.status.add(onair)
if device.value ~= 'STOP' then
if domoticz.data.status.get(3).data ~= onair then
domoticz.devices(294).cancelQueuedCommands()
domoticz.devices(294).switchOn().checkFirst().silent()
domoticz.devices(294).switchOff().afterSec(max_time)
elseif domoticz.data.status.get(3).time.secondsAgo > 5 then -- ignore pause > 5 sec
domoticz.devices(294).cancelQueuedCommands()
domoticz.devices(294).switchOn().checkFirst().silent()
domoticz.devices(294).switchOff().afterSec(max_time)
end
end
end
if (device.isDevice) and device.state == 'Off' and onair ~= 'STOP' then
domoticz.devices('TURN OFF').switchOn().forSec(max_break).silent()
end
end
}- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Getting data variables (timer)
Added some loglines and made some minor changes. Hoepfully it will help you locating the issue.tomes wrote: Thursday 09 April 2020 11:01 Thank you for your answer. I'm sending my script. It doesn't report any errors, but it doesn't work either. Probably fatigue and little experience do not allow me to see obvious mistakes or look at the problem completely differently.
Code: Select all
return
{
on =
{
variables =
{
'ONAIR',
},
devices =
{
294,
}, -- device switch TIME_OUT to trigger
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'onair',
},
data =
{
status =
{
history = true, maxItems = 3,
},
},
execute = function(dz, item)
local onair = dz.variables('ONAIR').value
local timeOut = dz.devices(294)
local turnOff = dz.devices('TURN OFF')
local max_time = 120 -- maxwork time
local max_break = 10 -- time to switch on device - to stop all devices reporting to variable 'ONAIR'
if dz.data.status.size > 0 then
dz.log(dz.data.status.getOldest().data,dz.LOG_DEBUG)
else
dz.log('No historic data available yet.',dz.LOG_DEBUG)
end
if item.isVariable then
dz.data.status.add(onair)
if onair.value ~= 'STOP' then
if dz.data.status.getOldest().data ~= onair then
timeOut.cancelQueuedCommands()
timeOut.switchOn().checkFirst().silent()
timeOut.switchOff().afterSec(max_time)
elseif dz.data.status.getOldest().time.secondsAgo > 5 then -- ignore pause > 5 sec
timeOut.cancelQueuedCommands()
timeOut.switchOn().checkFirst().silent()
timeOut.switchOff().afterSec(max_time)
end
end
end
if item.isDevice and item.state == 'Off' and onair ~= 'STOP' then
turnOff.cancelQueuedCommands()
turnOff.switchOn().checkFirst().silent()
turnOff.switchOff().silent().afterSec(max_break)
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
-
tomes
- Posts: 33
- Joined: Saturday 07 July 2018 22:08
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Poland
- Contact:
Re: Getting data variables (timer)
Thanks for the corrections. In fact, it looks better now.
However, I think it will still not work. The problem is probably not reading the data.status variable but the timeOut switch support. Maybe it can be solved somehow more easily than by creating additional devices?
Tom
However, I think it will still not work. The problem is probably not reading the data.status variable but the timeOut switch support. Maybe it can be solved somehow more easily than by creating additional devices?
Tom
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Getting data variables (timer)
Could be but I stil have no idea what your requirement is. So again my questiontomes wrote: Thursday 09 April 2020 12:11 Maybe it can be solved somehow more easily than by creating additional devices?
Maybe if you describe in more detail what the real life situation is,
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
-
tomes
- Posts: 33
- Joined: Saturday 07 July 2018 22:08
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Poland
- Contact:
Re: Getting data variables (timer)
I manage an amateur radio network. Remote relay stations connect to one server. Domoticz also works on this server. Each of the relays, receiving a signal transmitted by users' radios, sends its unique identifier to the domoticz. E.g:
if user U1 transmits via RPT1 repeater, domoticz receives the variable "ONAIR" with the value RPT1. When the user finishes sending, the variable changes to STOP.
If the user U2 transmits from the RPT2 repeater, domoticz receives the variable "ONAIR" with the value RPT2.
People can talk continuously for 15 minutes blocking the network. I would like to set a limit of 2 minutes. After this time the turnOff.switchOn () switch is activated which blocks the user to (max_break).
I also want to add functionality: a transmission pause shorter than 5 seconds will not extend the broadcasting time of one user by another 2 minutes. I can't identify a specific user - it's analog transmission. However, I can assume that if after a break of less than 5 seconds the value of the 'ONAIR' variable is the same as before the break, it is still transmitted by the same user. So he still has time: 2 minutes minus talk time + break time.
I know this is very complicated, but maybe it will let you give me a simpler solution than the one I'm working on.
Tom
if user U1 transmits via RPT1 repeater, domoticz receives the variable "ONAIR" with the value RPT1. When the user finishes sending, the variable changes to STOP.
If the user U2 transmits from the RPT2 repeater, domoticz receives the variable "ONAIR" with the value RPT2.
People can talk continuously for 15 minutes blocking the network. I would like to set a limit of 2 minutes. After this time the turnOff.switchOn () switch is activated which blocks the user to (max_break).
I also want to add functionality: a transmission pause shorter than 5 seconds will not extend the broadcasting time of one user by another 2 minutes. I can't identify a specific user - it's analog transmission. However, I can assume that if after a break of less than 5 seconds the value of the 'ONAIR' variable is the same as before the break, it is still transmitted by the same user. So he still has time: 2 minutes minus talk time + break time.
I know this is very complicated, but maybe it will let you give me a simpler solution than the one I'm working on.
Tom
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Getting data variables (timer) [Solved]
Thx for the explanation. I think I understand now what you try to do.tomes wrote: Thursday 09 April 2020 12:11 Thanks for the corrections. In fact, it looks better now.
However, I think it will still not work. The problem is probably not reading the data.status variable but the timeOut switch support. Maybe it can be solved somehow more easily than by creating additional devices?
Tom
I corrected one line below. Can you share what you see in the logfile and point to the log-lines where you see or miss something unexpected ?
Code: Select all
return
{
on =
{
variables =
{
'ONAIR',
},
devices =
{
294,
}, -- device switch TIME_OUT to trigger
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'onair',
},
data =
{
status =
{
history = true, maxItems = 3,
},
},
execute = function(dz, item)
local onair = dz.variables('ONAIR').value
local timeOut = dz.devices(294)
local turnOff = dz.devices('TURN OFF')
local max_time = 120 -- maxwork time
local max_break = 10 -- time to switch on device - to stop all devices reporting to variable 'ONAIR'
if dz.data.status.size > 0 then
dz.log(dz.data.status.getOldest().data,dz.LOG_DEBUG)
else
dz.log('No historic data available yet.',dz.LOG_DEBUG)
end
if item.isVariable then
dz.data.status.add(onair)
if onair ~= 'STOP' then
if dz.data.status.getOldest().data ~= onair then
timeOut.cancelQueuedCommands()
timeOut.switchOn().checkFirst().silent()
timeOut.switchOff().afterSec(max_time)
elseif dz.data.status.getOldest().time.secondsAgo > 5 then -- ignore pause > 5 sec
timeOut.cancelQueuedCommands()
timeOut.switchOn().checkFirst().silent()
timeOut.switchOff().afterSec(max_time)
end
end
end
if item.isDevice and item.state == 'Off' and onair ~= 'STOP' then
turnOff.cancelQueuedCommands()
turnOff.switchOn().checkFirst().silent()
turnOff.switchOff().silent().afterSec(max_break)
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
-
tomes
- Posts: 33
- Joined: Saturday 07 July 2018 22:08
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Poland
- Contact:
Re: Getting data variables (timer)
Ok, now it looks like it works. I still have to watch for any errors.
Again thank you very much Waaren for help.
Tom
Again thank you very much Waaren for help.
Tom
Who is online
Users browsing this forum: No registered users and 1 guest