-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeather.lua
61 lines (50 loc) · 3.2 KB
/
Weather.lua
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
return {
on = {
timer = { 'every 2 minutes' },
httpResponses = { 'response' }
},
logging = {
level = domoticz.LOG_FORCE,
marker = "Weather"
},
execute = function(domoticz, item)
if (item.isTimer) then
local api_key = "API_KEY"
local coord = "LON,LAT"
domoticz.openURL({
url = 'https://api.darksky.net/forecast/'..api_key..'/'..coord..'?lang=en&units=si',
method = 'GET',
callback = 'response'
})
elseif (item.isHTTPResponse) then
if (item.ok) then
local jsonValeur = item.json
local val_app_temp = jsonValeur.currently.apparentTemperature
local val_Cloud= jsonValeur.currently.cloudCover*100
local val_PercipationChance = jsonValeur.currently.precipProbability*100
local val_CurrentWeatherHours = jsonValeur.hourly.data[1].summary.." - "..jsonValeur.hourly.data[2].summary.." - "..jsonValeur.hourly.data[3].summary
local val_CurrentWeather = jsonValeur.daily.data[1].summary
local summary = jsonValeur.daily.data[2].summary
local forecast = "<b>Now</b>: "..val_CurrentWeatherHours.."<br> <b>Today</b>: "..val_CurrentWeather
local time = os.date("*t")
local isTime = time.hour >= 9 and time.hour <= 20
if (isTime
and domoticz.devices('Last Forecast Send').lastUpdate.minutesAgo > tonumber(domoticz.devices('Last Forecast Send').text)
and string.match(val_CurrentWeatherHours, "Rain")) then
domoticz.devices('Last Forecast Send').update(0, 150)
local message = "Rain Forecast. 3h forecast: ".. val_CurrentWeatherHours
domoticz.helpers.pushB("Weather Forecast", val_CurrentWeatherHours)
domoticz.log(message, domoticz.LOG_DEBUG)
domoticz.log('Weather is sending '..val_CurrentWeatherHours, domoticz.LOG_DEBUG)
end
if domoticz.devices('Forecast').svalues ~= forecast then domoticz.devices('Forecast').update(0, forecast) end
if domoticz.devices('Clouds').svalues ~= val_Cloud then domoticz.devices('Clouds').update(0, val_Cloud) end
if domoticz.devices('Apparent Temperature').svalues ~= val_app_temp then domoticz.devices('Apparent Temperature').update(0, val_app_temp) end
if domoticz.devices('Percipation Chance').svalues ~= val_PercipationChance then domoticz.devices('Percipation Chance').update(0, val_PercipationChance) end
if domoticz.devices('Current Weather').svalues ~= val_CurrentWeather then domoticz.devices('Current Weather').update(0, val_CurrentWeather) end
if domoticz.devices('Current Weather Hours').svalues ~= val_CurrentWeatherHours then domoticz.devices('Current Weather Hours').update(0, val_CurrentWeatherHours) end
end
end
domoticz.log('Weather is working ' .. item.trigger, domoticz.LOG_DEBUG)
end
}