luup code to open sunblinds

My sunblinds (Jaloezie in Dutch) goes up and down between 0 - 100%

When I want to open the sunblinds I need to increase the absolute value with 5%.

For example: sunblinds down, set the slider to 50%. When the sunblinds are stopped,
activate a scene to open the sunblinds to 45%.

I guess the scene code to relative increase the sunblinds with 5% would be something like this:

local lightLevel = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 6)

luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = {“local lightlevel” + “5”}}, 6)

who can help me with the right code? thanks

Hi

You just need to remove the “local” in the argument part of the luup.call_action part, because you’ve declared it local before in the code. You need to remove the double quote in the arguments because you are math adding to string part, it is not correct.

luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = {lightlevel + 5}}, 6)

Close … Actually you need:

luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = tonumber(lightlevel) + 5}, 6)

This opens 5% of full.
If you wanted 5% of current value the math for the new value would be:

math.ceil(1.05 * tonumber(lightlevel))

Do you need tonumber? Wouldn’t the built in coercion work it out in this case?

As a software developer I do not depend on coercion to work.

I know that the return value from luup.variable_get is a string and I want to do numeric operations on it. I do not have to remember where automatic coercion is done. It does not work everywhere … i.e. it does not work for comparisons. Not all functions will do a string to number coercion of their arguments where numbers are expected.

LOL, yes, that’s probably wise :wink:

thanks, I have tried this code now:

local lightLevel = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 6)

luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = tonumber(lightlevel) + 5}, 6)

the scene is executing but nothing happens on the FGR roller shutter #6

do you have some other suggestions?

Is it that your variable is lightLevel but you are then using lightlevel?

The right code is:

local lightLevel = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 6)

luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = tonumber(lightLevel) + 5}, 6)

small mistake with capital in lightLevel

Thank you all