[SOLVED] Pproblems with combined triggerrules

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

[SOLVED] Pproblems with combined triggerrules

Post 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
Last edited by McMelloW on Thursday 08 March 2018 16:31, edited 1 time in total.
Greetings McMelloW
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: problems with combined triggerrules

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: problems with combined triggerrules

Post 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
Greetings McMelloW
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest