Author Topic: Dimmer Step up script  (Read 402 times)

Offline Priest

  • Full Member
  • ***
  • Posts: 142
  • Karma: +5/-0
Dimmer Step up script
« on: April 02, 2017, 04:54:15 pm »
I've had a workin Vera 3 for quite some time now. At my old house I had quite a few switches, outlets, etc installed plus a thermostat.  I had basic scenes set up that I never did any scene scripting manually. I just plugged in through the interface so that when the door was unlocked by a code, turn on the light....etc.  I got a couple of the 7 button scene controllers and made them run scenes and that was it. When we moved at the end of 2015 to the new house, everything but the Vera and 1 plug in dimmer got lost.  I have now found most of it and am playing with this again.  The entire Vera interface has changed on me so none of it looks very familiar at all.

I've installed one of the 7 button scene controllers and have two buttons set up with a "step up" and "step down" script I found on the forum...and it works. this is the "step up" one as it is entered in my system. It is only slightly modified from how I found it.

Quote
local dID =23
local level = tonumber(luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",dID),15)
if level < 100 then
     if level <= 85 then level = level + 15 else level = 100 end
     local args = {}
     args["newLoadlevelTarget"] = level
     luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", args, dID)
end

What I am trying to accomplish now is to make it so that if the light is off or below 5% dim for the first step to go to 5%. From there I want every button push to step up like in the code above.  I've tried this about 10 different ways from all kinds of parts an peices I found on the forum and every one of them gives me a LUA error after saving.

So...this is what I've got in right now....and I cant figure out what I'm doing wrong.

Quote
local dID =23
local level = tonumber(luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",dID),15)
if level < 5 then level = 5
elseif level >= 85 then level = 100
else level = level +15 end
     local args = {}
     args["newLoadlevelTarget"] = level
     luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", args, dID)
end

I know I have much to learn. But in this house I want to do a lot of scripting to make the house work a lot better.  I had downloaded PLEG previosly...but I cant even figure out how to open it now that the whole interface has changed.  I dont know how to use it yet either, so it doesnt really help.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 537
  • Karma: +29/-2
Re: Dimmer Step up script
« Reply #1 on: April 02, 2017, 05:57:00 pm »
If I add some indents to your code (no change to functionality)
Code: [Select]
local dID =23
local level = tonumber(luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus",dID),15)

if level < 5 then
  level = 5
elseif level >= 85 then
  level = 100
else
  level = level +15
end

-- below not part of the if
     local args = {}
     args["newLoadlevelTarget"] = level
     luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", args, dID)

-- the 'end' below is hanging loose
end
Looks to me like you either want to remove that hanging "end" which doesn't belong, or you may want to enclose the code above with an "if then" if you need some logic there.  I think you probably don't need it, so you can just remove the 'end'.

Offline Priest

  • Full Member
  • ***
  • Posts: 142
  • Karma: +5/-0
Re: Dimmer Step up script
« Reply #2 on: April 02, 2017, 07:57:19 pm »
I was copying the format of the working one above that I got from the forum. I'll try your suggestion in just a bit and see if it errors on me

Offline Priest

  • Full Member
  • ***
  • Posts: 142
  • Karma: +5/-0
Re: Dimmer Step up script
« Reply #3 on: April 02, 2017, 09:21:46 pm »
That did fix it.  I have now made some slight adjustments to it, and made a step down one that works as well.

Thank you.