I never used the 1.0 API so I’m unable to relate the differences.
Same here, I didn’t much time trouble-shooting though, I figure it’s missing login credentials but I don’t see a way to edit / add those from the web page view.
I’m just taking the primitive approach. I have the api page open for reference, and I’ve just been working my way through bit by bit using curl and piping through jq to help make results easier read in the terminal.
json_attributes:
- uptime
- version
- model
- cores
Sorry for my late answer. I didn’t have time to take care of things over the weekend.
Too bad, with the web interface it was very convenient. OK, thanks to your tip on the command line, I’m able to use the API documentation to get the relevant information. It’s a bit of work in the beginning, but the main thing is that it works. I could only go via the API key because I can’t create an API key. I think this is because I’m still on FreeNas 11.3.4 and I can’t create an API Key.
@troy, have you had a chance to play around more with the 2.0 API? Anyone else?
I can’t find a simple way to pull the available space in a pool, ideally just as a percentage free or something like that. The old sensor had a used_pct attribute.
Also, I don’t know how to properly handle the alerts. Right now I’m using:
So with all the bits and pieces that everyone has posted here and elsewhere, these are my TrueNAS sensors that all work with the 2.0 API and don’t rely on scripts, and this is my monitor page:
The CPU temperature request and handling is quite cumbersome. I’m glad you figured it out and shared it!
I’ve tried looking at the online API documentation to find an easier to use endpoint for this information, but it loads soooo slowly and often crashes my browser.
hello reven! A true newbie here. First of all, Thanks you all very much for making things easier, and I apologize in advance for not being on your level. I’d like to know if you could help me get some information to make it work. The information I don’t understand is where do you get the api key for authorization? do you have to configure something in freenas? I tried to follow the steps but English is not my native language, so I got lost.
TrueNAS 12.0 and later has the ability to use API keys instead of login credentials. Unfortunately, there is no way to use the API key on FreeNAS 11.3.
Here’s the link for the TrueNAS docs
Basically
To create an API key, open the [ TrueNAS ] web interface (Settings) menu and click API KEY .
Click Add , enter a new key name, and click Add again to confirm. Immediately after the API key is created, you can use the key locally by clicking Copy to Clipboard . The API key can only be copied immediately after creation. When the initial creation window is closed, the API key cannot be copied again.
EDIT: For those still using FreeNAS 11.3, I have modified the # General info sensor from @reven great example, to show how you can use login credentials instead of an API Key.
# General info
- platform: rest
name: tn_info
resource: http://192.168.1.4/api/v2.0/system/info
authentication: basic
username: !secret tn_user
password: !secret tn_passwd
headers:
Content-Type: application/json
User-Agent: Home Assistant
scan_interval: 3600
value_template: '{{ value_json.uptime }}'
json_attributes:
- uptime_seconds
- version
- model
- cores
Thanks @reven, brilliant stuff.
Mostly working here though I was unable to get the alert message to show content for some reason.
Oh, and for others confused with using API keys, you need to make sure it’s precursered with “Bearer”.
So for myself I set my tn_api_key variable to something like:
tn_api_key: Bearer 1-SomerandomAPIkeystringthing
EDIT: okay so found the reason for the missing alert message, my current warning message of pools eligible for upgrade was more than the 255 character limit allowed for a sensor state. Something to keep in mind.
Alternatively you can change the log level to debug for the rest integration. I think this will post the response to your logs. I don’t prefer this method as it likely will spam your logs.