Quick pointer needed on how to code this

core

(Lewis) #1

Hi all, I am trying to use the below code to gradually increase the brightness of my two Philips LED strip lights but can’t figure out what I need to put in where it references the xxxxxxxxx’s.

I tried changing them to the LED strip lights but it generated an error. Assistance would be much appreciated.


(Dave Gutheinz) #2

def fadeIn() {
def increment = 10 // The percent increment per step.

def increment =


(Lewis) #3

Thanks for the info but I have no idea what to do with this could you provide a little more information please?


(Dave Gutheinz) #4

let me think for a while on the code. Basic idea is to use an if loop until the level is at the target. Then use a runIn to recall the if loop. How you would get the target in and out is another item. The below may work.

{USE YOUR DEVICE COMMAND TO SET TO THE INITIAL LEVEL)
def fadeIn() {
def target = 90 // 90 percent target
def increment = 5 // 5 percent per increment
def level = device.latestValue(“level”) // may be a different currentValue for your device
if (level <= target) {
level += increment // Adds 5 to level
{YOUR DEVICE COMMAND TO SET LEVEL)
runIn(20, fadeIn) // will run again in 20 seconds
}
}

}


(Lewis) #5

Thanks i’ll give that a try. This is my first piston that I am working on so struggling a bit with finding the web element that puts in the particular code item.

Is there any way I can directly write the code? Not being able to insert a line is also a bit frustrating at the moment.


(Dave Gutheinz) #6

again, it may not work. Core is a different beast to me.


(Eric) #7

You have X's level is equal to TargetLevel

I don’t think that is ever going to be true.

First it starts out empty so 0. $index is 10 on the first iteration…

when you set the TargetLevel = {{$index}}, the next iteration, TargetLevel will be 10, but $index will be 11.