-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
175 lines (158 loc) · 5.52 KB
/
messages.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
const DeviceID = "rabbitf3"
type Discovery struct {
Home string `json:"~"`
Name string `json:"name,omitempty"`
UniqueID string `json:"unique_id,omitempty"`
ObjectID string `json:"object_id,omitempty"`
UnitOfMeasurement string `json:"unit_of_measurement,omitempty"`
ValueTemplate string `json:"value_template,omitempty"`
CommandTopic string `json:"cmd_t,omitempty"`
StatusTopic string `json:"stat_t,omitempty"`
Device Device `json:"device,omitempty"`
Icon string `json:"icon,omitempty"`
}
type Device struct {
Identifiers []string `json:"identifiers,omitempty"`
Name string `json:"name,omitempty"`
Model string `json:"model,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"`
}
type SensorState struct {
Temperature int32 `json:"temperature,omitempty"`
Humidity int32 `json:"humidity,omitempty"`
Pressure int32 `json:"pressure,omitempty"`
Distance uint16 `json:"distance,omitempty"`
EEPROM []byte `json:"eeprom,omitempty"`
Date string `json:"date,omitempty"`
}
type RelayState struct {
Relay1 string `json:"relay1,omitempty"`
Relay2 string `json:"relay2,omitempty"`
Relay3 string `json:"relay3,omitempty"`
Relay4 string `json:"relay4,omitempty"`
}
var device = Device{
Identifiers: []string{"rabbitf3"},
Name: "Rabbit Feeder Supreme",
Model: "Rabbit Feeder Supreme F3",
Manufacturer: "@conejo@social.tinygo.org",
}
var Relay1Discovery = Discovery{
Home: "homeassistant/switch/relay1",
Name: "Relay 1 (USB)",
UniqueID: DeviceID + "_relay1",
ObjectID: DeviceID + "_relay1",
ValueTemplate: "{{ value_json.relay1 }}",
CommandTopic: "~/set",
StatusTopic: "homeassistant/switch/relays/state",
Device: device,
Icon: "mdi:usb-port",
}
var Relay2Discovery = Discovery{
Home: "homeassistant/switch/relay2",
Name: "Relay 2 (USB)",
UniqueID: DeviceID + "_relay2",
ObjectID: DeviceID + "_relay2",
ValueTemplate: "{{ value_json.relay2 }}",
CommandTopic: "~/set",
StatusTopic: "homeassistant/switch/relays/state",
Device: device,
Icon: "mdi:usb-port",
}
var Relay3Discovery = Discovery{
Home: "homeassistant/switch/relay3",
Name: "Relay 3 (12V)",
UniqueID: DeviceID + "_relay3",
ObjectID: DeviceID + "_relay3",
ValueTemplate: "{{ value_json.relay3 }}",
CommandTopic: "~/set",
StatusTopic: "homeassistant/switch/relays/state",
Device: device,
Icon: "mdi:audio-input-stereo-minijack",
}
var Relay4Discovery = Discovery{
Home: "homeassistant/switch/relay4",
Name: "Relay 4 (12V)",
UniqueID: DeviceID + "_relay4",
ObjectID: DeviceID + "_relay4",
ValueTemplate: "{{ value_json.relay4 }}",
CommandTopic: "~/set",
StatusTopic: "homeassistant/switch/relays/state",
Device: device,
Icon: "mdi:audio-input-stereo-minijack",
}
var TemperatureDiscovery = Discovery{
Home: "homeassistant/sensor/temperature",
Name: "Temperature",
UniqueID: DeviceID + "_temp",
ObjectID: DeviceID + "_temp",
UnitOfMeasurement: "ºC",
ValueTemplate: "{{ value_json.temperature / 1000 }}",
StatusTopic: "homeassistant/switch/sensors/state",
Device: device,
Icon: "mdi:thermometer",
}
var HumidityDiscovery = Discovery{
Home: "homeassistant/sensor/humidity",
Name: "Humidity",
UniqueID: DeviceID + "_humidity",
ObjectID: DeviceID + "_humidity",
UnitOfMeasurement: "%",
ValueTemplate: "{{ value_json.humidity / 100 }}",
StatusTopic: "homeassistant/switch/sensors/state",
Device: device,
Icon: "mdi:water-percent",
}
var PressureDiscovery = Discovery{
Home: "homeassistant/sensor/pressure",
Name: "Pressure",
UniqueID: DeviceID + "_pressure",
ObjectID: DeviceID + "_pressure",
UnitOfMeasurement: "Pa",
ValueTemplate: "{{ value_json.pressure / 1000 }}",
StatusTopic: "homeassistant/switch/sensors/state",
Device: device,
Icon: "mdi:air-filter",
}
var DistanceDiscovery = Discovery{
Home: "homeassistant/sensor/distance",
Name: "Distance",
UniqueID: DeviceID + "_dist",
ObjectID: DeviceID + "_dist",
UnitOfMeasurement: "mm",
ValueTemplate: "{{ value_json.distance }}",
StatusTopic: "homeassistant/switch/sensors/state",
Device: device,
Icon: "mdi:gauge-full",
}
var RTCDiscovery = Discovery{
Home: "homeassistant/statestream/rtc",
Name: "RTC",
UniqueID: DeviceID + "_rtc",
ObjectID: DeviceID + "_rtc",
ValueTemplate: "{{ value_json.timestamp }}",
StatusTopic: "homeassistant/switch/sensors/state",
Device: device,
Icon: "mdi:clock-digital",
}
var EEPROMDiscovery = Discovery{
Home: "homeassistant/text/eeprom",
Name: "EEPROM",
UniqueID: DeviceID + "_eeprom",
ObjectID: DeviceID + "_eeprom",
ValueTemplate: "{{ value_json.eeprom }}",
StatusTopic: "homeassistant/switch/sensors/state",
Device: device,
Icon: "mdi:text-box",
}
var MotorDiscovery = Discovery{
Home: "homeassistant/binary_sensor/motor",
Name: "Motor",
UniqueID: DeviceID + "_motor",
ObjectID: DeviceID + "_motor",
CommandTopic: "~/set",
StatusTopic: "~/state",
Device: device,
Icon: "mdi:engine",
}