timer not working in dzvents

Moderator: leecollings

Post Reply
rokutas
Posts: 11
Joined: Monday 24 April 2023 12:53
Target OS: -
Domoticz version:
Contact:

timer not working in dzvents

Post 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)
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: timer not working in dzvents

Post 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.
rokutas
Posts: 11
Joined: Monday 24 April 2023 12:53
Target OS: -
Domoticz version:
Contact:

Re: timer not working in dzvents

Post by rokutas »

sorry, its still runs every second i mean, not every minute.
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: timer not working in dzvents

Post 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?
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: timer not working in dzvents

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: timer not working in dzvents

Post 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?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
rokutas
Posts: 11
Joined: Monday 24 April 2023 12:53
Target OS: -
Domoticz version:
Contact:

Re: timer not working in dzvents

Post 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)
rokutas
Posts: 11
Joined: Monday 24 April 2023 12:53
Target OS: -
Domoticz version:
Contact:

Re: timer not working in dzvents

Post 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
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: timer not working in dzvents

Post 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
},
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest