First plugin and first blocking problem

hello

i’am trying to do my first plugin to manage KNX gateway

it’s a plugin with child, i wrote it following the walkthrough here http://wiki.micasaverde.com/index.php/Luup_Somfy_Walkthrough

in my implementation file i have the following action

urn:upnp-org:serviceId:SwitchPower1 SetTarget local lul_prefix = luup.variable_get("urn:geo6-net:serviceId:KNX1", "UrtsiId", lul_device) local lul_command = lul_prefix .. luup.devices[lul_device].id .. 'U\r' local lul_reverse = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "ReverseOnOff", lul_device)
    if (lul_settings.newTargetValue == "1" or (lul_settings.newTargetValue == "0" and lul_reverse == "1")) then
      lul_command = lul_prefix .. luup.devices[lul_device].id .. 'D\r'
    end

    if (luup.io.write(lul_command) == false) then
      luup.log("cannot send: " .. tostring(lul_command),1)
      luup.set_failure(true)
      return false
    end
  </run>
</action>

but when i launch it i obtain

LuaInterface::CallFunction-1 device 12 function SSwitchPower1_SwitchPower1_SetTarget_run failed [string “…”]:40: attempt to concatenate local ‘lul_prefix’ (a nil value) <0x580c>

any idea ?

thanks for your help

Probably the UrtsiId variable is not initialized anywhere. Usually this is done in the startup function.

It is recommended to assign a default value to a variable in case it doesn’t exist, like this:

local lul_prefix = luup.variable_get ("urn:geo6-net:serviceId:KNX1", "UrtsiId", lul_device) or "something"

So if luup.variable_get returns nil, the lul_prefix will be “something”.

An alternative will be to use the tostring() function. tostring converts the nil values to the “nil” string.

local lul_command = tostring (lul_prefix) .. luup.devices[lul_device].id .. 'U\r'

Also, luup.devices.id contains a device’s altid, which is the Z-Wave node ID in the case of Z-Wave devices, or the Insteon ID in the case of Insteon devices. If you want the device ID (device number) you should use lul_device. So your code will look like this:

local lul_command = lul_prefix .. lul_device .. 'U\r'