Page 1 of 1

Write in description Case

Posted: Monday 18 September 2017 22:58
by deennoo
Hi there,

Got some smal skills with LUA and domoticz API, and i don't found how to do what i need, so i'm looking in dz events for this, mayb e away to convert me...let's try.

Working on a script for a esp8266 based module, his goal is to drive french electrique heating using pilot wire.

this module is cloud base, APi is quiete clear and easy to parse :

Get : to retrive Token, Device ID, and actual status
Post : to drive it

Retrive token, stroe it on a uservariable, refresh it every 5 day as asken : no problemo

Get device ID = one per module, no problemo, to be more easy to use i want to store this Device Id on Switch description, then with a device script, when switch is trigger, parsing json, get Device ID, and use it with parsed token from uservariable, will make easier to use for people : just wirte device IDX on script variable, and enjoy.

But how to write on description case ?, using mysql ? ggrr don't like this idea.

Does dz event allow to do this ?

Re: Write in description Case

Posted: Tuesday 19 September 2017 7:36
by dannybloe
For what I know is that you have to use the GUI api to do so as there is no other way that I know of:

This is how I do it in my dzVents integration tests:

Code: Select all

function updateSwitch(idx, name, description, switchType)
	local url = "type=setused&idx=" ..
			tostring(idx) ..
			"&name=" .. name ..
			"&description=" .. description ..
			"&strparam1=&strparam2=&protected=false&" ..
			"switchtype=" .. tostring(switchType) .. "&customimage=0&used=true&addjvalue=0&addjvalue2=0&options="	
	return url		
end

domoticz.openURL(updateSwitch(....))
The only problem is that you have to provide all the parameters for it to work. But all that info is available on the device in dzVents. So, what you could do to make this nice is create a helper function (see doc) and put it in global_data.lua:

Code: Select all

return {
	helpers = {
		updateDescription = function(domoticz, device, description)
			local url = "type=setused&idx=" ..
				tostring(device.id) ..
				"&name=" .. device.name ..
				"&description=" .. description ..
				"&strparam1=&strparam2=&protected=false&" ..
				"switchtype=" .. tostring(device.switchType) .. "&customimage=0&used=true&addjvalue=0&addjvalue2=0&options="
			domoticz.openURL(url)
		end
	}
}
Then in your event script you can do this:

Code: Select all

return {
	...
	execute = function(domoticz, device)
		domoticz.helpers.updateDescription(domoticz, device, 'My new description')
	end
}
One note though.. I suspect this doesn't work with all devices as some devices need more parameters to be sent to the 'setused' api. I have tested this only with switches. But with a little trial and error you can get this to work.

Re: Write in description Case

Posted: Tuesday 19 September 2017 8:01
by deennoo
Ok, thanks.

The same Can be done with lua and parsing value...surely more complexe.

That an hard solution for people who start with Domoticz. Idea was to make it easy.

Other solution is to provied à python script