first commit

This commit is contained in:
Souti
2025-03-06 11:09:58 +01:00
commit 11f7d440ff
330 changed files with 38306 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
require "scripts/lua/functions"
-- URL du fichier JSON
local url = "http://api.openweathermap.org/data/2.5/weather?q=La%20gacilly,fr&APPID=feba3f4d926db3b358a25ec782bd1c8b&lang=FR&units=metric"
time=os.time()
seconds=tonumber(os.date('%S',time))
minutes=tonumber(os.date('%M',time))
heures=tonumber(os.date('%H',time))
jour=tonumber(os.date('%w',time))
mois=tonumber(os.date('%M',time))
function updateBarometerDevice(deviceId, temperature, humidity, pressure, cloud)
local svalue = string.format("%.1f;%d;%d;%d;%d;", temperature, humidity, humidity, pressure, cloud)
--local svalue = "TEMP;HUM;HUM_STAT;BAR;BAR_FOR"
url = domoticzURL..'/json.htm?type=command&param=udevice&idx='..deviceId..'&svalue='..svalue
print(url)
result = os.execute(curl..'"'..url..'" &')
print(result)
end
commandArray = {}
if minutes == 00 and heures == 08 then
if mois == 2 and jour == 01 then
commandArray['SendNotification']='Changement d\'anglet#Passer l\'angle des pannneaux à 60°!'
end
if mois == 3 and jour == 01 then
commandArray['SendNotification']='Changement d\'anglet#Passer l\'angle des pannneaux à 45!'
end
if mois == 4 and jour == 24 then
commandArray['SendNotification']='Changement d\'anglet#Passer l\'angle des pannneaux à 30°!'
end
if mois == 8 and jour == 19 then
commandArray['SendNotification']='Changement d\'anglet#Passer l\'angle des pannneaux à 45!'
end
if mois == 10 and jour == 13 then
commandArray['SendNotification']='Changement d\'anglet#Passer l\'angle des pannneaux à 60°!'
end
end
if minutes%15 == 0 then
local cmd = 'curl "'..url..'"'
local jsonContent = os.capture(cmd, true)
-- jsonContent = '{"coord":{"lon":-2.1322,"lat":47.7656},"weather":[{"id":803,"main":"Clouds","description":"nuageux","icon":"04d"}],"base":"stations","main":{"temp":22.33,"feels_like":22.21,"temp_min":21.14,"temp_max":23.77,"pressure":1012,"humidity":61,"sea_level":1012,"grnd_level":1010},"visibility":10000,"wind":{"speed":4.87,"deg":265,"gust":5.72},"clouds":{"all":58},"dt":1686396178,"sys":{"type":2,"id":2007485,"country":"FR","sunrise":1686370227,"sunset":1686427534},"timezone":7200,"id":3009239,"name":"La Gacilly","cod":200}'
print(cmd)
-- Appel de la fonction pour récupérer le contenu JSON de l'URL
-- local jsonContent = getJSON(url)
json = (loadfile "/opt/domoticz/scripts/lua/JSON.lua")()
local devices = json:decode(jsonContent)
printTableAsTree(devices)
-- local jsonTable = domoticz.utils.fromJSON(jsonContent)
-- Vérification si la récupération du JSON a réussi
if jsonContent then
print("Contenu JSON récupéré avec succès:")
--print(jsonContent)
else
print("Erreur lors de la récupération du JSON")
end
-- Conversion du contenu JSON en une table Lua
-- local devices = json.decode(jsonContent)
--local devices = domoticz.utils.fromJSON(jsonContent)
--for k, v in pairs(devices) do
--print(k .. ' '.. v)
--end
pluie_1h = 0
local main = searchKeyInTable("main", devices['weather'])
print('main='..main)
forecast = 0
if main == "Clouds" then
nuage = searchKeyInTable("all", devices)
if (tonumber(nuage) > 50) then
forecast = 3
else
forecast = 2
end
print("Nuage " .. nuage)
elseif main == "Rain" then
forecast = 4
pluie_1h = searchKeyInTable("1h", devices)
elseif main == "Clear" then
nuage = searchKeyInTable("all", devices)
forecast = 1
end
print("pluie " .. pluie_1h)
deviceId = 1159
-- /json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=RAINRATE;RAINCOUNTER
local svalue = string.format(";%d", pluie_1h)
url = domoticzURL..'/json.htm?type=command&param=udevice&idx='..deviceId..'&svalue='..svalue
print(url)
result = os.execute(curl..'"'..url..'" &')
print(result)
deviceId = 1160
-- /json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=RAINRATE;RAINCOUNTER
local svalue = string.format("%d", nuage)
url = domoticzURL..'/json.htm?type=command&param=udevice&idx='..deviceId..'&svalue='..svalue
print(url)
result = os.execute(curl..'"'..url..'" &')
print(result)
local temp_min = searchKeyInTable("temp", devices)
local humidity = searchKeyInTable("humidity", devices)
local grnd_level = searchKeyInTable("pressure", devices)
local cloud = searchKeyInTable("all", devices)
updateBarometerDevice(1157, temp_min, humidity, grnd_level, forecast)
local temp = searchKeyInTable("temp", devices)
local feels_like = searchKeyInTable("feels_like", devices)
local deg = searchKeyInTable("pressure", devices)
local speed = searchKeyInTable("speed", devices) * 10
local gust = searchKeyInTable("gust", devices) * 10
deviceId = 1158
local svalue = string.format("%d;;%.1f;%.1f;%.1f;%.1f", deg, speed, gust, temp, feels_like)
--local svalue = "TEMP;HUM;HUM_STAT;BAR;BAR_FOR"
url = domoticzURL..'/json.htm?type=command&param=udevice&idx='..deviceId..'&svalue='..svalue
print(url)
result = os.execute(curl..'"'..url..'" &')
print(result)
end
return commandArray