2 identical scripts, one works on doesn't?  [Solved]

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

Moderator: leecollings

Post Reply
wouterlet
Posts: 109
Joined: Tuesday 02 October 2018 20:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

2 identical scripts, one works on doesn't?

Post by wouterlet »

Hello,

I'm still starting with DzVents, but I have a light script working:

Code: Select all

return {
	on = {
		devices = {'Lux Zithoek', 'Motion Zithoek'
		}
	},
	execute = function(dz, item)

		if dz.devices('Motion Zithoek').active and
		   item.lux < 25 then
		   dz.devices('Light Wand Voor').setLevel(50)
		end
		if dz.devices('Motion Zithoek') == Off or 
            item.lux > 70 then
		   dz.devices('Light Wand Voor').switchOff()
		end
	end
}
So I copied it and only changed the devices names (Checked them on mistakes) but now it doesn't work:

Code: Select all

{
	on = {
		devices = {'Lux Bijkeuken', 'Motion Bijkeuken'
		}
	},
	execute = function(dz, item)

		if dz.devices('Motion Bijkeuken').active and
		   item.lux < 25 then
		   dz.devices('Light Bijkeuken').setLevel(50)
		end
		if dz.devices('Motion Bijkeuken') == Off or 
            item.lux > 70 then
		   dz.devices('Light Bijkeuken').switchOff()
		end
	end
}
I get the following error:

2020-05-03 07:27:24.027 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Licht Bijkeuken DzVents
2020-05-03 07:27:24.027 Error: dzVents: Error: (3.0.2) ...ts/dzVents/generated_scripts/Licht Bijkeuken DzVents.lua:13: attempt to compare number with nil
2020-05-03 07:27:24.125 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Licht Bijkeuken DzVents
2020-05-03 07:27:24.126 Error: dzVents: Error: (3.0.2) ...ts/dzVents/generated_scripts/Licht Bijkeuken DzVents.lua:9: attempt to compare nil with number

So the problem is in the lux comparation
I use the Neo Coolcam pir and the Fibaro Dimmer 2 on both settings.
What can the problem be?

I tried to put the value in a local,

Code: Select all

return {
	on = {
		devices = {'Lux Bijkeuken', 'Motion Bijkeuken'
		}
	},
	execute = function(dz, item)
    local LuxBijkeuken = dz.devices('Lux Bijkeuken')
		if dz.devices('Motion Bijkeuken').active and
		   LuxBijkeuken < 35 then
		   dz.devices('Light Bijkeuken').setLevel(50)
		end
		if dz.devices('Motion Bijkeuken') == Off or 
            LuxBijkeuken > 55 then
		   dz.devices('Light Bijkeuken').switchOff()
		end
	end
}

but then I get another error:

2020-05-03 08:01:13.621 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Licht Bijkeuken DzVents
2020-05-03 08:01:13.621 Error: dzVents: Error: (3.0.2) ...ts/dzVents/generated_scripts/Licht Bijkeuken DzVents.lua:13: attempt to compare number with table
2020-05-03 08:01:13.719 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Licht Bijkeuken DzVents
2020-05-03 08:01:13.719 Error: dzVents: Error: (3.0.2) ...ts/dzVents/generated_scripts/Licht Bijkeuken DzVents.lua:13: attempt to compare number with table
User avatar
boum
Posts: 136
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: 2 identical scripts, one works on doesn't?

Post by boum »

Please try:

Code: Select all

return {
    on = {
        devices = {'Lux Bijkeuken', 'Motion Bijkeuken', },
    }

    execute = function(dz, item)
        local LuxBijkeuken = dz.devices('Lux Bijkeuken')
        local MotionBijkeuken = dz.devices('Motion Bijkeuken')
        if MotionBijkeuken.active and LuxBijkeuken.lux < 35 then
            dz.devices('Light Bijkeuken').setLevel(50)
        elseif MotionBijkeuken.state == 'Off' or LuxBijkeuken.lux > 55 then
            dz.devices('Light Bijkeuken').switchOff()
        end
    end
}
dz.devices('bla") returns an object table. You must use a selector to test either the state (.state, .active) or the luminosity (.lux).
In your first change item can be either a lux sensor or a motion sensor. If it is the latest, it won't have a .lux selector.
wouterlet
Posts: 109
Joined: Tuesday 02 October 2018 20:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 2 identical scripts, one works on doesn't?  [Solved]

Post by wouterlet »

Ok, that was the hint!.

Only the Off should be 'Off' Else the light doesn't go off ;)

Thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest