It should be fairly simple to do using Tasker.
Create a profile and select type State -> Hardware -> Docked
Press the back button on the top left of this screen (where is says State Edit Docked) once you are done and a list of tasks will pop up. select New Task, give it a name eg Dim Screen and select the tick.
Then on the task screen, select the + to add an action
Display -> Display Brightness, edit the level as appropriate (presumably very low if you want it on while you are asleep) then tap the back button at the top left (where it says Task Edit Dim Screen) and you will be back at the profile screen.
If you are using auto brightness you will need a task to turn it off before you dim the screen or it won't dim. Some state based profiles automatically return settings to their previous value when the state is no longer active. If your profile doesn't do this you will need to add an exit task to reverse the changes to the settings.
Tasker is very powerful and you can do all sorts of nifty things with it. It's well worth the money and worth getting to know how to use.