npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netatmo-presence-onoff

v1.0.3

Published

Code to turn ON or OFF the monitoring state of your Netatmo Presence cameras

Downloads

4

Readme

netatmo-presence-onoff

Code to turn ON or OFF the monitoring state of your Netatmo Presence cameras directly from Javascript !

usage

Prerequisite

You may rely on environment variables either as system env vars or within a .env file loaded with a tool such as dotenv to create a Netatmo Presence controller. While this is not mandatory to rely on env vars, the controller expect 4 parameters as described below:

NETATMO_USERNAME="XXXXXXXXXX"
NETATMO_PASSWORD="XXXXXXXXXX"
NETATMO_CLIENT_ID="XXXXXXXXXX"
NETATMO_CLIENT_SECRET="XXXXXXXXXX"
  • NETATMO_USERNAME and NETATMO_PASSWORD is your credentials to access your Netatmo Security application.
  • NETATMO_CLIENT_ID and NETATMO_CLIENT_SECRET are two values you get when you create an application within Netatmo Connect which is the landing portal for the developper community.
    • Connect to https://dev.netatmo.com/apps/ with your Netatmo credentials
    • Create a new app and fill only the required fields (marked by a *)
    • Once saved you instantly get your Cliend ID and Client Secret to fill both environment variable

Turning your cameras ON or OFF

This is as simple as that:

const netatmo = require("netatmo-presence-onoff");

console.log("Et c'est parti pour le show");

let ctrl = new netatmo.NetatmoPresenceController(
            process.env.NETATMO_CLIENT_ID,
            process.env.NETATMO_CLIENT_SECRET,
            process.env.NETATMO_USERNAME,
            process.env.NETATMO_PASSWORD);

await ctrl.TurnMonitoringOn();
await ctrl.TurnMonitoringOff();

The function returns a Promise so you have the choice to await or then/catch something such as:

ctrl.TurnMonitoringOn()
.then(() =>
{
    console.log("C'est magnifique");
});

Passing your Home IDs along

Introduction

If you don't know your home ID and camera ID the library will get it for you. However there are cases where you're already aware of them and it may be easier for you to pass these values along at the object creation. Doing so will avoid an HTTP request to the Netatmo endpoint to get your home information thus making your overall call to TurnMonitoringOn() or TurnMonitoringOff() a little bit faster. There are no API calls during the object creation so if you make mistakes regarding the values at the creation time you'll only be able to be aware when calling the public functions of the object.

Now the code

The expected format to add your Home IDs is as below:

let homes =
[
    {
        id: "My first home ID",
        modules:
        [
            { id: "My first camera ID for my current home ID" },
            { id: "My second camera ID for my current home ID" }
            /* and so on */
        ]
    },
    {
        id: "My second home ID",
        modules:
        [
            { id: "My first camera ID for my current home ID" },
            { id: "My second camera ID for my current home ID" }
        ]
    },
    /* and so on */
];

Most of the time you'll have only one Home ID with one or two camera such as:

let homes =
[
    {
        id: "ABCDEFGHIJKLMNPO",
        modules:
        [
            { id: "AB:CD:EF:00:00:01" },
            { id: "AB:CD:EF:00:00:02" }
        ]
    }
];

Then you can build the controller by adding your homes tab as the last parameter:

let ctrl = new netatmo.NetatmoPresenceController(
            process.env.NETATMO_CLIENT_ID,
            process.env.NETATMO_CLIENT_SECRET,
            process.env.NETATMO_USERNAME,
            process.env.NETATMO_PASSWORD,
            homes);

Troubleshooting the dev side

  • "Ok bro but where could I get my camera IDs ??" => Heads to your Netatmo Security app on your smartphone, the camera ID is the serial number of your camera.

  • "You killing it man but I'm stuck finding my home ID. Any ideas ?" => That's more tricky as you need to call the Netatmo API on the /homesdata path. The GetHomes() function on the controller returns a deep copy of the homes tab so my advise would be to create an object without homes passed along, turn the monitoring either on or off then call the GetHomes() and console.log the object to get the values.

let ctrl = new netatmo.NetatmoPresenceController(
            process.env.NETATMO_CLIENT_ID,
            process.env.NETATMO_CLIENT_SECRET,
            process.env.NETATMO_USERNAME,
            process.env.NETATMO_PASSWORD);

await ctrl.TurnMonitoringOff();

console.log(JSON.stringify(ctrl.GetHomes()));

Fair enough? :-)