property zwave encode
Posted: Monday 03 February 2020 10:03
Hi ,
I try to improve my zwave config script. Changing my old function(zet_zwave_alarm) to a new function(applyzwavenodeconfig) that uses logical names instead off codes.
It does work perfect, but still some questions (one by one)
1. In my function i use the idx off the zwave device, i use 7 for the idx and 7 is also the id off the parameter in the zwave siren.
When you look at my zwave config (see attachment, you can see that my zwave id =15, how is that possible, that this even works!?
And this is my domoticz database , zwave part that explains more...
I try to improve my zwave config script. Changing my old function(zet_zwave_alarm) to a new function(applyzwavenodeconfig) that uses logical names instead off codes.
It does work perfect, but still some questions (one by one)
1. In my function i use the idx off the zwave device, i use 7 for the idx and 7 is also the id off the parameter in the zwave siren.
When you look at my zwave config (see attachment, you can see that my zwave id =15, how is that possible, that this even works!?
Code: Select all
local scriptVar = 'zwaveresponce'
-- url's afvangen met f12 network in zwave panel door beide settings alarm en doorbell af te vangen en te knippen en plakken
-- https://www.base64encode.org/ (encode/decode base = moet %3D zijn
return
{
on = {devices = {'sirene_cfg'}},
httpResponses = {scriptVar},
logging = {level = domoticz.LOG_ERROR},
execute = function(dz, item)
_G.logMarker = _G.moduleLabel
local function zet_zwave_alarm(alarm_type)
local zwaveURL_start = 'http://192.168.20.35:82/json.htm?type=command¶m=applyzwavenodeconfig&idx=7&valuelist='
local zwaveURL_begin = '7_'
local zwaveURL_end = '_'
local alarm_types = { sirene = 'QWxhcm0gbXVzaWM%3D', doorbell = 'RG9vciBiZWxsIG11c2lj',}
local zwaveURL = zwaveURL_start .. zwaveURL_begin .. alarm_types[alarm_type] .. zwaveURL_end -- only nr 7 is changed, rest is for so far hard coded
dz.openURL({url = zwaveURL, callback = scriptVar})
end
function applyzwavenodeconfig(dz, deviceidx, parameteridx, value)
local server = 'http://192.168.20.35:82'
local encoded_value = dz.utils.urlEncode(dz.utils.toBase64(value))
local url = server .. '/json.htm?type=command¶m=applyzwavenodeconfig&idx=' .. tostring(deviceidx) .. '&valuelist=' .. tostring(parameteridx) .. '_' .. encoded_value .. '_'
dz.log('Opening URL: '..url)
local handle = io.popen('curl "'..url..'"')
local result = handle:read("*a")
handle:close()
dz.log(result)
end
if (item.isDevice) then
if (item.state == 'sirene') then
applyzwavenodeconfig(dz, 7, 7, "Alarm music")
--zet_zwave_alarm('sirene')
elseif (item.state == 'deurbel') then
applyzwavenodeconfig(dz, 7, 7, "Door bell music")
-- zet_zwave_alarm('doorbell')
elseif (item.state == 'uit') then
dz.devices('binnenalarm').switchOff() --.repeatAfterSec(0, 2)
else
dz.log('There was a problem handling the state, state: ' .. item.state, dz.LOG_ERROR)
end
elseif item.isHTTPResponse and item.ok then -- do i need item.ok ???
if not(item.isJSON) then item.json = dz.utils.fromJSON(item.data) end
rt = item.json
if rt.status == 'OK' then
-- hier switch aanzetten en log met data bekijken dit hele script moet een global functie worden
else
dz.log('There was a problem handling the request; response is ' .. item.data, dz.LOG_ERROR)
end
else
dz.log('There was a problem the device type... ', dz.LOG_ERROR)
end
end
}