MySensors LED dimmer doesn't appear in HA. Message type error

Hello. I have a serial gateway on a Hassio 0.116.4 installation. When i try to connect a led dimmer, it is seen by the gateway (i guess?) but the entity never appears.
There are some errors in log, but i’m unable to draw much sense from them.
Configuration.yaml:

> mysensors:
>   gateways:
>     - device: '/dev/ttyUSB0'
>       # persistence_file: '/config/mysensors2.json'
>   version: '2.3'
>   persistence: false
> #      baud_rate: 38400

Persistence disabled for debugging purposes.
Log entries after HA restart (and dimmer restart a bit later):

2020-10-16 15:55:25 INFO (MainThread) [mysensors.gateway_serial] Trying to connect to /dev/ttyUSB0
2020-10-16 15:55:25 INFO (MainThread) [mysensors] Connected to Serial<id=0x6f2c6670, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0, xonxoff=False, rtscts=False, dsrdtr=False)
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors] Receiving 0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RNNGA---,FQ=16,REL=255,VER=2.3.2
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:0 MCO:BGN:INIT GW,CP=RNNGA---,FQ=16,REL=255,VER=2.3.2
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:5 TSM:INIT
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:7 TSF:WUR:MS=0
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:15 TSM:INIT:TSP OK
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:18 TSM:INIT:GW MODE
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:21 TSM:READY:ID=0,PAR=0,DIS=0
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:24 MCO:REG:NOT NEEDED
2020-10-16 15:55:26 INFO (MainThread) [mysensors.handler] n:0 c:255 t:3 s:14 p:Gateway startup complete.
2020-10-16 15:55:26 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 0 child 255
2020-10-16 15:55:26 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 0 child 255
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:28 MCO:BGN:STP
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:35 MCO:BGN:INIT OK,TSP=1
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:38 TSM:READY:NWD REQ
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:45 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
2020-10-16 15:55:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:55 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 15:55:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:714 TSF:MSG:READ,21-21-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0
2020-10-16 15:55:27 WARNING (MainThread) [mysensors] Node 21 is unknown
2020-10-16 15:55:27 INFO (MainThread) [mysensors] Requesting new presentation for node 21
2020-10-16 15:55:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:737 TSF:MSG:SEND,0-0-21-21,s=255,c=3,t=19,pt=1,l=1,sg=1,ft=0,st=OK:0
2020-10-16 15:55:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1049 TSF:MSG:READ,21-21-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0
2020-10-16 15:55:27 WARNING (MainThread) [mysensors] Node 21 is unknown
2020-10-16 15:55:27 INFO (MainThread) [mysensors] Requesting new presentation for node 21
2020-10-16 15:55:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1115 TSF:MSG:SEND,0-0-21-21,s=255,c=3,t=19,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:24 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298036 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=2,l=2,sg=0:0
2020-10-16 16:00:24 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298042 TSF:MSG:ECHO REQ
2020-10-16 16:00:24 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298046 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=2,l=2,sg=0,ft=0,st=OK:0
2020-10-16 16:00:24 WARNING (MainThread) [mysensors] Node 2 is unknown
2020-10-16 16:00:24 INFO (MainThread) [mysensors] Requesting new presentation for node 2
2020-10-16 16:00:24 ERROR (MainThread) [mysensors.handler] Node 2 is unknown, will not add child 116
2020-10-16 16:00:24 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298065 !TSF:RTE:2 UNKNOWN
2020-10-16 16:00:24 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298104 !TSF:MSG:SEND,0-0-2-2,s=255,c=3,t=19,pt=1,l=1,sg=0,ft=0,st=NACK:0
2020-10-16 16:00:25 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298552 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=2,l=2,sg=0:1
2020-10-16 16:00:25 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298558 TSF:MSG:ECHO REQ
2020-10-16 16:00:25 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:298563 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=2,l=2,sg=0,ft=0,st=OK:1
2020-10-16 16:00:25 WARNING (MainThread) [mysensors] Not a valid message: Not valid message sub-type: 116 for dictionary value @ data['sub_type']
2020-10-16 16:00:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:299362 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=2,l=2,sg=0:26
2020-10-16 16:00:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:299368 TSF:MSG:ECHO REQ
2020-10-16 16:00:26 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:299373 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=2,l=2,sg=0,ft=0,st=OK:26
2020-10-16 16:00:26 WARNING (MainThread) [mysensors] Not a valid message: When message type is 4, child_id must be 255 for dictionary value @ data['child_id']
2020-10-16 16:00:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:300576 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:00:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:300582 TSF:MSG:ECHO REQ
2020-10-16 16:00:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:300588 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:27 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 7 for dictionary value @ data['type']
2020-10-16 16:00:29 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:303216 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:00:29 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:303222 TSF:MSG:ECHO REQ
2020-10-16 16:00:29 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:303227 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:29 WARNING (MainThread) [mysensors] Not a valid message: When message type is 4, child_id must be 255 for dictionary value @ data['child_id']
2020-10-16 16:00:39 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:312401 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:00:39 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:312408 TSF:MSG:ECHO REQ
2020-10-16 16:00:39 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:312415 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:39 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:312422 TSF:MSG:ECHO
2020-10-16 16:00:39 WARNING (MainThread) [mysensors] Not a valid message: When message type is 4, child_id must be 255 for dictionary value @ data['child_id']
2020-10-16 16:00:40 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:313482 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:00:40 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:313487 TSF:MSG:ECHO REQ
2020-10-16 16:00:40 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:313494 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:40 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 7 for dictionary value @ data['type']
2020-10-16 16:00:40 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314190 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:00:40 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314195 TSF:MSG:ECHO REQ
2020-10-16 16:00:40 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314201 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:40 WARNING (MainThread) [mysensors] Node 167 is unknown
2020-10-16 16:00:40 INFO (MainThread) [mysensors] Requesting new presentation for node 167
2020-10-16 16:00:40 ERROR (MainThread) [mysensors.handler] Node 167 is unknown, will not add child 0
2020-10-16 16:00:40 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314224 !TSF:RTE:167 UNKNOWN
2020-10-16 16:00:41 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314263 !TSF:MSG:SEND,0-0-167-167,s=255,c=3,t=19,pt=1,l=1,sg=0,ft=0,st=NACK:0
2020-10-16 16:00:41 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314543 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:00:41 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314549 TSF:MSG:ECHO REQ
2020-10-16 16:00:41 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:314554 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:41 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 7 for dictionary value @ data['type']
2020-10-16 16:00:42 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:315942 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=2,l=2,sg=0:44
2020-10-16 16:00:42 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:315949 TSF:MSG:ECHO REQ
2020-10-16 16:00:42 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:315954 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=2,l=2,sg=0,ft=0,st=OK:44
2020-10-16 16:00:42 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 7 for dictionary value @ data['type']
2020-10-16 16:00:49 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:322525 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:00:49 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:322531 TSF:MSG:ECHO REQ
2020-10-16 16:00:49 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:322535 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:00:49 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 7 for dictionary value @ data['type']
2020-10-16 16:10:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:900008 TSF:SAN:OK
2020-10-16 16:15:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1200039 TSM:READY:NWD REQ
2020-10-16 16:15:27 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1200046 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
2020-10-16 16:15:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1208719 TSF:MSG:READ,21-21-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
2020-10-16 16:15:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1208725 TSF:MSG:BC
2020-10-16 16:15:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1208728 TSF:MSG:FPAR REQ,ID=21
2020-10-16 16:15:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1208732 TSF:PNG:SEND,TO=0
2020-10-16 16:15:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1208735 TSF:CKU:OK
2020-10-16 16:15:35 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1208738 TSF:MSG:GWL OK
2020-10-16 16:15:36 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1209164 TSF:MSG:SEND,0-0-21-21,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:15:37 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210732 TSF:MSG:READ,21-21-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
2020-10-16 16:15:37 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210738 TSF:MSG:PINGED,ID=21,HP=1
2020-10-16 16:15:37 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210744 TSF:MSG:SEND,0-0-21-21,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
2020-10-16 16:15:37 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210758 TSF:MSG:READ,21-21-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2020-10-16 16:15:37 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210766 TSF:MSG:SEND,0-0-21-21,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2020-10-16 16:15:37 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210777 TSF:MSG:READ,21-21-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.3.2
2020-10-16 16:15:37 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 21 child 255
2020-10-16 16:15:37 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210790 TSF:MSG:READ,21-21-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210843 !TSF:MSG:SEND,0-0-21-21,s=255,c=3,t=6,pt=0,l=1,sg=0,ft=0,st=NACK:M
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210852 TSF:MSG:READ,21-21-0,s=255,c=3,t=11,pt=0,l=21,sg=0:DimmableLED /w button
2020-10-16 16:15:38 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 21 child 255
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210869 TSF:MSG:READ,21-21-0,s=255,c=3,t=12,pt=0,l=3,sg=0:1.2
2020-10-16 16:15:38 DEBUG (MainThread) [homeassistant.components.mysensors.gateway] Node update: node 21 child 255
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210888 TSF:MSG:READ,21-21-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210896 TSF:MSG:SEND,0-0-21-21,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210910 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210916 TSF:MSG:ECHO REQ
2020-10-16 16:15:38 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1210921 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:15:38 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 6 for dictionary value @ data['type']
2020-10-16 16:16:00 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1233672 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:44
2020-10-16 16:16:00 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1233678 TSF:MSG:ECHO REQ
2020-10-16 16:16:00 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1233683 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:44
2020-10-16 16:16:00 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1233690 TSF:MSG:ECHO
2020-10-16 16:16:00 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 7 for dictionary value @ data['type']
2020-10-16 16:16:04 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1237352 TSF:MSG:READ,21-21-0,s=1,c=1,t=3,pt=1,l=1,sg=0:0
2020-10-16 16:16:04 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1237357 TSF:MSG:ECHO REQ
2020-10-16 16:16:04 DEBUG (MainThread) [mysensors.handler] n:0 c:255 t:3 s:9 p:1237362 TSF:MSG:SEND,0-0-21-21,s=1,c=1,t=3,pt=1,l=1,sg=0,ft=0,st=OK:0
2020-10-16 16:16:04 WARNING (MainThread) [mysensors] Not a valid message: Not valid message type: 6 for dictionary value @ data['type']

Unrelated strings omited, of course.

The sketch is taken straight from Mysensors page:

/**
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <[email protected]>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 *******************************
 *
 * REVISION HISTORY
 * Version 1.0 - Developed by Bruce Lacey and GizMoCuz (Domoticz)
 * Version 1.1 - Modified by hek to incorporate a rotary encode to adjust 
 *                                light level locally at node
 * 
 * DESCRIPTION
 * This sketch provides an example how to implement a dimmable led light node with a rotary 
 * encoder connected for adjusting light level. 
 * The encoder has a click button which turns on/off the light (and remembers last dim-level) 
 * The sketch fades the light (non-blocking) to the desired level. 
 *
 * Default MOSFET pin is 3
 * 
 *  Arduino      Encoder module
 *  ---------------------------
 *  5V           5V (+)  
 *  GND          GND (-)
 *  4            CLK (or putput 1)
 *  5            DT  (or output 1) 
 *  6            SW (Switch/Click)  
 */

 
// Enable debug prints
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_RF24
//#define MY_RADIO_RFM69

#include <MySensors.h>  
#include <Bounce2.h>
#include <Encoder.h>

#define LED_PIN 3           // Arduino pin attached to MOSFET Gate pin
#define KNOB_ENC_PIN_1 4    // Rotary encoder input pin 1
#define KNOB_ENC_PIN_2 5    // Rotary encoder input pin 2
#define KNOB_BUTTON_PIN 6   // Rotary encoder button pin 
#define FADE_DELAY 10       // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
#define SEND_THROTTLE_DELAY 400 // Number of milliseconds before sending after user stops turning knob
#define SN "DimmableLED /w button"
#define SV "1.2"

