How to dim/brighten RGB strip lights over time

Hi folks,

I have a few RGB light strips hooked up via a wifi controller, and I am controlling them thru node-red/ha.

Is there a routine/method, that I can have the lights slow dim/brighten over time?

For example, if i have a flow that will dim the light strip to 20% brightness over 5 minutes, it would find the current brightness value, find the delta difference, and then gradually decrease that difference over the 5 minute time frame.

I suspect several components would be needed to do this, which would fire an event off to the wifi controllers ever x seconds or so.

has anyone done this yet, or have any pointers?

TIA

This is a very broad question, with a very broad answer: node-red can do it.

There are many ways to do this, with home assistant I don't know because I don't use that, but I can imagine that you can control your wifi controller directly from NR or from HA.

But there is not a "component" that will do this for you because of the many variables that apply.

Questions:

  • Do you "just" want to dim the strip to 20% brightness over 5 minutes or
  • Do you want to sync it to something like sunrise
  • Do you want it to happen on a specific time or via a certain trigger ?

bakman2, thanks for the reply.

In this case, I "just" want to dim the strip to 20% brightness over 5 minutes. Once that's figured out, I can trigger it with various other items in my other nodes.

Simple example:

5 minutes is 300 seconds, send value+1 every 15 seconds, 20 times = 5 minutes and the 20% brightness you should map yourself somewhere towards the striplight.

[{"id":"b1e6a54.d960d58","type":"function","z":"bb6546dd.319b98","name":"","func":"let d = 1\n\ndimmer()\nvar timer = setInterval(dimmer, 15000);\n\nfunction dimmer() {\n  \n  \n   if(d>20){\n      stopDimmer() \n   }\n   else{\n        node.send({payload:{dimmer:d}})\n         d++\n   }\n}\n\nfunction stopDimmer() {\n  clearInterval(timer);\n}","outputs":1,"noerr":0,"x":314,"y":288,"wires":[["5fa67a01.f04a2c"]]},{"id":"1a492d63.f5cd6b","type":"inject","z":"bb6546dd.319b98","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":288,"wires":[["b1e6a54.d960d58"]]},{"id":"5fa67a01.f04a2c","type":"debug","z":"bb6546dd.319b98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":454,"y":288,"wires":[]}]

Have a look at the dsm wiki

or

bakman2, that's exactly what I needed.

I made a few tweaks, as needed, and works perfect, thanks!

In case anyone stumbles on this in the future, here's a bit more coding based around bakman2's original code.

I added in a few variables, and have a few checks and balances going on (it will dim or brighten accordingly).

this is my first chunk of code done in js, so it may not be to best practices...

