In parts 1-3, we went over how to use Proxmox, EVE\PNET and and Home Assistant to automate starting and stopping our physical server, and lab nodes. In my lab I also have resources in AWS EC2. Every time I need to get into AWS I have to go to the webpage, log in, pass MFA, go to EC2, find my resources and then start them.
And, because I need to turn them off when I’m done to keep costs down I have to remember to go back and turn them off. It’s painfully tedious. I finally got to the point of where it annoyed me enough to ask…can I add this to my Home Assistant logic?
As the gif below shows…yes.
Let’s quickly go over how I did it. In my initial testing, I downloaded AWS CLI for Windows. After installing I ran “aws configure” from CLI. It will then prompt for:AWS Access Key ID
AWS Secret Access Key
Default region name
Default output format ( I used YAML, easiest to read.)
You must create a Access key ID and Secret Access key via AWS IAM that has rights to your resources.
Then the basic command structure is: aws ec2 start-instances --instance-ids [space separated instance IDs]
aws ec2 stop-instances --instance-ids [space separated instance IDs]
A handy command to see the state of your instances is:aws ec2 describe-instances --instance-ids [space separated instance IDs] --query Reservations[*].Instances[*].State.Name --output text
Once I was able successfully able to send these via Windows, my next step was folding this into my overall automation strategy. I followed the basic structure of my original steps, but the question was where do I install AWS CLI? I could install it on Home Assistant, but I want to be very limited about how I change the install environment outside of HA itself. In fact, the only change on HA I’ve made is to install the private key for SSH to the other servers.
I could install it on PNET/EVE but my same apprehension applies. It’s a stable lab environment, I don’t want to color outside the lines. In the end I decided to install it on a LXC fileserver in my lab, and then copy the public key over to it so HA could call it remotely like how I use it for PNET/EVE. That way I don’t have to create another resource just for this, and it’s only available while the lab itself is up.
Just like before, I added both start and stop to my configuration.yaml, then rebooted HA.
Once it shows up as an entity, I then created a helper Boolean and tied it to some logic in Node Red. Then I added to the power on/shutdown logic of the PNET/EVE server and made it trigger the Boolean so I can see it’s status on the lab management page. I decided to add it as a part of the server turnup, as it is only ever needed as part of my SDWAN lab.
That’s it! Since I already had the foundation built, extending it to other services was fairly easy to do.
Until next time.