Page 1 of 1

[SOLVED] Pproblems with combined triggerrules

Posted: Thursday 08 March 2018 12:40
by McMelloW
This dzVents script has to run every minute. But only when a Percentage Device has a value is > 0

This is the trigger part of the code

Code: Select all

local Bpump = 64   -- Index of a Percentage Virtual Device


	on = {
		timer = { 'every minute' },
		devices = { 'Bpump' }
	},
	
	execute = function(domoticz, triggerItem)
	if (triggerItem.isTimer) and
	    (device.name == 'Bpump' and device.percentage > 0) then
            domoticz.log('Script is running.', domoticz.LOG_DEBUG)
	else
	    -- do nothing
	end
The log shows I do something wrong with (device.name == 'Bpump' and device.percentage > 0) But I can't figure out what
Who can point me at the right direction?

Code: Select all

2018-03-08 12:10:01.168 dzVents: Info: VSEB 0.0.1: ------ Start internal script: Heat-Counter:, trigger: every minute
2018-03-08 12:10:01.169 dzVents: Error (2.4.1): VSEB 0.0.1: An error occured when calling event handler Heat-Counter
2018-03-08 12:10:01.169 dzVents: Error (2.4.1): VSEB 0.0.1: ...oticz/scripts/dzVents/generated_scripts/Heat-Counter.lua:44: attempt to index global 'device' (a nil value)
2018-03-08 12:10:01.169 dzVents: Info: VSEB 0.0.1: ------ Finished Heat-Counter

Re: problems with combined triggerrules

Posted: Thursday 08 March 2018 12:48
by dannybloe
Yes, you are doing something wrong :)
'device' is not a variable that exists in your code. If the trigger is due to the timer then the second argument of the execute function (triggerInfo in your script) is a timer object. If the trigger is due to Bpump being updated (device-rule) then the second argument is a device. So, in case of the timer trigger you want do this:

Code: Select all

if (triggerItem.isTimer and domoticz.devices('Bpump').percentage > 0) then
    --
end
If however you want to do something when the device is updated you can do this:

Code: Select all

if (triggerItem.isDevice and trigerItem.percentage > 0) then
    --
end
In this case, triggerItem is the device being triggered.

Re: problems with combined triggerrules

Posted: Thursday 08 March 2018 13:15
by McMelloW
Thanks very much.
I have got it working now. :D :D
It is not easy to understand the logic of dzVents. But once you got it. It is such an easy way to write scripts. :)
Looking forward to your Youtube video volmue 2