Disclosure: This post contains affiliate links. If you click through and make a purchase, I will earn a commission, at no additional cost to you. Read my full disclosure here.
In addition to my Proxmox VE application server that hosts my Home Assistant, I also have a NAS (Network Attached Storage) which stores a lot of media, such as backups of my photography and many delicious recipes. Currently, my NAS is operating on TrueNAS CORE and I plan to continue using that operating system for the near future, despite its faults.
My TrueNAS CORE NAS is far from ideal. It's quite basic, I bought the most affordable case available and installed the bare minimum of hardware. It's not particularly quiet and there is no sound dampening, so it gets loud when writing. Since it's located right next to where I sleep, I can't leave it on 24/7.
This is where Home Assistant enters the fray. I needed a way of remotely turning my TrueNAS CORE server on and off, as it sits on a shelf that isn’t easy to reach.
For this to work, I’m using the TrueNAS CORE API to trigger a system shutdown from Home Assistant. Turning on the TrueNAS CORE is way easier thanks to Wake on LAN (WOL) integration in Home Assistant. Let me start by showing you how to use the WOL switch to turn on your TrueNAS CORE instantly.
The FreeNAS switch in my Home Assistant
Booting TrueNAS CORE using Home Assistant
Before you implement this, it is important to note that I'm assuming you have a solid understanding of both Home Assistant and TrueNAS CORE. To set up the WOL switch, you will need to know the IP and MAC address of your FreeNAS; technically, the IP address is optional, though you are likely to know it already.
To find out your MAC, simply enter the command ifconfig in the TrueNAS CORE shell and look for hwaddr. The IP is solely used for Home Assistant to figure out if your TrueNAS CORE is turned on or not. So if you are going to use the switch in the UI, I would definitely recommend adding the IP to the configuration.
Once you have the MAC and IP on hand, the following entry to your configuration.yaml file will create a switch that allows you to boot your TrueNAS CORE machine:
Shutting down a TrueNAS CORE system using Home Assistant can be slightly more complex. There is no option for reverse WOL or similar functionality, and no standard method for handling shutdowns. Therefore, I have chosen to use the TrueNAS CORE API. To make the API call, you can create a REST command that includes the following details:
As you might have noticed, I’ve used the secrets.yaml file to store my credentials. I had to use root to get this API call to work. There might be a nicer and safer way of doing this. To accomplish this, simply open the secrets.yaml on your Home Assistant server and enter the following on a new line:
With the TrueNAS CORE RESTful Command complete, it can be added to the switch that was created earlier. To accomplish this, simply append the “turn_off” variable to the end of the switch's configuration, as shown below:
And there you have it, TrueNAS CORE can now be controlled by Home Assistant. This switch can be used in automations using switch.turn_on, switch.toggle, and switch.turn_off and can be placed in the UI.
And that's it, you can now control your TrueNAS CORE machine using Home Assistant. This switch can be integrated into automations using commands such as “switch.turn_on”, “switch.toggle”, and “switch.turn_off”. You can also add it to your Dashboard for manual control.
4 thoughts on “Controlling TrueNAS CORE using Home Assistant”
Hello,
I just wanted to thank you, as it’s working perfectly as expected.
Hi there, this might help: “in ZFS terminology, the storage that is managed by ZFS is referred to as a pool. The FreeNAS® graphical interface uses the term volume to refer to a ZFS pool.”
Hello,
I just wanted to thank you, as it’s working perfectly as expected.
Thanks !
That’s great to hear! I don’t use FreeNAS anymore so thanks for confirming that this still works😊
When you say “VOLUME” you mean the Disk? The pool¿ or the share?
thank you!
Enric
Hi there, this might help: “in ZFS terminology, the storage that is managed by ZFS is referred to as a pool. The FreeNAS® graphical interface uses the term volume to refer to a ZFS pool.”
https://www.ixsystems.com/documentation/freenas/9.3/freenas_storage.html#volumes