Page 1 of 1

What is wrong

Posted: Friday 09 September 2022 9:37
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
}

Re: What is wrong

Posted: Friday 09 September 2022 10:06
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
		 }

Re: What is wrong  [Solved]

Posted: Friday 09 September 2022 10:33
by boum

Code: Select all

execute = function(domoticz)
should be

Code: Select all

execute = function(domoticz, timer)