Home Assistant and FreeNAS

Status
Not open for further replies.

TooMuchData

Contributor
Joined
Jan 4, 2015
Messages
188
I run Home Assistant in a VM on FreeNAS 11.0-U4. Been using it for years to manage lights, switches, thermostats, and IOT devices. Works great.

Recently I started using HASS to "manage" FN replication tasks (specifically to enable and disable them individually or en mass). Screen Shot 2017-10-05 at 2.08.39 PM.jpg

Just wondering if other FN users are interested in such integrations or have done them already?
 

Dice

Wizard
Joined
Dec 11, 2015
Messages
1,410
Cool integration.
 

TooMuchData

Contributor
Joined
Jan 4, 2015
Messages
188
There doesn't seem to be much interest, but I thought I would post my latest Home Assistant "FreeNAS" page:

Screen Shot 2017-10-16 at 10.30.30 PM.jpg

I have two FreeNAS systems. The first is a C2750D4I w/ 32GB and 6x6TB WD Reds in a Fractal Node. I use it for file storage and Emby (which I prefer to Plex). The second box is a Lenovo TS140 with 16GB, 2x6TB, and 2x1TB. Connected to it via homebuilt SAS is 6x6TB in another Node case. The TS140 box is for testing and replication for backup.

The Node SAS box has a Particle Photon controlling the power via a $3 relay (in parallel with the pushbutton) and a Supermicro PCC-JBPWR2. The Photon also senses whether the control board has lit the power LED. Control of and status from Photon to Home Assistant (running in a FreeNAS VM) is via MQTT Broker (running in same VM). The HASS "TS140 NodePower Switch" then controls the SAS box and shows status. I also have a bunch of switches to turn replication tasks on and off (via the FreeNAS API). By collecting all these switches under one "card" Home Assistant gratuitously gives me a switch to bulk control enable/disable all the replication tasks (replaces 9 edit/disable/close sequences on FN). There are cron tasks on the two FN systems sending temperature and other data to HASS via MQTT for display in badges. FreeNAS doesn't have an MQTT publisher (really should be included in FreeBSD under FN), but HASS does and let's FN use it via CURL to the HASS API. Finally I have a "TS140tank Zvol" sensor which uses the FreeNAS API to show whether the volume in the SAS box has been imported or not.

The primary purpose of my Home Assistant system is to control lighting, HVAC, leak detection, and some automation. My next automation will be to lower the thermostat if any of the FreeNAS hard drives are getting too hot (email notifications sent by FreeNAS could also be sent to HASS to trigger such an automation).

When away from home I access HASS either via VPN Tunnel or an Android phone app.

Installing HASS takes 10 minutes. Configuring HASS is done by YAML files. The learning curve is not trivial, but is substantially less than for FreeNAS. And, like FreeNAS, there is a very supportive user community. See hass.io if interested.
 

TooMuchData

Contributor
Joined
Jan 4, 2015
Messages
188
I have recently been asked how I get the FreeNAS data into Home Assistant. Some of that is explained above, and the answer, until today, was cron jobs on FreeNAS that published MQTT data via curl to the HASS service. HASS sensors subscribed to and processed the MQTT payloads.

I had also been asked to post my scripts, but I never did so because I was changing them in response to FreeNAS and FreeBSD version changes.

Anyway, I've now adopted a HASS only approach. Instead of scripts on the FreeNAS side I'm now using ssh to execute commands on FreeNAS. Consequently, most of my HASS sensors are now "command_line" instead of MQTT. For instance, this is the entry format in my sensors.yaml file to get one disk temperature every five minutes:

Code:
- platform: command_line
  name: 'C2750D4I ADA2'
  unit_of_measurement: '°C'
  scan_interval: 300
  command: >-
	ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q
	xxx@192.168.0.xxx
	smartctl -A /dev/ada2 | grep -i temperature | awk '{print $10"°"}'


