Page 1 of 1

timer not working in dzvents

Posted: Sunday 05 November 2023 13:05
by rokutas
hello, i want to add timer to my dzvents script, however with adding timer, still the script goes on every minute. Can someone help?


return {
on = {
devices = {
5, -- Flow Meter IDX
15, -- Temperature Delta IDX
25, -- Watt Sensor IDX
31,
29,
34 -- Power Sensor IDX
},
timer = {
'every 1 minute'
}
},
execute = function(domoticz, devices, timer)

Re: timer not working in dzvents

Posted: Sunday 05 November 2023 13:48
by willemd
'every 1 minute' is exactly what you specified, so what is it that you want?

by the way, I think in the execute you should only add one parameter behind "domoticz", like this
execute = function(domoticz, trigger)

then you can check in your script whether the trigger is a device or a timer.

Re: timer not working in dzvents

Posted: Sunday 05 November 2023 17:28
by rokutas
sorry, its still runs every second i mean, not every minute.

Re: timer not working in dzvents

Posted: Sunday 05 November 2023 17:33
by willemd
rokutas wrote: Sunday 05 November 2023 17:28 sorry, its still runs every second i mean, not every minute.
Maybe it runs every second because your devices are updated that often and then trigger your script?

Re: timer not working in dzvents

Posted: Sunday 05 November 2023 21:46
by waltervl
Your script has 2 triggers:
1. Every minute
2. On every device change on the by you defined devices.

If your devices are updates every second then your script will also run every second.
BTW updating sensor devices every second is very fast for a domotica system. It is possible but your hardware should be accordingly fast.

If you just want to run it every minute you have to remove the device trigger from your script.

Re: timer not working in dzvents

Posted: Monday 06 November 2023 7:03
by hoeby
Do you need to have those devices as a trigger?

What i often see when people start using dzvents, that they out the devices In the trigger list, because they think this is necessary to use the data in the script. This is not the case.

Maybe you van post the complete script, that we can look if that device list can be shorters. And like waltervl said, look at your devices. Is an every second update necessary?

Re: timer not working in dzvents

Posted: Sunday 12 November 2023 12:43
by rokutas
return {
on = {
devices = {
5, -- Flow Meter IDX
15, -- Temperature Delta IDX
25, -- Watt Sensor IDX
31,
29,
34 -- Power Sensor IDX
},
timer = {
'every 1 minute'
}
},
execute = function(domoticz, timer)
-- Get devices
local flowMeter = domoticz.devices(5) -- Flow Meter IDX
local temperatureDelta = domoticz.devices(15) -- Temperature Delta IDX
local wattSensor = domoticz.devices(25) -- Watt Sensor IDX
local powerSensor = domoticz.devices(34) -- Power Sensor IDX
local customSensor = domoticz.devices(17) -- Custom Sensor IDX for COP
local sensor1 = domoticz.devices(31) -- Temperature Sensor 20 IDX
local sensor2 = domoticz.devices(29) -- Temperature Sensor 29 IDX

-- Check if all devices are available
if flowMeter and temperatureDelta and wattSensor and powerSensor and customSensor then
-- Get flow reading (default to 0 if nil)
local flow = flowMeter.flow or 0
-- Get the value from the temperatureDelta device
local temperatureDeltaValue = sensor1.temperature - sensor2.temperature
-- Calculate power
local power = (flow * 60 / 1 ) * 4 * 975 * temperatureDeltaValue / 3

-- Get watt reading (default to 0 if nil)
local watt = wattSensor.actualWatt or 0

if watt > 0 then
-- Calculate COP
local cop = power / watt
cop = math.floor(cop * 100) / 100
customSensor.updateCustomSensor(cop)
else
-- Set COP to 0 if watt reading is 0
customSensor.updateCustomSensor(0)
end

-- Update power sensor with calculated power
powerSensor.updateCustomSensor(power)
temperatureDelta.updateCustomSensor(temperatureDeltaValue)
end
end
}

now it gets triggered by every device change (interval for devices is 1 second)

Re: timer not working in dzvents

Posted: Sunday 12 November 2023 13:02
by rokutas
also, maybe someone has information on controlling pwm signal?
http://192.168.8.182/control?cmd=PWM,12,3 i put in this code to my selector switch (i need to generate 18Hz 3% pwm signal) , however it doesnt seem to react to this command

Re: timer not working in dzvents

Posted: Sunday 12 November 2023 16:48
by waltervl
Better keep questions seperated.

To return to your original question of script being run every second instead of every minute:
Remove the following section from your script:

Code: Select all

devices = {
5, -- Flow Meter IDX
15, -- Temperature Delta IDX
25, -- Watt Sensor IDX
31,
29,
34 -- Power Sensor IDX
},