#define CHILD_ID_LIGHT 1

#define EEPROM_DIM_LEVEL_LAST 1
#define EEPROM_DIM_LEVEL_SAVE 2

#define LIGHT_OFF 0
#define LIGHT_ON 1

int dimValue;
int fadeTo;
int fadeDelta;
byte oldButtonVal;
bool changedByKnob=false;
bool sendDimValue=false;
unsigned long lastFadeStep;
unsigned long sendDimTimeout;
char convBuffer[10];

MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
Encoder knob(KNOB_ENC_PIN_1, KNOB_ENC_PIN_2);  
Bounce debouncer = Bounce(); 

void setup()  
{ 
  // Set knob button pin as input (with debounce)
  pinMode(KNOB_BUTTON_PIN, INPUT);
  digitalWrite(KNOB_BUTTON_PIN, HIGH);
  debouncer.attach(KNOB_BUTTON_PIN);
  debouncer.interval(5);
  oldButtonVal = debouncer.read();

  // Set analog led pin to off
  analogWrite( LED_PIN, 0);

  // Retreive our last dim levels from the eprom
  fadeTo = dimValue = 0;
  byte oldLevel = loadLevelState(EEPROM_DIM_LEVEL_LAST);
  Serial.print("Sending in last known light level to controller: ");
  Serial.println(oldLevel);  
  send(dimmerMsg.set(oldLevel), true);   

  Serial.println("Ready to receive messages...");  
}

