Error compare number with nil

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

Moderator: leecollings

Post Reply
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Error compare number with nil

Post by kroonp »

Hello, a beginners question.
What do I wrong in this script.
I tried several options but I cant find the correct way.
Thanks in advance.
Peter

Code: Select all

return {
	active = true,
	on = {
    	variables = 
	    { 'situatie' },

		timer = {
			'every minute'
		},
	},

	
  execute = function(domoticz, variable)
	      -- variable is the variable that's triggered
        if (variable.value > 0) then
	    
	    domoticz.devices('Keuken').switchOn() 
		domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
	    end
	end
}
variable
6 situatie Integer 1 2020-07-23 15:39:00


ERROR:
2020-07-23 16:44:00.524 Error: dzVents: Error: (3.0.9) An error occurred when calling event handler 00 var dag nacht
2020-07-23 16:44:00.524 Error: dzVents: Error: (3.0.9) ...r/scripts/dzVents/generated_scripts/00 var dag nacht.lua:15: attempt to compare number with nil
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error compare number with nil

Post by waaren »

kroonp wrote: Thursday 23 July 2020 16:51 What do I wrong in this script.
2020-07-23 16:44:00.524 Error: dzVents: Error: (3.0.9) ...r/scripts/dzVents/generated_scripts/00 var dag nacht.lua:15: attempt to compare number with nil
The second parm of the execute function (in your script named variable) will be a variable when the script is triggered by the variable 'situatie' but every minute it will be a timer (trigger is 'every minute')
Regardless of what triggered it, your script tries to access the attribute value which is available for variables but not for a timer.

Try this

Code: Select all

return
{
    active = true,

    on =
    {
        variables =
        {
            'situatie'
        },

        timer =
        {
            'every minute'
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'variable and timer',
    },

    execute = function(domoticz, item)

        if item.isVariable then
            domoticz.log('Script triggered by variable: "' .. item.name .. '" (value = ' .. item.value .. ')' , domoticz.LOG_DEBUG)
            if item.value > 0 then
				domoticz.log('Value > 0 ==>> switching "keuken" On' , domoticz.LOG_DEBUG)
                domoticz.devices('Keuken').switchOn()
            end
        elseif item.isTimer then
            domoticz.log('Script triggered by timer: "' .. item.trigger ..'"', domoticz.LOG_DEBUG)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Error compare number with nil

Post by kroonp »

I ran the received script. The switch is unfortunately not executed. I don't get an error either. Herewith the log.

2020-07-23 21:01:00.345 Status: dzVents: Info: variable and timer: ------ Start internal script: 00 var dag nacht:, trigger: "every minute"
2020-07-23 21:01:00.345 Status: dzVents: Debug: variable and timer: Script triggered by timer: "every minute"
2020-07-23 21:01:00.345 Status: dzVents: Info: variable and timer: ------ Finished 00 var dag nacht
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Error compare number with nil

Post by waaren »

kroonp wrote: Thursday 23 July 2020 21:06 I ran the received script. The switch is unfortunately not executed. I don't get an error either. Herewith the log.

2020-07-23 21:01:00.345 Status: dzVents: Info: variable and timer: ------ Start internal script: 00 var dag nacht:, trigger: "every minute"
2020-07-23 21:01:00.345 Status: dzVents: Debug: variable and timer: Script triggered by timer: "every minute"
2020-07-23 21:01:00.345 Status: dzVents: Info: variable and timer: ------ Finished 00 var dag nacht
This is intentional. The light will only be switched when the script is triggered by the variable.
From your script I could not determine what the script should do.
Please describe what you expect from the script when you change the value of the var and what your expectation is when the script is triggered by the timer.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Error compare number with nil

Post by kroonp »

Sorry, I didn't know that only changing the variable takes an action. Now that I know that, it is clear to me why the script did not do what I expected. So with your help it is now clear to me and I can move on. Thanks for the support.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest