flacon030 Posté(e) mercredi à 05:57 Signaler Posté(e) mercredi à 05:57 (modifié) Bonjour a tous Je voudrais envoyer tous les nuit vers 4h du matin l'index de production de mes panneaux vers le site dbpv La requête est la suivante https://www.bdpv.fr/webservice/majProd/expeditionProd_v3.php?util=xxxx-jc&apiKey=xxxx&source=homeassistant&typeReleve=onduleur&index=7 562738 ?util (nom d'utilisateur sur le site) apikey (apikey pour mise a jour de la production) index de production (7562738) comment le faire selon vous ? L'id de mon compteur est le 600 sachant que la valeur qu'attend dbpv doit être en Wh sans virgule Modifié jeudi à 16:22 par flacon030
jojo Posté(e) mercredi à 11:24 Signaler Posté(e) mercredi à 11:24 via un QA classique qui compose ton url comme tu veux. Ensuite, tu utilises GEA comme trigger tous les jours à 4h00
flacon030 Posté(e) mercredi à 14:55 Auteur Signaler Posté(e) mercredi à 14:55 il serait possible d'avoir un exemple Merci
Lazer Posté(e) mercredi à 16:00 Signaler Posté(e) mercredi à 16:00 Le QA sera à écrire entièrement, mais tu peux t'inspirer de la documentation Fibaro officielle des nombreux exemples du forum. Pour la requête HTTP, voir :
flacon030 Posté(e) mercredi à 18:45 Auteur Signaler Posté(e) mercredi à 18:45 (modifié) Bon une fois de plus merci chatgpt pour son aide Je viens de faire un QA qui envoie mes données a 4:00 les index de production de mon installation -- QuickApp : BDPV Updater HC3 -- Version : 1.3 avec compte a rebourg dynamique et ajout des variables -- ================================ -- INITIALISATION -- ================================ function QuickApp:onInit() self:debug("QuickApp BDPV initialisé") -- Lecture des variables éditables self.DEVICE_ID = tonumber(self:getVariable("DEVICE_ID")) self.BDPV_USER = self:getVariable("BDPV_USER") self.BDPV_API_KEY = self:getVariable("BDPV_API_KEY") self.BDPV_SOURCE = self:getVariable("BDPV_SOURCE") or "homeassistant" self.BDPV_TYPE = self:getVariable("BDPV_TYPE") or "onduleur" if not self.DEVICE_ID then self:error("ERREUR : DEVICE_ID invalide dans les variables !") end -- Bouton "Envoyer maintenant" self:updateView("sendButton", "text", "Envoyer maintenant") -- Planification automatique à 4h00 self:scheduleDailySend(4, 0) end -- ================================ -- BOUTON MANUEL -- ================================ function QuickApp:sendNow() self:sendBDPV() end -- ================================ -- RAFRAICHISSEMENT COMPTE À REBOURS -- ================================ function QuickApp:startCountdownUpdater(nextRun) -- Stoppe l'ancien timer si présent if self.countdownTimer then clearInterval(self.countdownTimer) end -- Mise à jour chaque minute self.countdownTimer = setInterval(function() local now = os.time() local remaining = nextRun - now if remaining < 0 then remaining = 0 end local minutesTotal = math.floor(remaining / 60) local hours = math.floor(minutesTotal / 60) local minutes = minutesTotal % 60 local text = string.format("Envoi index dans %02dh %02dmin", hours, minutes) -- Mise à jour dans l’UI self:updateView("nextSendLabel", "text", text) -- Mise à jour dans une variable self:setVariable("NEXT_SEND", text) -- >>> NOUVEAU : DEBUG DU COMPTE À REBOURDS <<< self:debug(text) end, 60 * 1000) -- Forcer une première mise à jour immédiate (pour éviter d’attendre 1 min) local minutesTotal = math.floor((nextRun - os.time()) / 60) local hours = math.floor(minutesTotal / 60) local minutes = minutesTotal % 60 local text = string.format("Envoi index dans %02dh %02dmin", hours, minutes) self:updateView("nextSendLabel", "text", text) self:setVariable("NEXT_SEND", text) -- DEBUG immédiat self:debug(text) end -- ================================ -- PLANIFICATION QUOTIDIENNE -- ================================ function QuickApp:scheduleDailySend(h, m) local now = os.time() local t = os.date("*t") local nextRun = os.time({ year = t.year, month = t.month, day = t.day, hour = h, min = m, sec = 0 }) -- Si l'heure est déjà passée → lendemain if nextRun <= now then nextRun = nextRun + 24 * 60 * 60 end local delaySeconds = nextRun - now -- Démarre la mise à jour dynamique du compte à rebours self:startCountdownUpdater(nextRun) -- (Première mise à jour immédiate) self:updateView("nextSendLabel", "text", string.format("Envoi index dans %02dh %02dmin", math.floor(delaySeconds / 3600), math.floor((delaySeconds % 3600) / 60) ) ) -- Planification de l'envoi réel setTimeout(function() self:sendBDPV() self:scheduleDailySend(h, m) end, delaySeconds * 1000) end -- ================================ -- ENVOI VERS BDPV -- ================================ function QuickApp:sendBDPV() -- Lecture compteur HC3 (kWh) local raw = fibaro.getValue(self.DEVICE_ID, "value") raw = tostring(raw):gsub(",", ".") local index_kwh = tonumber(raw) if not index_kwh then local msg = "Valeur compteur invalide" self:error(msg) self:updateView("statusLabel", "text", msg) self:setVariable("STATUS_BDPV", msg) return end -- Conversion en Wh local index_wh = math.floor(index_kwh * 1000 + 0.5) self:debug("Index compteur (kWh) : " .. index_kwh) self:debug("Index converti (Wh) : " .. index_wh) -- Construction URL local url = "https://www.bdpv.fr/webservice/majProd/expeditionProd_v3.php" .. "?util=" .. tostring(self.BDPV_USER) .. "&apiKey=" .. tostring(self.BDPV_API_KEY) .. "&source=" .. tostring(self.BDPV_SOURCE) .. "&typeReleve=" .. tostring(self.BDPV_TYPE) .. "&index=" .. tostring(index_wh) self:debug("URL envoyée à BDPV : " .. url) -- Envoi HTTP GET local http = net.HTTPClient() http:request(url, { options = { method = "GET", timeout = 8000 }, success = function(response) local cleaned = response.data:gsub('{"codeRetour" ?: ?"[^"]*",?"texteRetour" ?:?"?', "") cleaned = cleaned:gsub('"}$', "") local msg = "BDPV : " .. cleaned self:debug(msg) self:updateView("statusLabel", "text", msg) self:setVariable("STATUS_BDPV", msg) end, error = function(err) local msg = "Erreur : " .. tostring(err) self:error(msg) self:updateView("statusLabel", "text", msg) self:setVariable("STATUS_BDPV", msg) end }) end Modifié vendredi à 17:45 par flacon030 2
Messages recommandés