global_data function using domoticz.openURL  [Solved]

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

Moderator: leecollings

Post Reply
tonadam
Posts: 16
Joined: Saturday 20 February 2016 12:02
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9999
Location: Amsterdam
Contact:

global_data function using domoticz.openURL

Post 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!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: global_data function using domoticz.openURL

Post 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')
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
tonadam
Posts: 16
Joined: Saturday 20 February 2016 12:02
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9999
Location: Amsterdam
Contact:

Re: global_data function using domoticz.openURL  [Solved]

Post by tonadam »

That did the trick! Many thanks, appreciate your support. :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest