What is wrong  [Solved]

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

Moderator: leecollings

Post Reply
pipiche
Posts: 2027
Joined: Monday 02 April 2018 20:33
Target OS: Linux
Domoticz version:

What is wrong

Post by pipiche »

I'm getting this error, and I do not understand what I'm doing wrong ?

Ligne 26 is if prise.state == 'Off' and (timer.trigger == START_TIME ) then
Sep 09 09:30:02 pi3 domoticz[23326]: 2022-09-09 09:30:02.201 Status: dzVents: Info: ------ Start external script: recharge-aspirateur.lua:, trigger: "every 5 minutes"
Sep 09 09:30:02 pi3 domoticz[23326]: 2022-09-09 09:30:02.201 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler recharge-aspirateur
Sep 09 09:30:02 pi3 domoticz[23326]: 2022-09-09 09:30:02.201 Error: dzVents: Error: (3.1.8) /var/lib/domoticz/scripts/dzVents/scripts/recharge-aspirateur.lua:26: attempt to index a nil value (global 'timer')
Sep 09 09:30:02 pi3 domoticz[23326]: 2022-09-09 09:30:02.201 Status: dzVents: Info: ------ Finished recharge-aspirateur.lua

Code: Select all

local GENERAL = 'Grenoble General'
local PRISE = 'Prise Aspirateur'
local CONSO = 'Prise Aspirateur Power'
local START_TIME = 'at 01:00'
local LOGGING = false

return {
	active = true,
	on = {
		['timer'] = {
			'every 5 minutes',  -- checking if we are still charging
			START_TIME          -- switch on the plug
		 }
	},

	execute = function(domoticz)
		local prise = domoticz.devices( PRISE )
		local power = domoticz.devices( CONSO )
		local general = domoticz.devices( GENERAL )

		if LOGGING then
			domoticz.log('Prise State: ' .. prise.state .. ' LastUpdate: ' .. prise.lastUpdate.minutesAgo .. ' Power: ' .. power.actualWatt .. ' Trigger: ' .. timer.trigger)
		end

		if general.bState then
			if prise.state == 'Off' and (timer.trigger == START_TIME ) then
				-- Check if it is time to start the plug
				if LOGGING then domoticz.log('Lancement de la Recharge') end
				prise.switchOn()

			elseif prise.state == 'On' and prise.lastUpdate.minutesAgo > 7 and power.actualWatt < 5 then
				-- Leave time for the Power to be reported
				-- and finaly if we have only small power then stop the plug
				if LOGGING then domoticz.log('Recharge terminée')end
				prise.switchOff()
			end
		end
	end
}
willemd
Posts: 741
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: What is wrong

Post by willemd »

In the "On" section, why is your timer between [] and '' ?

Code: Select all

['timer'] = {
			'every 5 minutes',  -- checking if we are still charging
			START_TIME          -- switch on the plug
		 }
instead of

Code: Select all

timer = {
			'every 5 minutes',  -- checking if we are still charging
			START_TIME          -- switch on the plug
		 }
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: What is wrong  [Solved]

Post by boum »

Code: Select all

execute = function(domoticz)
should be

Code: Select all

execute = function(domoticz, timer)
Post Reply

Who is online

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