@@ -62,7 +62,200 @@ func GetTemplateForType(deviceType string) map[string]interface{} {
6262 },
6363 },
6464 }
65- // Add other templates here as needed
65+
66+ case "weather_station" :
67+ return map [string ]interface {}{
68+ "title" : "Weather Station" ,
69+ "properties" : map [string ]interface {}{
70+ "temp" : map [string ]interface {}{
71+ "title" : "Air Temperature" ,
72+ "type" : "number" ,
73+ "unit" : "°C" ,
74+ "ui:widget" : "timeseries" ,
75+ },
76+ "humidity" : map [string ]interface {}{
77+ "title" : "Relative Humidity" ,
78+ "type" : "number" ,
79+ "unit" : "%" ,
80+ "ui:widget" : "chart" ,
81+ },
82+ "pressure" : map [string ]interface {}{
83+ "title" : "Barometric Pressure" ,
84+ "type" : "number" ,
85+ "unit" : "hPa" ,
86+ "ui:widget" : "timeseries" ,
87+ },
88+ "wind_speed" : map [string ]interface {}{
89+ "title" : "Wind Speed" ,
90+ "type" : "number" ,
91+ "unit" : "km/h" ,
92+ "ui:widget" : "gauge" ,
93+ },
94+ "wind_dir" : map [string ]interface {}{
95+ "title" : "Wind Direction" ,
96+ "type" : "number" ,
97+ "unit" : "°" ,
98+ "minimum" : 0 ,
99+ "maximum" : 360 ,
100+ "ui:widget" : "compass" ,
101+ },
102+ "rain_mm" : map [string ]interface {}{
103+ "title" : "Rainfall" ,
104+ "type" : "number" ,
105+ "unit" : "mm" ,
106+ "ui:widget" : "timeseries" ,
107+ },
108+ "uv_index" : map [string ]interface {}{
109+ "title" : "UV Index" ,
110+ "type" : "number" ,
111+ "unit" : "" ,
112+ "minimum" : 0 ,
113+ "maximum" : 11 ,
114+ "ui:widget" : "gauge" ,
115+ },
116+ },
117+ }
118+
119+ case "soil_sensor" :
120+ return map [string ]interface {}{
121+ "title" : "Soil Sensor" ,
122+ "properties" : map [string ]interface {}{
123+ "soil_moisture" : map [string ]interface {}{
124+ "title" : "Soil Moisture" ,
125+ "type" : "number" ,
126+ "unit" : "%" ,
127+ "minimum" : 0 ,
128+ "maximum" : 100 ,
129+ "ui:widget" : "gauge" ,
130+ },
131+ "soil_temp" : map [string ]interface {}{
132+ "title" : "Soil Temperature" ,
133+ "type" : "number" ,
134+ "unit" : "°C" ,
135+ "ui:widget" : "timeseries" ,
136+ },
137+ "soil_ph" : map [string ]interface {}{
138+ "title" : "Soil pH" ,
139+ "type" : "number" ,
140+ "unit" : "" ,
141+ "minimum" : 0 ,
142+ "maximum" : 14 ,
143+ "ui:widget" : "gauge" ,
144+ },
145+ "soil_ec" : map [string ]interface {}{
146+ "title" : "Electrical Conductivity" ,
147+ "type" : "number" ,
148+ "unit" : "µS/cm" ,
149+ "ui:widget" : "timeseries" ,
150+ },
151+ "nitrogen" : map [string ]interface {}{
152+ "title" : "Nitrogen (N)" ,
153+ "type" : "number" ,
154+ "unit" : "mg/kg" ,
155+ "ui:widget" : "chart" ,
156+ },
157+ "phosphorus" : map [string ]interface {}{
158+ "title" : "Phosphorus (P)" ,
159+ "type" : "number" ,
160+ "unit" : "mg/kg" ,
161+ "ui:widget" : "chart" ,
162+ },
163+ "potassium" : map [string ]interface {}{
164+ "title" : "Potassium (K)" ,
165+ "type" : "number" ,
166+ "unit" : "mg/kg" ,
167+ "ui:widget" : "chart" ,
168+ },
169+ },
170+ }
171+
172+ case "irrigation_controller" , "irrigation" :
173+ return map [string ]interface {}{
174+ "title" : "Irrigation Controller" ,
175+ "properties" : map [string ]interface {}{
176+ "zone1_active" : map [string ]interface {}{
177+ "title" : "Zone 1 Valve" ,
178+ "type" : "boolean" ,
179+ "readOnly" : false ,
180+ },
181+ "zone2_active" : map [string ]interface {}{
182+ "title" : "Zone 2 Valve" ,
183+ "type" : "boolean" ,
184+ "readOnly" : false ,
185+ },
186+ "zone3_active" : map [string ]interface {}{
187+ "title" : "Zone 3 Valve" ,
188+ "type" : "boolean" ,
189+ "readOnly" : false ,
190+ },
191+ "zone4_active" : map [string ]interface {}{
192+ "title" : "Zone 4 Valve" ,
193+ "type" : "boolean" ,
194+ "readOnly" : false ,
195+ },
196+ "flow_rate" : map [string ]interface {}{
197+ "title" : "Flow Rate" ,
198+ "type" : "number" ,
199+ "unit" : "L/min" ,
200+ "ui:widget" : "timeseries" ,
201+ },
202+ "total_volume" : map [string ]interface {}{
203+ "title" : "Total Volume Today" ,
204+ "type" : "number" ,
205+ "unit" : "L" ,
206+ "ui:widget" : "chart" ,
207+ },
208+ "pressure" : map [string ]interface {}{
209+ "title" : "Line Pressure" ,
210+ "type" : "number" ,
211+ "unit" : "bar" ,
212+ "ui:widget" : "gauge" ,
213+ },
214+ "schedule_enabled" : map [string ]interface {}{
215+ "title" : "Auto Schedule" ,
216+ "type" : "boolean" ,
217+ "readOnly" : false ,
218+ },
219+ },
220+ }
221+
222+ case "sensor" :
223+ return map [string ]interface {}{
224+ "title" : "Generic Sensor" ,
225+ "properties" : map [string ]interface {}{
226+ "value" : map [string ]interface {}{
227+ "title" : "Sensor Value" ,
228+ "type" : "number" ,
229+ "ui:widget" : "timeseries" ,
230+ },
231+ "battery" : map [string ]interface {}{
232+ "title" : "Battery Level" ,
233+ "type" : "number" ,
234+ "unit" : "%" ,
235+ "minimum" : 0 ,
236+ "maximum" : 100 ,
237+ "ui:widget" : "gauge" ,
238+ },
239+ },
240+ }
241+
242+ case "actuator" , "relay" :
243+ return map [string ]interface {}{
244+ "title" : "Actuator / Relay" ,
245+ "properties" : map [string ]interface {}{
246+ "state" : map [string ]interface {}{
247+ "title" : "Output State" ,
248+ "type" : "boolean" ,
249+ "readOnly" : false ,
250+ },
251+ "auto_mode" : map [string ]interface {}{
252+ "title" : "Automatic Mode" ,
253+ "type" : "boolean" ,
254+ "readOnly" : false ,
255+ },
256+ },
257+ }
258+
66259 default :
67260 return nil
68261 }
@@ -121,6 +314,133 @@ func GetDefaultRulesForType(deviceType string, deviceID string) []*rules.Rule {
121314 },
122315 },
123316 }
317+
318+ case "weather_station" :
319+ return []* rules.Rule {
320+ {
321+ Name : "Frost Warning" ,
322+ Description : "Alert when air temperature drops below 2°C (frost risk)" ,
323+ DeviceID : deviceID ,
324+ Conditions : []rules.Condition {
325+ {
326+ Field : "temp" ,
327+ Operator : rules .OpLT ,
328+ Value : 2.0 ,
329+ },
330+ },
331+ Actions : []rules.RuleAction {
332+ {Type : rules .ActionLog },
333+ {Type : rules .ActionWebhook },
334+ {
335+ Type : rules .ActionMQTT ,
336+ Config : map [string ]interface {}{
337+ "topic" : fmt .Sprintf ("dev/%s/alert/frost" , deviceID ),
338+ },
339+ },
340+ },
341+ },
342+ {
343+ Name : "High Wind Alert" ,
344+ Description : "Alert when wind speed exceeds 50 km/h" ,
345+ DeviceID : deviceID ,
346+ Conditions : []rules.Condition {
347+ {
348+ Field : "wind_speed" ,
349+ Operator : rules .OpGT ,
350+ Value : 50.0 ,
351+ },
352+ },
353+ Actions : []rules.RuleAction {
354+ {Type : rules .ActionLog },
355+ {Type : rules .ActionWebhook },
356+ },
357+ },
358+ }
359+
360+ case "soil_sensor" :
361+ return []* rules.Rule {
362+ {
363+ Name : "Low Soil Moisture Alert" ,
364+ Description : "Alert when soil moisture drops below 25%" ,
365+ DeviceID : deviceID ,
366+ Conditions : []rules.Condition {
367+ {
368+ Field : "soil_moisture" ,
369+ Operator : rules .OpLT ,
370+ Value : 25.0 ,
371+ },
372+ },
373+ Actions : []rules.RuleAction {
374+ {Type : rules .ActionLog },
375+ {Type : rules .ActionWebhook },
376+ {
377+ Type : rules .ActionMQTT ,
378+ Config : map [string ]interface {}{
379+ "topic" : fmt .Sprintf ("dev/%s/alert/dry_soil" , deviceID ),
380+ },
381+ },
382+ },
383+ },
384+ {
385+ Name : "Soil pH Out of Range" ,
386+ Description : "Alert when soil pH is outside the 5.5-7.5 optimal range" ,
387+ DeviceID : deviceID ,
388+ Conditions : []rules.Condition {
389+ {
390+ Field : "soil_ph" ,
391+ Operator : rules .OpGT ,
392+ Value : 7.5 ,
393+ },
394+ },
395+ Actions : []rules.RuleAction {
396+ {Type : rules .ActionLog },
397+ {Type : rules .ActionWebhook },
398+ },
399+ },
400+ }
401+
402+ case "irrigation_controller" , "irrigation" :
403+ return []* rules.Rule {
404+ {
405+ Name : "Low Pressure Alert" ,
406+ Description : "Alert when line pressure drops below 0.5 bar (possible leak)" ,
407+ DeviceID : deviceID ,
408+ Conditions : []rules.Condition {
409+ {
410+ Field : "pressure" ,
411+ Operator : rules .OpLT ,
412+ Value : 0.5 ,
413+ },
414+ },
415+ Actions : []rules.RuleAction {
416+ {Type : rules .ActionLog },
417+ {Type : rules .ActionWebhook },
418+ {
419+ Type : rules .ActionMQTT ,
420+ Config : map [string ]interface {}{
421+ "topic" : fmt .Sprintf ("dev/%s/alert/low_pressure" , deviceID ),
422+ },
423+ },
424+ },
425+ },
426+ {
427+ Name : "High Flow Rate Alert" ,
428+ Description : "Alert when flow rate exceeds 100 L/min (possible pipe burst)" ,
429+ DeviceID : deviceID ,
430+ Conditions : []rules.Condition {
431+ {
432+ Field : "flow_rate" ,
433+ Operator : rules .OpGT ,
434+ Value : 100.0 ,
435+ },
436+ },
437+ Actions : []rules.RuleAction {
438+ {Type : rules .ActionLog },
439+ {Type : rules .ActionWebhook },
440+ },
441+ },
442+ }
443+
124444 default :
125445 return nil
126446 }
0 commit comments