My (outdated) Quick Start for Home Assistant Core on FreeNAS 11.2

@Skeletor
agh… So I just tested this. I forgot how the install script worked. When you copy the files in manually the side entries for the configurator and hadashboard are there but they are not fully setup.

Still this is not complicated but simply a few more steps.

Did you try to install the configurator as well? Can you check if that’s running?
The configurator has the same ip address but it’s on port 3218

So for example if your homeassistant is http://192.168.1.100:8123
Please try to reach the configurator at http://192.168.1.100:3218

We can use it finish HA config.
If that is working you need to un-comment (remove # at beginning of line) on Line 77
as well as for hadashboard and/or configurator. Show below I have edited this file to enable only the configurator. You will still need to restart HA below the changes take effect.

@troy Thanks for the reply. So just to clarify I need to make the edits to my configuration.yaml before I do the copy procedure you gave me in the previous reply or after?

I tried the copy but I wasn’t logged into the jail itself nore did I realize I needed to set the permissions after.

Thanks again.

@Skeletor

Sorry to be confusing… I think since you have already copied the files once they may already be in place. You’ll know when you open the file to edit. The entries to edit for configurato and hadashboard are the entries I added to my example config. When you open the homeassistant configuration file, if you see these entries (again around Line 71 then you already have the example files. If those entries are missing then you would need to copy the files first or you can just add these lines to the default configuration file.

Also I should be mostly free till Monday now. Have a few things to do but otherwise I’ll be around so I can hopefully respond in a more timely manner and get you fully up and running!

Sorry for the delayed response, my life can be demanding at times.

Well in the immortal words of Doc Brown “IT WORKS!!”

My only remaining issue is when redoing this so many times trying to work it out myself I overlooked the dataset. The permissions of my Hass Dataset are both set to Hass so I can’t edit anything in the NFS share. How do I fix that without breaking something else. I need to change either the User or Group permissions to match the ones I have set in my Registry.

Thanks again @troy

@Skeletor

When you say

Are you referring to your user account you have created on FreeNAS?
There’s more than a few ways to set up permissions and I only know some basic in this regard.

I think the easiest thing is to use the group permission. (NOT inside the jail, use the FreeNAS GUI)

  • On your FreeNAS create the hass group with a GUID = 8123
  • Add the hass group to your FreeNAS user account

Also you mention NFS share. I’m using samba shares. Either one should work but something to keep in mind. You’ll see in the guide when I’m setting up the share I added some directory and file create masks to the samba share settings. This causes new file to be created already having the group permission set to read/write. By default new files will only allow the group the have read permission. This means if you create or copy a new file into the homeassistant directory, HA (technically hass, the user running HA) will be able to read the file but may not be able to save any changes it makes to the file. These create masks only apply to samba shares though. You may need to take addition steps or use the configurator to create new files.

For example if I make two file in my HA directory, One using samba share and the other over ssh you see the difference in default permissions as the file have been created. Only the file created over samba has group RW set.


The configurator is run by user hass as well and can further illustrate. In other words, Home Assistant has the same permissions to read or write files as the configurator dose because they are both run by the same user.

The file created over samba

The file created over ssh

If at any time you need to fix your permissions for HA, while not required, I find the best results doing so from inside the homeassistant jail since that’s where the main hass user exists and where HA is running. I’ll fix up the file __NEW_FILE_OVER_SSH as a quick example

iocage console homeassistant
  • Change the owner
chown hass:hass /home/hass/homeassistant/__NEW_FILE_OVER_SSH
  • Set group permissions (While there are numerous ways to do this, I think this is most simple and to the point. I don’t always want RW permissions for the group. What I actually want is the group to have the same permission the user has, so I use “group = user”
chmod g=u /home/hass/homeassistant/__NEW_FILE_OVER_SSH

And now the resulting permissions


These are the same commands but would set the entire homeassistant directory and everything in it

chown -R hass:hass /home/hass/homeassistant
chmod -R g=u /home/hass/homeassistant


You can work around all this as well by simply creating new files using the configurator.
This results correct file permissions as they will be owned by hass with RW for group


To be clear that applies to creating new files. If I create an empty file with configurator, it has been created with the proper permissions. Now I can still even open and edit the file over ssh and safely save changes. It will not break or takeaway the group RW permission once they have been properly set

Hope that helps!

@troy

That was very informative thanks. So if I wanted to change the group from Hass to say Shared it would be.

chown -R hass:Shared /home/hass/homeassistant
chmod -R g=u /home/hass/homeassistant

that would leave me with Hass still good to go and everything working fine in HA and with a different group associated with the files that lets me access things in windows through the NFS.

Thanks again

hmm… The commands would change but I don’t know if you can just change the group like that.

I think first, you need to created the Shared group inside the jail. Then HA needs to run using that group and user hass also needs to be a member inside the jail. I’m not 100% sure though. I did put in the service files the ability to set the HA user and group it runs as but changing these are not tested.

I think this should work but again I’m not really 100% sure. On your FreeNAS you need to see what the group ID number is for Shared. You need to use the same number in the command below. I will use 1234 as a placeholder. Replace 1234 with the GUID of the group Shared

iocage console homeassistant
pw addgroup -g 1234 -n Shared
pw groupmod Shared -M hass

service homeassistant stop
sysrc homeassistant_group=Shared
chown -R hass:Shared /home/hass/homeassistant
chmod -R g=u /home/hass/homeassistant
service homeassistant start

I think that should work but again I never tested it.

@troy

That did the trick, thanks again. Really appreciate the help and the useful explanations of concepts behind it.

Enjoy your weekend

1 Like

I’m having issues implementing the Long Live access token. I looked in the forums and manuals but can’t find what if anything I’m supposed to write in configuration.yaml. The steps I took were.

  1. Generate token in GUI
  2. Copy token
  3. Paste token in secret yaml for appdaemon
  4. Uncomment all references to token
  5. Comment out all references to legacy api

Below are screen caps of my yaml files

What I am I missing? Any help would be appreciated. Thanks

Everything looks correct to me… I’m not sure. I can only think of a few things to try right now.

  1. Do you have ip_ban_enabled: in your HA config? Check if you have banned ip connection from appdaemon. There will be a file in HA config directory called something like ip_bans.yaml. If that file exists delete it and try appdaemon again.

  2. Reset the ha_url: and dash_url: back to http://127.0.0.1:8123

  3. Move your token directly into appdaemon.yaml

I think it was something as dumb as not having a space between token: and the actual token.

I’m curious why its not necessary to have the correct ip in the ha_url or dash_url.

I’ve started using VS code to work so I’ll be able to spot mistakes like the token one in the future.

Thanks again @troy

Ahh glad you got it!

127.0.0.1 works because it is the loopback address. You can use that because appdaemon and HA are on the same host (same the host jail, not same FreeNAS host).

1 Like

Hi,
Great tutorial, i followed the manual version to install home-assistant but now i can’t figure out how to install appdeamon, any tips?

This worked my install on freenas.

Appdaemon should be installed in the Home Assistant jail but using a separate virtual environment.

You can manually install appdaemon with these steps beginning from logging into the jail.

iocage console homeassistant

You may notice this very similar to manually installing HA.

install -d -g hass -o hass -m 775 -- /srv/appdaemon
su - hass
    virtualenv -p /usr/local/bin/python3.6 /srv/appdaemon
    source /srv/appdaemon/bin/activate
    pip3 install --upgrade pip
    pip3 install --upgrade appdaemon
    deactivate && exit

You’ll also need a service file to start appdaemon auto-magically

ee /usr/local/etc/rc.d/appdaemon
Show File: /usr/local/etc/rc.d/appdaemon
#!/bin/sh

# PROVIDE: appdaemon
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# appdaemon_enable:	Set to YES to enable the appdaemon service.
#			Default: NO
# appdaemon_user:	The user account used to run the appdaemon daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run as root.
#			Default: USER_NAME
# appdaemon_group:	The group account used to run the appdaemon daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run with group wheel.
#			Default: USER_GROUP
# appdaemon_config_dir:	Directory where appdaemon config is located.
#			Default: ~/appdaemon/conf
#
# copy this file to /usr/local/etc/rc.d/appdaemon 
# chmod +x /usr/local/etc/rc.d/appdaemon
#
# sysrc appdaemon_enable=yes                # to enable
# sysrc appdaemon_config_dir="~/appdaemon"  # to change
# service appdaemon start                   # to start

. /etc/rc.subr
name=appdaemon
rcvar=${name}_enable

pidfile_child="/var/run/${name}.pid"
pidfile="/var/run/${name}_daemon.pid"
logfile="/var/log/${name}_daemon.log"

load_rc_config ${name}
: ${appdaemon_enable:="NO"}
: ${appdaemon_user:="hass"}
: ${appdaemon_group:="hass"}
: ${appdaemon_config_dir:="/home/hass/appdaemon/conf"}

command="/usr/sbin/daemon"

start_precmd=${name}_precmd
appdaemon_precmd()
{
        rc_flags="-f -o ${logfile} -P ${pidfile} -p ${pidfile_child} /srv/appdaemon/bin/appdaemon -c ${appdaemon_config_dir} ${rc_flags}"
        
    if [ ! -e "${pidfile_child}" ]; then
            install -g ${appdaemon_group} -o ${appdaemon_user} -- /dev/null "${pidfile_child}";
    fi

    if [ ! -e "${pidfile}" ]; then
            install -g ${appdaemon_group} -o ${appdaemon_user} -- /dev/null "${pidfile}";
    fi

    if [ ! -e "${logfile}" ]; then
        install -g ${appdaemon_group} -o ${appdaemon_user} -- /dev/null "${logfile}";
    fi
 
    if [ ! -d "${appdaemon_config_dir}" ]; then
        install -d -g ${appdaemon_group} -o ${appdaemon_user} -- "${appdaemon_config_dir}";
    fi
}

stop_postcmd=${name}_postcmd
appdaemon_postcmd()
{
    rm -f -- "${pidfile}"
    rm -f -- "${pidfile_child}"
}

run_rc_command "$1"

copy and paste. Press escape then enter twice to save and exit
Finally make this file executable, enable and start appdaemon service

chmod +x /usr/local/etc/rc.d/appdaemon
sysrc appdaemon_enable=yes 
service appdaemon start

Also, appdaemon will not start without a configuration file.

Starting appdaemon with the provided service file, will by default, be looking for the configuration file /home/hass/appdaemon/conf/appdaemon.yaml You can look at the examples I have HERE to see the folder structure. Note these are not in anyway special or even “official” config files. They contain only the minimum to get the services to start. You can use as a starting point or completely replace them with your own.

That worked, thank you very much

1 Like

Hi,
I have no clue what I am doing wrong or missing. I have homeassistant for a while now (3 years) on a RPI3. And I want to migrate it to freenas (old PC) for convinience. Freenas is working fine for quite a while and found time now to do it. Running 11.2-U6.

But on the first attempts to make a jail, I am already getting errors at the section iocage standard-jail – Scripted Install
command

wget -O /tmp/pkglist.json https://raw.githubusercontent.com/tprelog/iocage-homeassistant/master/pkg-list.json

but the following code:

sudo iocage exec homeassistant bash /root/.iocage-homeassistant/post_install.sh standard

throws an error:

Sorry, user root is not allowed to execute '/usr/local/bin/iocage create -r 11.2-U6 boot=on dhcp=on bpf=yes vnet=on vnet_default_interface=auto -p /tmp/pkglist.json -n homeassistant' as root on freenas.local.

Someone an idea?

EDIT: I got the solution already, the shell is already root, so the script runs withouth ‘sudo’ fine.
I would suggest an addition in the manual for this. (SSH as root: remove sudo from the commands)

Hi Koen,
Sorry for the confusion. I plan on updating a few things here in the near future. I’ll be sure to add a note about not using sudo when your already the root user.

Hi,
Thnx for the quick reply, I am now still working on it. I tried the scripted version, but got stuck on the next line I had to run, so now I have done the manual install. It should be up and running, and I see that there is a live connection on my IP, but if I browse my jailIP:8123 I get nothing. Am I missing something?

Everything on the manual install went great, (except that I did not had permission to use the pkg) fixed with https://www.justinsilver.com/technology/linux/fix-pkg-on-freenas-11-2/

Cheers,

With the manual install the could be any number of things missed to prevent HA from starting. Also it can take 2-3 minutes for HA to start for the first time… or even longer depending on how old your PC is.

You can check if HA is running from the terminal. Starting from FreeNAS

iocage console homeassistant
service homeassistant status

Really the best thing is to use the script. It might be quicker to help you with that if HA is not running correctly, since there are less steps involved. Really it only takes a few minutes to just start over with a fresh jail rather than troubleshoot a new install.

Did you have to do this inside the jail or on FreeNAS?