dzVents triggering on the change of user variables and text devices

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

Moderator: leecollings

Post Reply
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

dzVents triggering on the change of user variables and text devices

Post by BakSeeDaa »

Domoticz normally won't trigger on the change of user variables and text devices. I recall that I read somewhere that the reason for that is that it would opening up for users to create "nasty loops".

Please correct me if I'm wrong. ;)

The above behavior can be circumvented simply by using an API call instead.

I read in the dzVents release notices that
Fixed setting uservariables. It still uses json calls to update the variable in Domoticz otherwise you won't get uservariable event scripts triggered in dzVents.
I assume (without testing it) that means that the dzVents statement

Code: Select all

domoticz.variables('anotherVar').set('Hello')
will allow other scripts triggering upon the resulting change of that user variable while as the Domoticz vanilla LUA statement

Code: Select all

commandArray['Variable:anotherVar']='Hello' 
won't let other scripts trigger upon the change.

When it comes to text devices, dzVents has a different approach. Here it's treated equal to the Domoticz vanilla, so that the change caused by

Code: Select all

device('myTextSensor').updateText('Hello')
can not be triggered by any script.

I frequently use "Text Devices" in my dzVents script and I always want other scripts to be able to trigger upon the changes. Therefore I use a custom helper function to set text devices. It works great.

Has there been any thoughts about why dzVents is not using API calls also for Text devices similar as API calls are used for user variables?

Cheers!
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents triggering on the change of user variables and text devices

Post by dannybloe »

Ah.. for variables dzVents already uses the json API just to make sure your events are indeed triggered. I didn't know it was needed for text devices as well. I just fixed that.
And the looping problem is kinda nonsense as you can have loops with switches just as easily. It's up to the user to not create loops. But you'll see it quickly enough in the logs or when domoticz stops responding or the GUI :)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: dzVents triggering on the change of user variables and text devices

Post by BakSeeDaa »

dannybloe wrote:I didn't know it was needed for text devices as well. I just fixed that.
Wow, that's really great! Thanks a million times! :D

You probably already thought of URLEncoding the svalue parameter too ;)

Just curios, will the following work also?

Code: Select all

device('myTextSensor').updateText('Hello').afterSec(10)
I'm currently using a similar construction in my dzVents alarm script where I have a text device for the "status" of the alarm. It's not relevant for this topic but below is my script that I use meanwhile ...

global_data.lua

Code: Select all

local domoticzHost = '127.0.0.1'
local domoticzPort = '8080'

-- Interact with all switches and sensors using JSON with an optional delay argument
local function jsonAPI(apiCall, delay)
	delay = delay or 0
	local url = 'http://'..domoticzHost..':'..domoticzPort..'/json.htm?'
	os.execute('(sleep '..delay..';curl -s "'..url..apiCall..'" > /dev/null)&')
end

local function urlEncode(str)
	if (str) then
		str = string.gsub (str, '\n', '\r\n')
		str = string.gsub (str, '([^%w ])',
		function (c) return string.format ('%%%02X', string.byte(c)) end)
		str = string.gsub (str, ' ', '+')
	end
	return str
end

return {
	data = {
	},
	helpers = {

		-- Safety pig has arrived!
		--
		--  _._ _..._ .-',     _.._(`))
		-- '-. `     '  /-._.-'    ',/
		--    )         \            '.
		--   / _    _    |             \
		--  |  a    a    /              |
		--  \   .-.                     ;  
		--   '-('' ).-'       ,'       ;
		--      '-;           |      .'
		--         \           \    /
		--         | 7  .__  _.-\   \
		--         | |  |  ``/  /`  /
		--        /,_|  |   /,_/   /
		--           /,_/      '`-'
		--
		-- MY OWN HELPER FUNCTIONS
	
		setTextDevice = function(idx, sValue, delay)
			delay = delay or 0
			jsonAPI('type=command&param=udevice&idx='..idx.."&nvalue=0&svalue="..urlEncode(sValue), delay)
		end,
	}
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents triggering on the change of user variables and text devices

Post by dannybloe »

Yes, you can use domoticz.openURL() though.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest