-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAmbientWeatherDevice.groovy
More file actions
119 lines (99 loc) · 4.57 KB
/
AmbientWeatherDevice.groovy
File metadata and controls
119 lines (99 loc) · 4.57 KB
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
metadata {
definition(name: "Ambient Weather Device", namespace: "CordMaster", author: "Alden Howard") {
capability "Temperature Measurement"
capability "Relative Humidity Measurement"
capability "Pressure Measurement"
capability "Illuminance Measurement"
capability "Refresh"
capability "Sensor"
capability "Actuator"
//Current Conditions
attribute "weather", "string"
attribute "weatherIcon", "string"
attribute "dewPoint", "number"
attribute "comfort", "number"
attribute "feelsLike", "number"
attribute "pressure", "string"
//Precipitation
attribute "precip_today", "number"
attribute "precip_1hr", "number"
//Wind
attribute "wind", "number"
attribute "wind_gust", "number"
attribute "wind_degree", "number"
attribute "wind_dir", "string"
attribute "wind_direction", "string"
//Light
attribute "solarradiation", "number"
attribute "uv", "number"
}
preferences {
section("Preferences") {
input "showLogs", "bool", required: false, title: "Show Debug Logs?", defaultValue: false
}
}
}
def refresh() {
parent.fetchNewWeather();
}
def setWeather(weather){
logger("debug", "Weather: "+weather);
//Set temperature
sendEvent(name: "temperature", value: weather.tempf, unit: '°F', isStateChange: true);
//Set Humidity
sendEvent(name: "humidity", value: weather.humidity, unit: '%', isStateChange: true);
//Set DewPoint
sendEvent(name: "dewPoint", value: weather.dewPoint, unit:'°F', isStateChange: true);
//Set Comfort Level
float temp = 0.0;
temp = (weather.dewPoint - 35);
if (temp <= 0) {
temp = 0.0;
} else if (temp >= 40.0) {
temp = 100.0;
} else {
temp = (temp/40.0)*100.0;
}
temp = temp.round(1);
sendEvent(name: "comfort", value: temp, isStateChange: true);
//Set Barometric Pressure
sendEvent(name: "pressure", value: weather.baromrelin, unit: 'in', isStateChange: true);
//Set Feels Like Temperature
sendEvent(name: "feelsLike", value: weather.feelsLike, unit: '°F', isStateChange: true);
//Rain
sendEvent(name: "precip_today", value: weather.dailyrainin, unit: 'in', isStateChange: true);
sendEvent(name: "precip_1hr", value: weather.hourlyrainin, unit: 'in', isStateChange: true);
//Wind
sendEvent(name: "wind", value: weather.windspeedmph, unit: 'mph', isStateChange: true);
sendEvent(name: "wind_gust", value: weather.windgustmph, unit: 'mph', isStateChange: true);
sendEvent(name: "wind_degree", value: weather.winddir, unit: '°', isStateChange: true);
temp = weather.winddir
if (temp < 22.5) { sendEvent(name: "wind_direction", value: "North", isStateChange: true);
sendEvent(name: "wind_dir", value: "N", isStateChange: true);
} else if (temp < 67.5) { sendEvent(name: "wind_direction", value: "Northeast", isStateChange: true);
sendEvent(name: "wind_dir", value: "NE", isStateChange: true);
} else if (temp < 112.5) { sendEvent(name: "wind_direction", value: "East", isStateChange: true);
sendEvent(name: "wind_dir", value: "E", isStateChange: true);
} else if (temp < 157.5) { sendEvent(name: "wind_direction", value: "Southeast", isStateChange: true);
sendEvent(name: "wind_dir", value: "SE", isStateChange: true);
} else if (temp < 202.5) { sendEvent(name: "wind_direction", value: "South", isStateChange: true);
sendEvent(name: "wind_dir", value: "S", isStateChange: true);
} else if (temp < 247.5) { sendEvent(name: "wind_direction", value: "Southwest", isStateChange: true);
sendEvent(name: "wind_dir", value: "SW", isStateChange: true);
} else if (temp < 292.5) { sendEvent(name: "wind_direction", value: "West", isStateChange: true);
sendEvent(name: "wind_dir", value: "W", isStateChange: true);
} else if (temp < 337.5) { sendEvent(name: "wind_direction", value: "Northwest", isStateChange: true);
sendEvent(name: "wind_dir", value: "NW", isStateChange: true);
} else { sendEvent(name: "wind_direction", value: "North", isStateChange: true);
sendEvent(name: "wind_dir", value: "N", isStateChange: true);
}
//UV and Light
sendEvent(name: "solarradiation", value: weather.solarradiation, isStateChange: true);
sendEvent(name: "illuminance", value: weather.solarradiation, isStateChange: true);
sendEvent(name: "uv", value: weather.uv, isStateChange: true);
}
private logger(type, msg){
if(type && msg && settings?.showLogs) {
log."${type}" "${msg}"
}
}