void presentation() {
  // Send the Sketch Version Information to the Gateway
  present(CHILD_ID_LIGHT, S_DIMMER);
  sendSketchInfo(SN, SV);
}

void loop()      
{
  // Check if someone turned the rotary encode
  checkRotaryEncoder();
  
  // Check if someone has pressed the knob button
  checkButtonClick();
  
  // Fade light to new dim value
  fadeStep();
}

void receive(const MyMessage &message)
{
  if (message.type == V_LIGHT) {
    // Incoming on/off command sent from controller ("1" or "0")
    int lightState = message.getString()[0] == '1';
    int newLevel = 0;
    if (lightState==LIGHT_ON) {
      // Pick up last saved dimmer level from the eeprom
      newLevel = loadLevelState(EEPROM_DIM_LEVEL_SAVE);
    } 
    // Send dimmer level back to controller with ack enabled
    send(dimmerMsg.set(newLevel), true);
    // We do not change any levels here until ack comes back from gateway 
    return;
  } else if (message.type == V_DIMMER) {
    // Incoming dim-level command sent from controller (or ack message)
    fadeTo = atoi(message.getString(convBuffer));
    // Save received dim value to eeprom (unless turned off). Will be
    // retreived when a on command comes in
    if (fadeTo != 0)
      saveLevelState(EEPROM_DIM_LEVEL_SAVE, fadeTo);
  }
  saveLevelState(EEPROM_DIM_LEVEL_LAST, fadeTo);
  
  Serial.print("New light level received: ");
  Serial.println(fadeTo);

  if (!changedByKnob) 
    knob.write(fadeTo); 
    
  // Cancel send if user turns knob while message comes in
  changedByKnob = false;
  sendDimValue = false;

  // Stard fading to new light level
  startFade();
}



void checkRotaryEncoder() {
  long encoderValue = knob.read();

  if (encoderValue > 100) {
    encoderValue = 100;
    knob.write(100);
  } else if (encoderValue < 0) {
    encoderValue = 0;
    knob.write(0);
  }

  if (encoderValue != fadeTo) { 
    fadeTo = encoderValue;
    changedByKnob = true;
    startFade();
  }
}

void checkButtonClick() {
  debouncer.update();
  byte buttonVal = debouncer.read();
  byte newLevel = 0;
  if (buttonVal != oldButtonVal && buttonVal == LOW) {
    if (dimValue==0) {
      // Turn on light. Set the level to last saved dim value
      int saved = loadLevelState(EEPROM_DIM_LEVEL_SAVE);
      newLevel = saved > 0 ? saved : 100;
    }
    send(dimmerMsg.set(newLevel),true);
  }
  oldButtonVal = buttonVal;
}

void startFade() {
  fadeDelta = ( fadeTo - dimValue ) < 0 ? -1 : 1;
  lastFadeStep = millis();
}

// This method provides a graceful none-blocking fade up/down effect
void fadeStep() {
  unsigned long currentTime  = millis();
  if ( dimValue != fadeTo && currentTime > lastFadeStep + FADE_DELAY) {
    dimValue += fadeDelta;
    analogWrite( LED_PIN, (int)(dimValue / 100. * 255) );
    lastFadeStep = currentTime;
    
    Serial.print("Fading level: ");
    Serial.println(dimValue);

    if (fadeTo == dimValue && changedByKnob) {
      sendDimValue = true;
      sendDimTimeout = currentTime;
    }
  } 
  // Wait a few millisecs before sending in new value (if user still turns the knob)
  if (sendDimValue && currentTime > sendDimTimeout + SEND_THROTTLE_DELAY)  {
     // We're done fading.. send in new dim-value to controller.
     // Send in new dim value with ack (will be picked up in incomingMessage) 
    send(dimmerMsg.set(dimValue), true); // Send new dimmer value and request ack back
    sendDimValue = false;
  }
}

// Make sure only to store/fetch values in the range 0-100 from eeprom
int loadLevelState(byte pos) {
  return min(max(loadState(pos),0),100);
}
void saveLevelState(byte pos, byte data) {
  saveState(pos,min(max(data,0),100));
}

I’m well aware that it’s probably the 100th topic like that, but what worked for others, doesnt seem to work for me. It drives me crazy a bit. So i will greatly appreciate any help.