[{"id":"3ecc6bc2.1b93b4","type":"inject","z":"25593659.aa9afa","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":460,"y":1840,"wires":[["47536eab.c10f9"]]},{"id":"47536eab.c10f9","type":"api-current-state","z":"25593659.aa9afa","name":"Kitchen Upper Status","server":"1e3a8fe9.e93cf","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.kitchen_upper","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":680,"y":1840,"wires":[["3b178f5.58d107"]]},{"id":"3b178f5.58d107","type":"function","z":"25593659.aa9afa","name":"switch to 80% - 5 seconds","func":"var Desired_Brightness_Pct = 80  //key in desired percent value (0-100)\nvar Desired_Time = 5 //transition time in seconds\n\n//do not edit below this line\n\nvar CurrBrightness_Pct = 0\nvar TimerValue = 1\nvar LightStatus = (msg.data.state)\n\nif (LightStatus == \"on\")  \n    {\n        CurrBrightness_Pct = (((msg.data.attributes.brightness)/255*100).toFixed(0))\n    }\n    else\n    {\n        CurrBrightness_Pct =  0\n    }\n\nvar Delta = (Desired_Brightness_Pct - CurrBrightness_Pct)\n\nif(Delta < 0)\n    {\n      TimerValue = ((Desired_Time/(Delta)*-1)*1000) \n    } \n    else\n    {\n      TimerValue = ((Desired_Time/Delta)*1000)\n    }\nlet CBP = CurrBrightness_Pct\n\ndimmer()\nvar timer = setInterval(dimmer, TimerValue);\n\nfunction dimmer() \n{\n    if(Delta > 0)\n        {\n           if(CBP >= Desired_Brightness_Pct)\n           {\n              node.send({payload:{dimmer:Desired_Brightness_Pct}}) \n              stopDimmer() \n           }\n           else\n           {\n                node.send({payload:{dimmer:CBP}})\n                 CBP++\n           }\n        }\n    else\n        {\n            if(CBP <= Desired_Brightness_Pct)\n           {\n              node.send({payload:{dimmer:Desired_Brightness_Pct}})  \n              stopDimmer() \n           }\n           else\n           {\n                node.send({payload:{dimmer:CBP}})\n                 CBP--\n           }\n        }\n        \n}\n\nfunction stopDimmer() {\n  clearInterval(timer);\n}\n\n\n\n","outputs":1,"noerr":0,"x":1050,"y":1860,"wires":[["6aba205d.456ec"]]},{"id":"6aba205d.456ec","type":"api-call-service","z":"25593659.aa9afa","name":"Kitchen Upper (128, 20, 0)","server":"1e3a8fe9.e93cf","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_upper","data":"{\"rgb_color\":[128,20,0],\"brightness_pct\":\"{{payload.dimmer}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1500,"y":1880,"wires":[[]]},{"id":"84fc14af.28e508","type":"inject","z":"25593659.aa9afa","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":460,"y":1980,"wires":[["5bbce65f.5be798"]]},{"id":"5bbce65f.5be798","type":"api-current-state","z":"25593659.aa9afa","name":"Kitchen Upper Status","server":"1e3a8fe9.e93cf","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.kitchen_upper","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":680,"y":1980,"wires":[["a75eb2f0.9500b"]]},{"id":"a75eb2f0.9500b","type":"function","z":"25593659.aa9afa","name":"switch to 20% - 5 seconds","func":"var Desired_Brightness_Pct = 20  //key in desired percent value (0-100)\nvar Desired_Time = 5 //transition time in seconds\n\n//do not edit below this line\n\nvar CurrBrightness_Pct = 0\nvar TimerValue = 1\nvar LightStatus = (msg.data.state)\n\nif (LightStatus == \"on\")  \n    {\n        CurrBrightness_Pct = (((msg.data.attributes.brightness)/255*100).toFixed(0))\n    }\n    else\n    {\n        CurrBrightness_Pct =  0\n    }\n\nvar Delta = (Desired_Brightness_Pct - CurrBrightness_Pct)\n\nif(Delta < 0)\n    {\n      TimerValue = ((Desired_Time/(Delta)*-1)*1000) \n    } \n    else\n    {\n      TimerValue = ((Desired_Time/Delta)*1000)\n    }\nlet CBP = CurrBrightness_Pct\n\ndimmer()\nvar timer = setInterval(dimmer, TimerValue);\n\nfunction dimmer() \n{\n    if(Delta > 0)\n        {\n           if(CBP >= Desired_Brightness_Pct)\n           {\n              node.send({payload:{dimmer:Desired_Brightness_Pct}}) \n              stopDimmer() \n           }\n           else\n           {\n                node.send({payload:{dimmer:CBP}})\n                 CBP++\n           }\n        }\n    else\n        {\n            if(CBP <= Desired_Brightness_Pct)\n           {\n              node.send({payload:{dimmer:Desired_Brightness_Pct}})  \n              stopDimmer() \n           }\n           else\n           {\n                node.send({payload:{dimmer:CBP}})\n                 CBP--\n           }\n        }\n        \n}\n\nfunction stopDimmer() {\n  clearInterval(timer);\n}\n\n\n\n","outputs":1,"noerr":0,"x":1050,"y":2000,"wires":[["98f77cc8.91b4f"]]},{"id":"98f77cc8.91b4f","type":"api-call-service","z":"25593659.aa9afa","name":"Kitchen Upper (128, 20, 0)","server":"1e3a8fe9.e93cf","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_upper","data":"{\"rgb_color\":[128,20,0],\"brightness_pct\":\"{{payload.dimmer}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1500,"y":2020,"wires":[[]]},{"id":"27fa326b.71eb2e","type":"inject","z":"25593659.aa9afa","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":460,"y":2140,"wires":[["c294f4de.9bb518"]]},{"id":"c294f4de.9bb518","type":"api-current-state","z":"25593659.aa9afa","name":"Kitchen Upper Status","server":"1e3a8fe9.e93cf","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.kitchen_upper","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":680,"y":2140,"wires":[["bcf31de.373c9e"]]},{"id":"bcf31de.373c9e","type":"function","z":"25593659.aa9afa","name":"switch to 0% - 5 seconds","func":"var Desired_Brightness_Pct = 0  //key in desired percent value (0-100)\nvar Desired_Time = 5 //transition time in seconds\n\n//do not edit below this line\n\nvar CurrBrightness_Pct = 0\nvar TimerValue = 1\nvar LightStatus = (msg.data.state)\n\nif (LightStatus == \"on\")  \n    {\n        CurrBrightness_Pct = (((msg.data.attributes.brightness)/255*100).toFixed(0))\n    }\n    else\n    {\n        CurrBrightness_Pct =  0\n    }\n\nvar Delta = (Desired_Brightness_Pct - CurrBrightness_Pct)\n\nif(Delta < 0)\n    {\n      TimerValue = ((Desired_Time/(Delta)*-1)*1000) \n    } \n    else\n    {\n      TimerValue = ((Desired_Time/Delta)*1000)\n    }\nlet CBP = CurrBrightness_Pct\n\ndimmer()\nvar timer = setInterval(dimmer, TimerValue);\n\nfunction dimmer() \n{\n    if(Delta > 0)\n        {\n           if(CBP >= Desired_Brightness_Pct)\n           {\n              node.send({payload:{dimmer:Desired_Brightness_Pct}}) \n              stopDimmer() \n           }\n           else\n           {\n                node.send({payload:{dimmer:CBP}})\n                 CBP++\n           }\n        }\n    else\n        {\n            if(CBP <= Desired_Brightness_Pct)\n           {\n              node.send({payload:{dimmer:Desired_Brightness_Pct}})  \n              stopDimmer() \n           }\n           else\n           {\n                node.send({payload:{dimmer:CBP}})\n                 CBP--\n           }\n        }\n        \n}\n\nfunction stopDimmer() {\n  clearInterval(timer);\n}\n\n\n\n","outputs":1,"noerr":0,"x":1050,"y":2160,"wires":[["f7e68c7d.82751"]]},{"id":"f7e68c7d.82751","type":"api-call-service","z":"25593659.aa9afa","name":"Kitchen Upper (128, 20, 0)","server":"1e3a8fe9.e93cf","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_upper","data":"{\"rgb_color\":[128,20,0],\"brightness_pct\":\"{{payload.dimmer}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1500,"y":2180,"wires":[[]]},{"id":"1e3a8fe9.e93cf","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.