0

Set HVAC unit Mode as Permanent Hold

by
Published Nov 5, 2024

Tell an HVAC unit to enter a permanent hold. Only available if the target's `capabilities.setPermanentHold.isCapable` is set to `true`. We retry sending the command until the HVAC unit's `target` field transition to the expected value. Note that this request will complete before any commands are sent to the HVAC unit. You may react to transitions by listening for the `user:vendor-action:updated` webhook event or polling the HVAC action endpoint.

Script enode Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Enode = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Enode,
8
	hvacId: string,
9
	body:
10
		| { coolSetpoint: number; mode: 'COOL' }
11
		| { heatSetpoint: number; mode: 'HEAT' }
12
		| { coolSetpoint: number; heatSetpoint: number; mode: 'AUTO' }
13
		| { mode: 'OFF' }
14
) {
15
	const url = new URL(`https://enode-api.production.enode.io/hvacs/${hvacId}/permanent-hold`)
16

17
	const response = await fetch(url, {
18
		method: 'POST',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			Authorization: 'Bearer ' + auth.token
22
		},
23
		body: JSON.stringify(body)
24
	})
25

26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30

31
	return await response.json()
32
}
33