If you have to ask the internet how to wire this stuff up; DON'T.

This an area common only to industrial electrical engineering. Knowing how to run a branch circuit and how to program a raspberry pie DOES NOT qualify you to install these type of things.

I gave up on electrical questions. I either don't know the answer (because it's professionals talking shop) or I'd have to begin my answer with a warning (just like that one does) so, no thanks, I'll pass. 

I had posted a [rather lengthy and somewhat embarrassing post][1] that explains my position on this further.


  [1]: https://diy.meta.stackexchange.com/questions/1029/for-safetys-sake-how-do-you-answer-an-electrical-question