Constructs a new instance of the MysaApiClient.
The credentials of the Mysa account to authenticate as.
Optionaloptions: MysaApiClientOptions
The options for the client.
ReadonlyemitterEvent emitter for client events.
MysaApiClientEventTypes for the possible events and their payloads.
Retrieves firmware information for all devices.
A promise that resolves to the firmware information for all devices.
MysaApiError When the API request fails.
UnauthenticatedError When the client cannot authenticate with its credentials.
Retrieves the list of devices associated with the user.
This method fetches all Mysa devices linked to the authenticated user's account, including device information such as models, locations, and configuration details.
A promise that resolves to the list of devices.
const devices = await client.getDevices();
for (const [deviceId, device] of Object.entries(devices.DevicesObj)) {
console.log(`Device: ${device.DisplayName} (${device.Model})`);
}
MysaApiError When the API request fails.
UnauthenticatedError When the client cannot authenticate with its credentials.
Retrieves the serial number for a specific device.
This method uses AWS IoT's DescribeThing API to fetch the serial number attribute for the specified device. This requires additional AWS IoT permissions and may not be available for all devices.
The ID of the device to get the serial number for.
A promise that resolves to the serial number, or undefined if not found.
const serialNumber = await client.getDeviceSerialNumber('device123');
if (serialNumber) {
console.log(`Device serial: ${serialNumber}`);
} else {
console.log('Serial number not available');
}
UnauthenticatedError When the client cannot authenticate with its credentials.
Retrieves the current state information for all devices.
A promise that resolves to the current state of all devices.
MysaApiError When the API request fails.
UnauthenticatedError When the client cannot authenticate with its credentials.
Retrieves information about all homes associated with the user.
A promise that resolves to the homes information.
MysaApiError When the API request fails.
UnauthenticatedError When the client cannot authenticate with its credentials.
Ensures the client has a usable session, logging in with the credentials it was constructed with if needed.
Calling this method is optional: the client authenticates on demand before its first API call, and re-authenticates on its own whenever its session can no longer be refreshed. Call it explicitly at startup to fail fast on invalid credentials instead of on the first API call. It is a no-op when the current session is still usable.
try {
await client.login();
console.log('Login successful!');
} catch (error) {
console.error('Login failed:', error.message);
}
UnauthenticatedError When authentication fails due to invalid credentials or network issues.
Sets the state of a specific device by sending commands via MQTT.
This method allows you to change the temperature set point and/or operating mode of a Mysa device. The command is sent through the MQTT connection for real-time device control.
The ID of the device to control.
OptionalsetPoint: number
The target temperature set point (optional).
Optionalmode: MysaDeviceMode
The operating mode to set (one of MysaDeviceMode values, or undefined to leave unchanged).
OptionalfanSpeed: MysaFanSpeedMode
The fan speed mode to set ('low', 'medium', 'high', 'max', 'auto', or undefined to leave unchanged).
OptionaltrackedSensor: MysaTrackedSensor
The sensor an in-floor thermostat should regulate against, or undefined to leave unchanged.
// Set temperature to 22°C
await client.setDeviceState('device123', 22);
// Turn device off
await client.setDeviceState('device123', undefined, 'off');
// Set temperature and mode
await client.setDeviceState('device123', 20, 'heat');
// Set fan speed
await client.setDeviceState('device123', undefined, undefined, 'auto');
UnauthenticatedError When the client cannot authenticate with its credentials.
UnknownDeviceError When the device id does not match any device on the account.
UnsupportedFanSpeedError When the requested fan speed is not supported by the device.
UnsupportedTrackedSensorError When a tracked sensor is requested for a device that has no floor probe to select.
Chooses which temperature sensor an in-floor heating thermostat regulates against.
In-floor units (INF-V1-0) carry both an ambient air sensor and a probe embedded in the floor, and this selects between them — the same setting the Mysa app exposes. The device confirms the change on its next status message via Status.trackedSensor, and immediately via StateChange.trackedSensor.
The ID of the in-floor thermostat to control.
The sensor to regulate against.
UnauthenticatedError When the client cannot authenticate with its credentials.
UnknownDeviceError When the device id does not match any device on the account.
UnsupportedTrackedSensorError When the device is not an in-floor thermostat.
Subscribes to raw MQTT topic filters and relays every message verbatim.
Unlike startRealtimeUpdates, this performs no parsing, emits no typed events and sends no "start publishing"
request to the device — it simply forwards the full message topic and the decoded UTF-8 payload of everything that
arrives on the given filters. It exists to reverse-engineer device families the SDK does not model yet, most
notably the AWS IoT Device Shadow protocol used by the central-HVAC ST-V1 thermostats, where both the topic (which
shadow, and accepted/rejected/delta/documents) and the raw JSON body carry the information a new
implementation needs.
The capture is passive: the device only publishes to its shadow topics when something drives a change (the Mysa mobile app, a schedule, or the device itself), so exercise the thermostat while a capture is running.
Registered filters are re-subscribed automatically after a reconnect.
MQTT topic filters to subscribe to. Wildcards (+, #) are allowed, subject to the AWS IoT
policy attached to the account's Cognito identity — a filter the policy forbids resolves with a non-zero
error_code, which is logged rather than thrown so the remaining filters still subscribe.
Invoked with the full message topic and the decoded UTF-8 payload for every message received.
Starts receiving real-time updates for the specified device.
This method establishes an MQTT subscription to receive live status updates from the device, including temperature, humidity, set point changes, and other state information. The client will automatically send keep-alive messages to maintain the connection.
The ID of the device to start receiving updates for.
Stops receiving real-time updates for the specified device.
This method unsubscribes from the MQTT topic for the specified device and clears any associated timers to stop the keep-alive messages.
The ID of the device to stop receiving real-time updates for.
Main client for interacting with the Mysa API and real-time device communication.
The MysaApiClient provides a comprehensive interface for authenticating with Mysa services, managing device data, and receiving real-time updates from Mysa thermostats and heating devices. It handles both REST API calls for device management and MQTT connections for live status updates and control commands.
Example