dzVents: Interact with all switches and sensors using JSON with an optional delay argument

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: Interact with all switches and sensors using JSON with an optional delay argument

Post by BakSeeDaa »

This is a primarily a question for the author @dannybloe

Wouldn't it be nice to incorporate the following into Domoticz.lua ?

Some devices like the RGBW device seems to work best if controlled by API/Json URL commands. The small function below would help doing those commands and it also allows a delay (seconds).

Code: Select all

	-- Interact with all switches and sensors using JSON with an optional delay argument
	function self.jsonAPI(apiCall, delay)
		delay = delay or 0
		local url = 'http://'..self.settings['Domoticz ip']..':'..self.settings['Domoticz port']..'/json.htm?'
		if delay == 0 then
			self.sendCommand('OpenURL', url..apiCall)
		else
			os.execute('(sleep '..delay..';curl -s "'..url..apiCall..'" > /dev/null)&')
		end
	end
I can make a pull request if you think this is useful ...

For controlling my RGBW ligt, it's essential for me. A pause of a few seconds seems needed after turning of a animation program and switching to a fixed color.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: dzVents: Interact with all switches and sensors using JSON with an optional delay argument

Post by BakSeeDaa »

Another useful thing is if You would like to trigger on the text change of a virtual text device. If You are using the traditional commandarray to change the text device, the change won't be triggered by scripts. However if You use a API/Json URL command changes of the text device can be triggered in scripts.

I use the code below:

Code: Select all

	function self.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

	-- Setting text devices the "Normal" way doesn't cause changes to be triggered.
	function self.setTextDevice(idx, sValue)
		self.jsonAPI('type=command&param=udevice&idx='..idx.."&nvalue=0&svalue="..self.urlencode(sValue))
	end
Just some ideas ;) ;)

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

Re: dzVents: Interact with all switches and sensors using JSON with an optional delay argument

Post by dannybloe »

Without looking at my code I believe there are already some devices in dzVents that work like this. Can you put a ticket in the tracker? In the coming weeks I will be continuing fixing/adding stuff to dzVents.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
digimate
Posts: 19
Joined: Tuesday 02 February 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: lastbeta
Contact:

Re: dzVents: Interact with all switches and sensors using JSON with an optional delay argument

Post by digimate »

dannybloe wrote:In the coming weeks I will be continuing fixing/adding stuff to dzVents.
Thanks in advance Danny! Great job your dzVents!!
Synology DS716+. Domotica devices (on about 30): KaKu (and other 433MHz devices), Z-Wave, Mi-Light, Xiaomi.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest