PCF9685 Dimmen slow

#2

what is your flow?
How do you have your slider set up?

#3

It is not clear exactly what the problem is with the slider. Can you explain a bit more?

#4

Hello and thanks for the quick reply.
I set it up like this.

[{"id":"100823ba.fc696c","type":"PCA9685 out","z":"a945a343.02499","name":"PWM Output 0 (Led)","pca9685":"27d30447.9cc9ec","channel":"0","payload":"","unit":"percent","onStep":"0","x":633,"y":630,"wires":[],"icon":"node-red/light.png"},{"id":"bb11f48e.8d6398","type":"ui_button","z":"a945a343.02499","name":"","group":"420d5227.34751c","order":6,"width":"2","height":"1","passthru":false,"label":"button","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":252,"y":587,"wires":[["658c757f.01663c"]]},{"id":"658c757f.01663c","type":"ui_slider","z":"a945a343.02499","name":"","label":"LED Blau","group":"420d5227.34751c","order":5,"width":"24","height":"1","passthru":true,"topic":"","min":0,"max":"50","step":1,"x":403,"y":587,"wires":[["100823ba.fc696c"]]},{"id":"f0780828.f7d738","type":"light-scheduler","z":"a945a343.02499","settings":"52fb5c40.a28814","events":"[{"start":{"dow":1,"mod":420},"end":{"dow":1,"mod":1200}},{"start":{"dow":2,"mod":420},"end":{"dow":2,"mod":1200}},{"start":{"dow":6,"mod":420},"end":{"dow":6,"mod":1200}},{"start":{"dow":0,"mod":420},"end":{"dow":0,"mod":1200}},{"start":{"dow":5,"mod":420},"end":{"dow":5,"mod":1200}},{"start":{"dow":4,"mod":420},"end":{"dow":4,"mod":1200}},{"start":{"dow":3,"mod":420},"end":{"dow":3,"mod":1200}}]","topic":"","name":"Sunrise","onPayload":"10","onPayloadType":"num","offPayload":"OFF","offPayloadType":"str","onlyWhenDark":false,"sunElevationThreshold":6,"sunShowElevationInStatus":true,"outputfreq":"output.minutely","x":406,"y":640,"wires":[["100823ba.fc696c"]]},{"id":"27d30447.9cc9ec","type":"PCA9685","z":"","deviceNumber":"1","address":"64","frequency":"50"},{"id":"420d5227.34751c","type":"ui_group","z":"","name":"Default[Home]","tab":"f4e14fb.64ba0b","disp":true,"width":"24","collapse":true},{"id":"52fb5c40.a28814","type":"light-scheduler-settings","z":"","name":"Arnstadt","latitude":"50.840914","longitude":"10.9505322"},{"id":"f4e14fb.64ba0b","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}]

If I move the slider to a different position, the brightness of the light changes abruptly.
I want it to change slowly, much like a sunrise.

greetings
André

Step down number increments over time node red dimming
#5

This sounds like an interesting little "smoothing" problem to solve...

Essentially, you have two (possibly) different light level values: the current level (of the light) and the target level (as defined by the slider). You also have some desired max change rate when moving from the current level to the target level. Sounds like a PID or PWM node to me -- but I only recognize that because of what I've learned from this recent discussion thread between Charles and Colin on how to control the brewing process. So I'd be really interested to hear from them whether similar techniques would work in this situation.

I guess my simple-minded approach would be to have a function node with the 2 input topics (current and target), which outputs either a current + 1 or current - 1 value depending on whether the target was higher or lower than the current value. Feed that into a delay node and then back to the input of the function node. When the two values are the same, there would be no output.

#6

I think it is simpler than that, I think you just need a slew rate limit. Surprisingly I can't see one on flows.nodered.org, though I may be using the wrong key words. I have a function node that does it but it relies on regular messages coming in which is not what we have here.

#7

I've solved a similar problem using my node-red-contrib-dsm node.
I'd post the flow if requested.

Error-circular - where is this coming from?
#8

Please do -- after posting, I wondered if a state machine would be overkill for this or not...

#9

Please import the flow from the Github Wiki: Fading

Generally there are a huge of state-machine solutions.
One of them I like: javascript-state-machine

#10

I think this is a simpler solution using a function node.

[{"id":"5f8de1b.3f7c8a","type":"function","z":"6dc690a3.1abc88","name":"Slew rate limit","func":"// Limits the slew rate incoming payload values\nvar maxRate = 60  ;         // max slew rate units/minute\nvar period = 1000;          // period in millisecs to send new values, 1000 is 1 per second\n\nvar newValue = Number(msg.payload);\nvar timer = context.get('timer') || 0;\n// check the value is  a number\nif (!isNaN(newValue) && isFinite(newValue)) {\n    var target = msg.payload;\n    context.set('target', target);\n    // set last value to new one if first time through\n    var lastValue = context.get('lastValue');\n    if (typeof lastValue == \"undefined\" || lastValue === null) {\n        lastValue = newValue;\n        context.set('lastValue', newValue)\n    }\n    // calc new value\n    msg.payload = calcOutput();\n    // stop and restart the timer\n    if (timer) {\n        clearTimeout(timer);\n        context.set('timer', null);\n    }\n    timer = setInterval(function(){\n        // the timer has run down calculate next value and send it\n        var newValue = calcOutput();\n        if (newValue != context.get('lastValueSent')) {\n            context.set('lastValueSent', newValue)\n            node.send({payload: newValue});\n        }\n    },period);\n    context.set('timer', timer);\n    context.set('lastValueSent', msg.payload);\n} else {\n    // payload is not a number so ignore it\n    msg = null;\n}\nreturn msg;\n\n// determines the required output value\nfunction calcOutput() {\n    var lastValue = context.get('lastValue');\n    var target = context.get('target');\n    // set to current value if first time through\n    if (typeof lastValue == \"undefined\" || lastValue === null) lastValue = newValue;\n    var now = new Date();\n    var lastTime = context.get('lastTime') || now;\n    // limit value to last value +- rate * time\n    var maxDelta = (now.getTime() - lastTime.getTime()) * maxRate / (60 * 1000);\n    if (target > lastValue) {\n        newValue = Math.min( lastValue + maxDelta, target);\n    } else {\n        newValue = Math.max( lastValue - maxDelta, target);\n    }\n    context.set('lastValue', newValue);\n    context.set('lastTime', now);   \n    return newValue;\n}","outputs":1,"noerr":0,"x":433,"y":232,"wires":[["fb203846.5494b"]]},{"id":"fb203846.5494b","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650.5,"y":231,"wires":[]},{"id":"df5dd6ab.d3bdd","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":159.5,"y":176,"wires":[["5f8de1b.3f7c8a"]]},{"id":"2a7e98bc.cd7f18","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":158,"y":237,"wires":[["5f8de1b.3f7c8a"]]},{"id":"381ece91.b0c4a2","type":"ui_slider","z":"6dc690a3.1abc88","name":"","label":"slider","group":"41737f1.c5e588","order":0,"width":0,"height":0,"passthru":false,"topic":"","min":0,"max":"10","step":1,"x":172.5,"y":304,"wires":[["5f8de1b.3f7c8a"]]},{"id":"41737f1.c5e588","type":"ui_group","z":"","name":"Default","tab":"bb9b58bd.29621","disp":true,"width":"6"},{"id":"bb9b58bd.29621","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
#11

Hello

many thanks for the help.
The code is very good.
I tried to experiment with it.
Unfortunately, it still dimms visibly halting.
How can I create a gentle dimming?
I also tried to bind light scheduler with. Unfortunately, this is on payload. Do I have to change that in the script?

greetings
André

#12

Which code do you mean? If you mean mine then as posted it sends a new value every second. If it is the 1 second changes that you don't like then you can change the period by changing the line at the front of the function. You could change it to 250 msec for example.
I don't know what you mean by 'tried to bind light scheduler with'.

#13

Hello Collin

I meant your code.
I can not handle the commands yet.
Maybe a picture says more because my english is bad and google does not translate so well.

greetings

André

led

#14

Sorry, I don't know what the question is.

#15

Hello Colin

I'll try to explain it.
I would like to equip my marine aquarium with a LED lighting. I have already built the lighting for it.
Now I want to set the LED's depending on the color to different values ​​and then dimm as long as possible up or down.
Hold like a realistic sun.
I wanted to add the moon later. For this I have installed ws2812 LED Stripe. I would be enough if the "sun" would go.

greetings

André

#16

Split the problem into small parts. Get them working one bit at a time.

#17

hello how do i reset the timer to a null value

#18

You flow is not importable. Please see this post for how to correctly format flows on the forum.


You can go back and edit the previous post.

#19

Just realised you have not posted a new flow but just referenced mine. I will have to go back and remind myself what it is all about......

#20

OK, have looked at the flow again, and I don't understand your question.

#21

say it counts down and i wont it to count up 255 but the brightness payload is 166 it will only count to 166 from previous 0

i have added a delay in parallel with a 1 second delay to send an 0 or 255 payload to overcome this now

thank you for the reply