Okey dokey.
So hopefully you can make sense of this.
I have two subflows. 1 is for rooms with colour temperature changing lights and adds a long press to the rotary encoder that switches to colour change mode instead of brightness. This is what my main flow looks like:
The brains for the rotary adjustment is in the dimmerControl subroutine. This has some hopefully self explanatory environmental variables:-
Then these are passed into the subflow:-
The magic happens at the top with the debounce node in combination with a counter. It’ll pass a number of how many times it’s been rotated in 250ms through the flow. The rest of the flow handles the environmental variables and then increments or decrements the brightness. It’ll stop at the max brightness set in the environmental variable and turn the light off if it hits minimum brightness.
Here’s the subflow:-
[{"id":"f4daa825.5dd3f8","type":"subflow","name":"dimmerControl (no colour)","info":"","category":"","in":[{"x":40,"y":80,"wires":[{"id":"2af0480a.6ebf38"}]}],"out":[],"env":[{"name":"light","type":"str","value":""},{"name":"brightstep","type":"num","value":"5"},{"name":"brightmin","type":"num","value":"5"},{"name":"brightmax","type":"str","value":"255"}],"color":"#DDAA99"},{"id":"2af0480a.6ebf38","type":"counter","z":"f4daa825.5dd3f8","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":180,"y":80,"wires":[["ce11729f.961e3"]]},{"id":"aa88fac1.a39c28","type":"debounce","z":"f4daa825.5dd3f8","time":"250","name":"debounce","x":520,"y":80,"wires":[["2b2bdf57.7b2f3","c536d7.0e53b928"]]},{"id":"2b2bdf57.7b2f3","type":"change","z":"f4daa825.5dd3f8","name":"reset count","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":80,"wires":[["2af0480a.6ebf38"]]},{"id":"ce11729f.961e3","type":"switch","z":"f4daa825.5dd3f8","name":"if non-zero","property":"count","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":80,"wires":[["aa88fac1.a39c28"]]},{"id":"b7c452a6.45573","type":"comment","z":"f4daa825.5dd3f8","name":"How many times have we moved in 250ms interval?","info":"","x":310,"y":40,"wires":[]},{"id":"992273c2.55bc","type":"api-current-state","z":"f4daa825.5dd3f8","name":"Current state - light","server":"e733376d.c37508","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"${light}","state_type":"str","state_location":"state","override_payload":"msg","entity_location":"lightdata","override_data":"msg","blockInputOverrides":false,"x":230,"y":280,"wires":[["5d3ed6e8.5482c8"]]},{"id":"5d3ed6e8.5482c8","type":"function","z":"f4daa825.5dd3f8","name":"Increment or Decrement?","func":"if (Number(msg.data.old_state.state) < Number(msg.data.new_state.state)) {\n return [ msg, null ];\n} else {\n return [ null, msg ];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":450,"y":360,"wires":[["92e9856d.0fee18"],["4fbf4574.3ea10c"]]},{"id":"2ec45dd6.827172","type":"change","z":"f4daa825.5dd3f8","name":"+ brightness","rules":[{"t":"set","p":"lightdata.attributes.brightness","pt":"msg","to":"$min([$number(lightdata.attributes.brightness + ($number(env.brightstep)*count)), $number(env.brightmax)])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":500,"wires":[["73047e8d.2f322"]]},{"id":"4fdc3278.fd253c","type":"change","z":"f4daa825.5dd3f8","name":"- brightness","rules":[{"t":"set","p":"lightdata.attributes.brightness","pt":"msg","to":"$max([$number(brightmin), $number(lightdata.attributes.brightness - ($number(env.brightstep)*count))])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":660,"wires":[["73047e8d.2f322"]]},{"id":"73047e8d.2f322","type":"api-call-service","z":"f4daa825.5dd3f8","name":"light_on","server":"e733376d.c37508","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"${light}","data":"{\"brightness\": {{lightdata.attributes.brightness}}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":820,"y":500,"wires":[[]]},{"id":"4fbf4574.3ea10c","type":"switch","z":"f4daa825.5dd3f8","name":"brightness at bright min?","property":"lightdata.attributes.brightness","propertyType":"msg","rules":[{"t":"gt","v":"brightmin","vt":"env"},{"t":"lte","v":"brightmin","vt":"env"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":700,"wires":[["4fdc3278.fd253c"],["247dca32.696136"]]},{"id":"247dca32.696136","type":"api-call-service","z":"f4daa825.5dd3f8","name":"light_off","server":"e733376d.c37508","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"${light}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":800,"y":700,"wires":[[]]},{"id":"c536d7.0e53b928","type":"change","z":"f4daa825.5dd3f8","name":"copy env vars","rules":[{"t":"set","p":"env.brightmin","pt":"msg","to":"brightmin","tot":"env"},{"t":"set","p":"env.brightstep","pt":"msg","to":"brightstep","tot":"env"},{"t":"set","p":"env.brightmax","pt":"msg","to":"brightmax","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":140,"y":200,"wires":[["992273c2.55bc"]]},{"id":"92e9856d.0fee18","type":"switch","z":"f4daa825.5dd3f8","name":"light off?","property":"lightdata.state","propertyType":"msg","rules":[{"t":"neq","v":"off","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":360,"y":540,"wires":[["2ec45dd6.827172"],["581a8f95.14cfa"]]},{"id":"581a8f95.14cfa","type":"change","z":"f4daa825.5dd3f8","name":"brightness to min bright","rules":[{"t":"set","p":"lightdata.attributes.brightness","pt":"msg","to":"$number(env.brightmin)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":560,"wires":[["73047e8d.2f322"]]},{"id":"8cd6de54.b82f8","type":"comment","z":"f4daa825.5dd3f8","name":"Take the environmental vars into the msg","info":"","x":200,"y":160,"wires":[]},{"id":"6562bb6f.296884","type":"comment","z":"f4daa825.5dd3f8","name":"Get the current state of the light - msg. state msg.lightdata","info":"","x":250,"y":240,"wires":[]},{"id":"dbcc9e65.15529","type":"comment","z":"f4daa825.5dd3f8","name":"Rotary increased or decreased?","info":"","x":170,"y":320,"wires":[]},{"id":"e733376d.c37508","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
I hope that’s understandable!