Below is what I imported, using your code. I just updated the switch to my switch.
I thought maybe the occupancy variable was causing the issue so I removed those parts and tried it again. This time I did not get the error message but when I turn off the lights manually with the dimmer switch at the wall, it goes back to full brightness.