This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
select.ino
68 lines (51 loc) · 1.63 KB
/
select.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <Ethernet.h>
#include <ArduinoHA.h>
#define BROKER_ADDR IPAddress(192,168,0,17)
byte mac[] = {0x00, 0x10, 0xFA, 0x6E, 0x38, 0x4A};
EthernetClient client;
HADevice device(mac, sizeof(mac));
HAMqtt mqtt(client, device);
HASelect select("mySelect");
void onSelectCommand(int8_t index, HASelect* sender)
{
switch (index) {
case 0:
// Option "Low" was selected
break;
case 1:
// Option "Medium" was selected
break;
case 2:
// Option "High" was selected
break;
default:
// unknown option
return;
}
sender->setState(index); // report the selected option back to the HA panel
}
void setup() {
// you don't need to verify return status
Ethernet.begin(mac);
// set device's details (optional)
device.setName("Arduino");
device.setSoftwareVersion("1.0.0");
// set available options
select.setOptions("Low;Medium;High"); // use semicolons as separator of options
select.onCommand(onSelectCommand);
select.setIcon("mdi:home"); // optional
select.setName("My dropdown"); // optional
// Optionally you can set retain flag for the HA commands
// select.setRetain(true);
// Optionally you can enable optimistic mode for the HASelect.
// In this mode you won't need to report state back to the HA when commands are executed.
// select.setOptimistic(true);
mqtt.begin(BROKER_ADDR);
}
void loop() {
Ethernet.maintain();
mqtt.loop();
// You can also report the state to the HA panel at runtime as shown below.
// The integer corresponds to the option's index.
// select.setState(1);
}