My HASS system runs under Docker on Raspbian Stretch on a Raspberry Pi 3B+. For the above to work I had to first issue ssh-copy-id from the pi to FreeNAS. Then I had create a .ssh directory in /usr/share/hassio/homeassistant/ and copy the id_rsa key from /home/pi/.ssh to /usr/share/hassio/homeassistant/.ssh. The ssh command above refers to /config/.ssh, which is how HASS (Docker) knows the directory.
Thanks go to BlinkyLights who outlined the approach in this post:
https://community.home-assistant.io/t/hass-io-and-making-ssh-client-requests-to-another-device/47225.

For cpu temperatures I use:
Code:
sysctl dev.cpu.0 | grep temperature | tr '.' ' ' | awk '{print $5"°"}'


My replication switches access the FreeNAS API, and are in this form in my switches.yaml file:
Code:
- platform: command_line
  switches:
	fn_repl_12:
	scan_interval: 60
	  friendly_name: FreeNAS Replication - Iohyve
	  command_on: 'curl -H "Content-Type: application/json" -X PUT -d "{\"repl_enabled\":true}" -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
	  command_off: 'curl -H "Content-Type: application/json" -X PUT -d "{\"repl_enabled\":false}" -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
	  command_state: 'curl -X GET -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
	  value_template: '{{value_json.repl_enabled}}'
 
Last edited by a moderator:

DeanNotDin

Dabbler
Joined
Mar 19, 2017
Messages
32
I have recently been asked how I get the FreeNAS data into Home Assistant. Some of that is explained above, and the answer, until today, was cron jobs on FreeNAS that published MQTT data via curl to the HASS service. HASS sensors subscribed to and processed the MQTT payloads.

I had also been asked to post my scripts, but I never did so because I was changing them in response to FreeNAS and FreeBSD version changes.

Anyway, I've now adopted a HASS only approach. Instead of scripts on the FreeNAS side I'm now using ssh to execute commands on FreeNAS. Consequently, most of my HASS sensors are now "command_line" instead of MQTT. For instance, this is the entry format in my sensors.yaml file to get one disk temperature every five minutes:

- platform: command_line
name: 'C2750D4I ADA2'
unit_of_measurement: '°C'
scan_interval: 300
command: >-
ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no -q
xxx@192.168.0.xxx
smartctl -A /dev/ada2 | grep -i temperature | awk '{print $10"°"}'

My HASS system runs under Docker on Raspbian Stretch on a Raspberry Pi 3B+. For the above to work I had to first issue ssh-copy-id from the pi to FreeNAS. Then I had create a .ssh directory in /usr/share/hassio/homeassistant/ and copy the id_rsa key from /home/pi/.ssh to /usr/share/hassio/homeassistant/.ssh. The ssh command above refers to /config/.ssh, which is how HASS (Docker) knows the directory.
Thanks go to BlinkyLights who outlined the approach in this post:
https://community.home-assistant.io/t/hass-io-and-making-ssh-client-requests-to-another-device/47225.

For cpu temperatures I use:
sysctl dev.cpu.0 | grep temperature | tr '.' ' ' | awk '{print $5"°"}'

My replication switches access the FreeNAS API, and are in this form in my switches.yaml file:
- platform: command_line
switches:
fn_repl_12:
scan_interval: 60
friendly_name: FreeNAS Replication - Iohyve
command_on: 'curl -H "Content-Type: application/json" -X PUT -d "{\"repl_enabled\":true}" -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
command_off: 'curl -H "Content-Type: application/json" -X PUT -d "{\"repl_enabled\":false}" -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
command_state: 'curl -X GET -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
value_template: '{{value_json.repl_enabled}}'

Wow! This is awesome!
Thank you for this great tip!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,702
I wonder if a daemon running on the FreeNAS boxes and posting the temps over MQTT wouldn't be more efficient in terms of CPU and network on both systems... I was thinking of how I would do the same thing you have done when I got the time, with MQTT having come to mind first. Good job working out the CMD sensor.
 

adrianwi

Guru
Joined
Oct 15, 2013
Messages
1,231
Very nice! I'll take a look at this as I'm running HA in a Docker container on a FreeNAS VM.

Not got it doing much more that lights, switches and some AV stuff, but it was useful to control my TP-Link switches via my Harmony remote.

