Hello,
I had Adam’s solution working for a long time and then when MFA was forced, it stopped working. Using a bunch of different replies in this thread I have put together something that works (just over a day), and I’m sure someone else can improve upon it. It’s not ideal I admit, but it works for me.
This is my first post here, so I’m only allowed to post 2 links. Therefore I can’t post the full url for the APIs, but it’s just the api url plus the endpoint specified.
Step 1: Getting your Access Token, Refresh Token, and Baby UIDs
- Download Postman and the Nanit collection
Send a POST request to this url: /login
In the Body of the request enter your username and password like this:
{
"email" :"youremail",
"password" :"yourpassword"
}
In your headers, make sure you set nanit-api-version as 1 (type nanit-api-version in the left column, 1 in the right)
In the response you will get a MFA token:
{
"mfa_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"phone_suffix": "xx",
"channel": "sms"
}
Now we need to send a POST request to this url endpoint: /login
In the body of the request enter the mfa_token value from the previous response and the 4-digit code that was sent to whatever you have setup in Nanit (SMS, maybe email?):
{
"mfa_token" :"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"chennel" :"sms",
"mfa_code" :"xxxx",
"password":"yourpassword",
"email":"youremail"
}
At the very bottom of the response you will see 3 values:
...
"access_token": "db03a76aba913bc952fd23db9f890b60dee8df94761378af",
"refresh_token": "4eaa5af7db14a34773348bc476a9f5cfd7f37e68f9bf81bb",
"token": "db03a76aba913bc952fd23db9f890b60dee8df94761378af"
...
Take note of these values.
Now you will send a GET request to this url endpoint: /babies
The only thing you need to send is your access token in the headers. If you’re using Postman, it already does that for you. Look in the response for uid and your baby’s name should be nearby. If you have multiple cameras, there will be more than 1 of these ids and you will need to look for the name to know which is which (or look at the camera feed later I guess?).
Step 2: Refreshing your token every hour with python
There’s probably a better way to do this, but it works. First make sure you’ve followed all the steps to use python scripts in your instance. Here: Python Scripts - Home Assistant
I am assuming you have this set up for the rest of the instructions.
Save your access token and refresh token from step 1 in files called access.token and refresh.token and put them in your python_scripts folder.
Save the refresh.py from here: https://github.com/jakeledwards/nanitTokenRefresh in your python_scripts folder and update the file with your baby’s uid.
Step 3: Set up cameras and automate the refresh token
Place this in your configuration.yaml with your cameras:
camera:
- name: Tiny Tim
platform: ffmpeg
input: !secret nanit_access_1
- name: Little Jonny
platform: ffmpeg
input: !secret nanit_access_2
Place this in your configuration.yaml with your other shell commands. If you don’t have any other ones, just put it somewhere nice.
shell_command:
update_nanit_token: "python3 /config/python_scripts/refresh.py > /config/www/log.log"
Place this in your automations.yaml
- id: 'xxxxxxxxxx'
alias: Nanit Token Update
description: Refreshes the Nanit token every hour and then reloads the configuration.yaml
trigger:
- platform: time_pattern
minutes: /5
condition: []
action:
- service: shell_command.update_nanit_token
data: {}
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: homeassistant.reload_core_config
data: {}
mode: single
Open your secrets.yaml and place this at the bottom:
nanit_access_1: xxthiscanbeanythingatallincludingthisxx
Restart Home Assistant
Step 4: Configure your lovelace dashboard
Place this card in your dashboard:
cards:
- show_state: false
show_name: true
camera_view: auto
type: picture-entity
entity: camera.jack
camera_image: camera.jack
theme: Graphite
aspect_ratio: '16:9'
image: >-
https://dm41breupsxmi.cloudfront.net/babies/29c2bc1c/VWZnMBUM-8MJkcMvWoam5w.jpg