So it’s been a while since I’ve posted something. I’ve been busy with work. So the latest project that I’m currently working on is related to my Home Automation project. After testing and searching for the best suitable option, I have decided to proceed on using Home Assistant as the controller for my smart home project.
A bit about Home Assistant
Home Assistant is an open-source home automation platform running on Python 3. Track and control all devices at home and automate control. Perfect to run on a Raspberry Pi.
Taken from www.home-assistant.io
I like the way that Home Assistant auto discovers new devices. Other Smart home software requires that you manually configure devices. This is a bit of inconvenience to me. A smart home solution should be smart enough to be aware of its perimeter.
So I had a few devices around the house but this is about the Plex Media Server that is running on my windows machine. I needed a way to remotely turn on and off the machine using my Home Assistant Controller (HASS). To turn on the machine, I can use Wake-On-LAN protocol to easily turn on any device on the network. On Linux, it works flawlessly but in Windows, there are some limitations.
Read more about this here
For turning off or putting the machine to sleep, I need to have a tool that can turn off / put the machine to sleep via a remote command from the HASS controller. After a bit of research I came out with a solution that will
- Run as a windows service
- It will listen for a http connection
- If the MAC Address of the originating command request is allowed, then the machine will then execute the command.
As of now I have 4 commands, lockwin ( to lock the machine ) , startplex ( start PlexService ) , stopplex ( stop PlexService ), tdola ( puts the machine to sleep ). It can actually be used to control any other services or commands.
You can compile it and ran normally or you can run it as a windows service using nssm / srvany or node-windows. Personally I prefer to bundled it into a single exe using pkg (https://www.npmjs.com/package/pkg) and then run it as a service using nssm (http://nssm.cc/)
You can read more at github.
This is my switch configuration .yaml
switch: - platform: wake_on_lan name: DH3C-ROG WOL mac_address: "XX:XX:XX:XX:XX:XX" host: 192.168.0.134 turn_off: service: shell_command.turn_off_mypc - platform: command_line switches: plex_service: command_on: 'curl http://192.168.0.134/startplex' command_off: 'curl http://192.168.0.134/stopplex' shell_command: turn_off_mypc: 'curl http://192.168.0.134/tdoqla'
Go to the main page of Home Assistant and 2 new switches will be shown like this.
- Plex – http://www.plex.tv/
- PlexService – https://forums.plex.tv/discussion/93994/pms-as-a-service
- Home Assistant – https://www.home-assistant.io/
- Node.js – https://nodejs.org/
- Wake-On-LAN – https://en.wikipedia.org/wiki/Wake-on-LAN
He has always been interested in computing. He is very passionate when it comes to technology oriented knowledge. He knows that the more that one knows, the more that one needs to learn. Experienced in content management and forms processing, he was a FileNet and Datacap Specialist. He is also a part time gamer and streams sometime.