Comfort cloud API wrapper to control HVAC (web.daichicloud.ru)
- Daichi Comfort Cloud API
$ npm i daichi
import { DaichiApi } from './api'
const daichi = new DaichiApi('[email protected]', 'login_password_123')
const devices = await daichi.getDevices()
Params:
- username (
string
) - required - password (
string
) - required - daichiApi (
string
) - optional, defaults tohttps://web.daichicloud.ru/api/v4/
- clientId (
string
) - optional, defaults tosOJO7B6SqgaKudTfCzqLAy540cCuDzpI
Returns: Promise<DaichiBuilding[]>
Returns: Promise<DaichiDevice[]>
Params:
- deviceId (
number
) - device id fromgetBuildings()
orgetDevices()
response
Returns: Promise<DaichiDevice>
Params:
- deviceId (
number
) - device id fromgetBuildings()
orgetDevices()
response - functionId (
number
) - function id, every device has list of functions. Functions may be uniq from model to model. So check your device response for function ids. - val (
number | boolean
) - value, can be boolean forisOn
functions (modes, on/off, start/stop slides, etc) or can be a number (temperature, fan speed, etc)
Returns: Promise<DaichiControl>
Returns: Promise<MqttUser>
- id (
number
) - userId to listen user topics - username (
string
) - mqtt username - password (
string
) - mqtt password
Example usage with mqtt package.
const mqttUser = await daichi.getMqttUserInfo()
const mqtt = connect('wss://split.daichicloud.ru/mqtt', {
username: mqttUser.username,
password: mqttUser.password
})
mqtt.on('message', (topic, message) => {
console.log(topic, message.toString())
})
mqtt.subscribe(`user/${mqttUser.id}/#`, (err, granted) => {
if (err) console.error(err)
else console.log(granted)
})
Currently discovered topics are:
user/${mqttUser.id}/notification
user/${mqttUser.id}/pre-notification
user/${mqttUser.id}/out/control/commands/status
For notification
and pre-notification
you can use Zod schemas:
Example:
import { DaichiMqttNotificationSchema } from 'daichi'
function onNotification(message: string) {
return DaichiMqttNotificationSchema.parse(JSON.parse(message))
}
For troubleshooting use env DEBUG=daichi
for verbose loggings.