Page 1 of 1

global_data function using domoticz.openURL

Posted: Wednesday 17 February 2021 16:33
by tonadam
Want to create a function to set the CV temperature. As I need this in a couple of scripts. Via the WebGUI I created a dzevents file called: "global_data". It's being saved to: scripts/dzVents/generated_scripts/global_data.lua.

global_data.lua:

Code: Select all

-- this scripts holds all the globally persistent variables and helper functions

return {
	helpers = {
	    
	    -- Functie op temperatuur te zetten
		SETCV = function(GEWENSTETEMP)
			local CVHOSTNAME='192.168.0.20'
		        local SETPOINT=GEWENSTETEMP*10-50
                        local CVURL='http://'..CVHOSTNAME..'/data.json?heater=0&setpoint='..SETPOINT
            
                        print('Verwarming wordt gezet naar: '..GEWENSTETEMP..' graden middels URL: '..CVURL)
                        domoticz.openURL(CVURL)
		end
		
		
	}
}
Executing this from another DzEvents script:

Code: Select all

domoticz.helpers.SETCV('20')
It works, until it hits: 'domoticz.openURL(CVURL)'. (line 13)
2021-02-17 16:28:00.496 Status: dzVents: Info: ------ Start internal script: TEST:, trigger: "every 1 minutes"
2021-02-17 16:28:00.496 Status: dzVents: Verwarming wordt gezet naar: 20 graden middels URL: http://192.168.0.20/data.json?heater=0&setpoint=150.0
2021-02-17 16:28:00.496 Error: dzVents: Error: (3.1.4) An error occurred when calling event handler TEST
2021-02-17 16:28:00.496 Error: dzVents: Error: (3.1.4) ....12934/scripts/dzVents/generated_scripts/global_data.lua:13: attempt to index a nil value (global 'domoticz')
2021-02-17 16:28:00.497 Status: dzVents: Info: ------ Finished TEST
Does anybody understand why I'm getting the "nil value" error. Also tried "openURL(CVURL)", and even hardcoding the URL, but it always comes back with that error.

Thanks!

Re: global_data function using domoticz.openURL

Posted: Wednesday 17 February 2021 17:24
by waaren
tonadam wrote: Wednesday 17 February 2021 16:33 Does anybody understand why I'm getting the "nil value" error. Also tried "openURL(CVURL)", and even hardcoding the URL, but it always comes back with that error.
If you need to access anything (vars, tables or functions) of the domoticz object you need to parse the domoticz object to your helper function.

change

Code: Select all

		SETCV = function(GEWENSTETEMP)
to

Code: Select all

		SETCV = function(domoticz, GEWENSTETEMP)
and

Code: Select all

domoticz.helpers.SETCV('20')
to

Code: Select all

domoticz.helpers.SETCV(domoticz,'20')

Re: global_data function using domoticz.openURL  [Solved]

Posted: Wednesday 17 February 2021 20:12
by tonadam
That did the trick! Many thanks, appreciate your support. :-)