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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mysa-js-sdk

v2.0.3

Published

A JavaScript SDK for accessing Mysa smart thermostats.

Readme

Mysa Smart Thermostat JavaScript SDK

All Contributors

NPM Version CodeQL CI: lint, build and release

A JavaScript SDK for accessing Mysa smart thermostats.

Description

This SDK provides a simple and intuitive way to interact with Mysa smart thermostats, allowing developers to easily query and update data from their Mysa smart thermostats, including real-time updates.

Disclaimer

This SDK was developed without the consent of the Mysa Smart Thermostats company, and makes use of undocumented and unsupported APIs. Use at your own risk, and be aware that Mysa may change the APIs at any time and break this repository permanently.

Installation

Prerequisites

  • You must own at least one Mysa Smart Thermostat or have credentials to access a working setup.
  • Node.js version 22.4.0 or higher.
# Using npm
npm install mysa-js-sdk

# Using yarn
yarn add mysa-js-sdk

# Using pnpm
pnpm add mysa-js-sdk

Running the Example Application

To run the example application, you'll need to provide your Mysa credentials. Create a .env file in the project root:

[email protected]
MYSA_PASSWORD=your-password

Then, run the example:

npm run example

If you prefer to see the raw data published by your Mysa smart thermostats, run:

npm run example:raw

Using

The Mysa SDK provides a simple interface to interact with Mysa smart thermostats.

Basic Authentication

import { MysaApiClient } from 'mysa-js-sdk';

const client = new MysaApiClient();

// Login with email and password
await client.login('[email protected]', 'your-password');

// Check if authenticated
if (client.isAuthenticated) {
  console.log('Successfully authenticated!');
}

Retrieving Thermostat Data

Once authenticated, you can access your thermostat data:

// Get all devices
const devices = await client.getDevices();

// Access individual devices
for (const [deviceId, device] of Object.entries(devices.DevicesObj)) {
  console.log(`Device: ${device.Name}`);
  console.log(`Model: ${device.Model}`);
  console.log(`Location: ${device.Location}`);
  console.log(`Voltage: ${device.Voltage}V`);
}

// Set device temperature and mode
await client.setDeviceState('device-id', 22, 'heat'); // Set to 22°C in heat mode
await client.setDeviceState('device-id', undefined, 'off'); // Turn off

Real-time Updates

The SDK also supports real-time updates:

// Listen for temperature and status changes
client.emitter.on('statusChanged', (status) => {
  console.log(`Device ${status.deviceId}:`);
  console.log(`  Temperature: ${status.temperature}°C`);
  console.log(`  Humidity: ${status.humidity}%`);
  console.log(`  Set Point: ${status.setPoint}°C`);
  if (status.current !== undefined) {
    console.log(`  Current: ${status.current}A`);
  }
});

// Listen for setpoint changes
client.emitter.on('setPointChanged', (change) => {
  console.log(`Setpoint changed from ${change.previousSetPoint}°C to ${change.newSetPoint}°C`);
});

// Listen for device state changes
client.emitter.on('stateChanged', (change) => {
  console.log(`Device mode changed to: ${change.mode}`);
  console.log(`New setpoint: ${change.setPoint}°C`);
});

// Start real-time updates for all devices
const devices = await client.getDevices();
for (const deviceId of Object.keys(devices.DevicesObj)) {
  await client.startRealtimeUpdates(deviceId);
}

Error Handling

The SDK provides specific error types to handle API errors:

import { MysaApiClient, MysaApiError, UnauthenticatedError } from 'mysa-js-sdk';

const client = new MysaApiClient();

try {
  await client.login('[email protected]', 'password');
  const devices = await client.getDevices();
} catch (error) {
  if (error instanceof UnauthenticatedError) {
    console.error('Authentication failed:', error.message);
  } else if (error instanceof MysaApiError) {
    console.error(`API Error ${error.status}: ${error.statusText}`);
  } else {
    console.error('Unexpected error:', error);
  }
}

Advanced Configuration

You can customize the client with various options:

import { MysaApiClient } from 'mysa-js-sdk';
import { pino } from 'pino';

// Create a custom logger
const logger = pino({
  name: 'mysa-client',
  level: 'debug'
});

// Configure client with options
const client = new MysaApiClient(undefined, {
  logger: logger,
  fetcher: fetch // Custom fetch implementation if needed
});

// Or restore from a saved session
const savedSession = {
  username: '[email protected]',
  idToken: 'eyJ...',
  accessToken: 'eyJ...',
  refreshToken: 'abc123...'
};

const clientWithSession = new MysaApiClient(savedSession, { logger });

// Listen for session changes to persist them
client.emitter.on('sessionChanged', (newSession) => {
  if (newSession) {
    // Save session to storage (file, database, etc.)
    localStorage.setItem('mysaSession', JSON.stringify(newSession));
  } else {
    // Session expired or logged out
    localStorage.removeItem('mysaSession');
  }
});

Reference documentation

The complete reference documentation for the mysa-js-sdk library can be found at https://bourquep.github.io/mysa-js-sdk/.

Contributing

If you want to contribute to this project, please read the CONTRIBUTING.md file for guidelines.

License

mysa-js-sdk is licensed under the MIT License. This is a permissive license that allows you to use, modify, and redistribute this software in both private and commercial projects. You can change the code and distribute your changes without being required to release your source code. The MIT License only requires that you include the original copyright notice and license text in any copy of the software or substantial portion of it.

Copyright

© 2025 Pascal Bourque

Support

For bug reports and feature requests, please use the GitHub Issues page.

For general questions and discussions, join our Discussion Forum.

Acknowledgments

This library would not be possible without the amazing work by @dlenski in his mysotherm repository. He's the one who reversed-engineered the Mysa MQTT protocol which is being used by this library.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!