Came here to ask this. From what I can tell, there’s no API endpoint for turning the camera on and off or for controlling the night light. Instead, those commands seem to be sent to the camera directly via the WSS connection. I’ll be working on this over the coming days, so if I make any progress, I’ll post an update.
My Nanit docker is still working great as I have been able to avoid MFA (multi factor authentication) enforcing by not using my login through the app. I am technically still logged in I suppose, but without MFA. Either my wife monitors, or I monitor through Home Assistant. Does anyone know if I was to login to the app with my wife’s username, or add a new member login, if I would be able to keep my original login working with HA without MFA, but still use the app logged in as either my wife or a new user?
Aside from all this, has anyone been able to integrate Nanit with HA with MFA enabled?
EDIT: NM on the last question. I found the article regarding setup with 2FA.
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
Hi Jakee!
Do you have a link to the “nanit collection”? My wife is on me to get the monitor back up and running in HA.
Edit: Found the API link a few posts above. Got this working! Curious to know how long yours has gone for un-interupted!
Thanks!
Not the person you asked, but mine has been solid for over a week now.
I took a different approach to this problem and I created a plugin for Scrypted. I liked this approach for a couple reasons
- Scrypted is fast. The video delay is under 1 second. It’s as good as watching the video in nanit
- Scrypted has native support for rebroadcasting as RTSP which works well with HA
- You can add external motion/sound detection through Scrypted
- HKSV, i am actually using Scrypted for homekit for the HKSV
Caveat is that I use the external RTMP stream (rtmp://media-secured.nanit.com/…). It also doesn’t do anything with temp/humidity or motions.
If there is interest, I would be happy to clean it up a bit and open source it.
I’d be interested in giving it a try.
Same, would love to try but would need more detail. Looks interesting.
I’ll do some more cleanup to it this week. Here is a working implementation and a readme with instructions. GitHub - zone99dev/scrypted-nanit
It seems to work, but I haven’t tried adding it to HA yet. I’ll get to that tomorrow.
There might be a missing step from the installation instructions. I needed to run npm run build
before I was able to deploy.
I got most of this working but the camera card still not showing anthing.
The secrets.yaml contains the correct url with the token and I can use the url with rtmpdump and vlc but the card does not show anything and I get the following error:
ERROR (stream_worker) [homeassistant.components.stream.stream.camera.jack] Error from stream worker: Error opening stream (ERRORTYPE_5, I/O error) rtmps://media-secured.nanit.com/nanit/xxxxxxx.YYYYYYYYYYYYYYYYYYYYY
Any suggestion? I am not sure if I have to install or configure something else in home assistant to have the camera (ffmpeg) to work.
Thanks in advance.
Never mind me… stupidly, I didn’t have the ffmpeg integration enabled in my configuration.yaml
good catch, i fixed that
@zone99 THANK YOU!!
This was super simple to follow and setup from scratch. I didn’t have Scrypted before, and now it’s feeding the Nanit RTSP stream into HomeAssistant and through to HomeKit as well. This is so awesome.
Thanks!!
I am very new at this and I was trying the scrypted route today but I am stuck in one of the very first steps
- Open this plugin directory in VS Code
- In a terminal cd into this project directory
Where it says open this plugin directory was there supposed to be a link there?
For anyone interested in this, I finally had some time to set up a MITM proxy and look at some of the traffic here. It looks like to turn the camera on and off, the app actually starts and stops the remote video stream. If stopped, there are a couple of other API requests and the camera turns off. When restarted, the camera turns on. I don’t have the camera itself going through the MITM proxy, so I don’t know what happens on its side when that stream stops, but I’ll work on that next.
I am getting this error even after login in with the npx
TypeError: Cannot read properties of undefined (reading ‘username’)
at getLogin (C:\Users\The Surge\Git\scrypted-nanit\node_modules@scrypted\sdk\bin\index.js:35:25)
at C:\Users\The Surge\Git\scrypted-nanit\node_modules@scrypted\sdk\bin\index.js:86:20
at new Promise ()
at exports.deploy (C:\Users\The Surge\Git\scrypted-nanit\node_modules@scrypted\sdk\bin\index.js:57:12)
at Object. (C:\Users\The Surge\Git\scrypted-nanit\node_modules@scrypted\sdk\bin\scrypted-deploy.js:16:10)
at Module._compile (node:internal/modules/cjs/loader:1226:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1280:10)
at Module.load (node:internal/modules/cjs/loader:1089:32)
at Module._load (node:internal/modules/cjs/loader:930:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Authorization required. Please log in with the following:
npx scrypted login [ip]
Is this published such that I can install it from within an existing HAOS > Scrypted (as an add on) workflow? I’m guessing not, since I don’t see it listed… perhaps this super cool idea isn’t ready for that level of prime time, though?! Super cool work, nonetheless!
Yes, there’s an HA add on available via the scrypted repo.
I have this working, but there’s no video preview in HA or scrypted. Is this due to the battery mode?