I'm currently struggling with creating an emby group to show all the devices connecting to my emby server, but don't want to list each entity as its a long list and constantly changes. I was hoping you could wildcard it e.g. media_player.emby* but I haven't found a solution yet. Any ideas?
 

abe_one

Explorer
Joined
Nov 11, 2015
Messages
70
Hi, I've just installed Home Assistant on raspberry, and I would love to integrate some information from freenas.
Basically I would like to be able to switch it on and off.
To turn it on I can use a switch like you did, but to turn it off I should call the shutdown service.
Also I would like to monitor the CPU and disk temperature (I have 6 disks) and the CPU load.

I read your posts but I did not understand much. Could you kindly give me some suggestions? I also use an asrock rack motherboard.

Thanks so much
 

abe_one

Explorer
Joined
Nov 11, 2015
Messages
70
I've done it. I can read information via API from the Hass.io to Freenas.
The only problem is that I would like to be able to read the temperature of the CPU and the 6 disks, and I would like to add a key to switch off.
I'm trying to use SSH to do it, the configuration does not give me errors but does not read the temperature.
I tried to look among the documents of the freenas bees but in this regard I find nothing especially for the CPU temperature.
For the shutdown I found the command to call the API but I do not know where to put it ... maybe between the switches ... how do I compose for the command?
 

abe_one

Explorer
Joined
Nov 11, 2015
Messages
70
ok reading for a few hours I was able to understand where I'm wrong. I do not have the key file for the ssh .... I can not find the way to get it and install it on freenas because you accept the request of my command from Home Assistant.

I read something about generating it through Putty but I do not understand then how do I put it and where too!
 

adrianwi

Guru
Joined
Oct 15, 2013
Messages
1,231
I've been looking at this today, although got distracted trying to spin up a Windows VM using FreeNAS!

I'm running HA inside a FreeNAS jail, so wasn't sure what commands I need to get the HDD Temp sensors working? Do I still need to SSH into FreeNAS even though the jail is running on FreeNAS?
 

abe_one

Explorer
Joined
Nov 11, 2015
Messages
70
Ok I did it !!!! Hooray!
It was just a ssh key problem that prevented me from connecting without needing to enter the password!
Now I have done a nice graph of the temperature of the CPU and the disks so I can check the status .....
I have to understand how to make an alert in case they exceed a certain temperature but now I'll see how to do it.

I just have to understand how to turn it on and off.
I saw that there is the API to turn it off, while to turn it on I think I'll have to find a way to connect through the IPMI port ....

Now I'll try!
Thank you....
 

usergiven

Dabbler
Joined
Jul 15, 2015
Messages
47
My replication switches access the FreeNAS API, and are in this form in my switches.yaml file:
Code:
- platform: command_line
  switches:
	fn_repl_12:
	scan_interval: 60
	  friendly_name: FreeNAS Replication - Iohyve
	  command_on: 'curl -H "Content-Type: application/json" -X PUT -d "{\"repl_enabled\":true}" -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
	  command_off: 'curl -H "Content-Type: application/json" -X PUT -d "{\"repl_enabled\":false}" -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
	  command_state: 'curl -X GET -u root:password http://192.168.0.xxx/api/v1.0/storage/replication/12/'
	  value_template: '{{value_json.repl_enabled}}'

Hi TooMuchData, very much appreciate the post, it opens my eyes as to what I can automate in my FN box. I'm having trouble with this replication example. I'm running Home Assistant in a docker container on an Ubuntu VM. In simply pasting (and personalizing) your Yaml above, I would get errors in the log. I've exec'd into the Home Assistant container and run the Command_on statement and first had to remove the /12/ at the end of the API url to get a valid command but my error says:

Code:
root@docker:/usr/src/app# curl -H "Content-Type: application/json" -X PUT -d "{\"repl_enabled\":true}" -u root:password http://192.168.1.x/api/v1.0/storage/replication/
{"error": "Invalid data sent: missing 'objects'"}root@docker:/usr/src/app#


What am I missing?

**EDIT** Figured it out. It had to do with the number at the end of the API, you had identified replication ID 12 with /12/ and I needed to add a /1/ at the end for mine, replication ID 1.
 
Last edited:
Status
Not open for further replies.
Top