Bonjour
J’ai essayé d’adapter le code de Guy aux tarifs HP HC de mon abonnement. Malheureusement, ne s’affiche que les tarifs du kwh ainsi que les index des anciennes factures.
Voici le code modifié. Aucune valeur de l’eco device ne remonte. Y a t-il une application spécifique pour avoir les différentes fonction Set_Container,Get switch, Extract2 xml ?
Si quelqu’un à une solution. Merci.
Partie dans Edit Startup Lua (Lua)
– Startup LUA -
function my_unescape (l_string)
l_string = string.gsub(l_string, " ", « + »)
– l_string = string.gsub(l_string, « %%(%x%x) », function (h)return string.char(tonumber(h, 16)) end)
return l_string
end
– Fonction My Notification vers Notify My Android
– 4 paramètres : destinataire, nom de l’événement
– description du message, priorité du message
function my_notification (l_who, l_event, l_description, l_priority)
local l_url = « https://www.notifymyandroid.com/publicapi/notify?apikey= »
local l_apikey = « xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx »
local l_application = my_unescape(« Maison - Domotique »)
l_event = my_unescape(l_event)
l_description = my_unescape(os.date(‹ %H:%M:%S ›) …" " …l_description)
luup.inet.wget(l_url …l_apikey …« &application= » …l_application …« &event= » …l_event …« &description= » …l_description …« &priority= » …l_priority)
return true
end
– Fonction d’extration de la valeur d’une variable
function Extract2_XML(l_XML, l_tag, l_default)
local l_pattern = « (.-) »
local l_result = {}
for var in l_XML:gmatch(l_pattern) do
table.insert(l_result, var)
end
return l_result[1] or l_default
end
– Fonction Get_Container (valeur d’une variable)
function Get_Container (l_device, l_variable, l_Expected_Type)
local l_value = « »
local l_value_Type = « »
l_value = luup.variable_get(« urn:upnp-org:serviceId:VContainer1 »,« Variable »…l_variable, l_device)
if (l_value == nil) then
my_notification (« Seb », « * Get_Container = " …l_device … » Variable = " …l_variable …" ***" , « Value = nil »,« 2 »)
l_value = « »
end
if (l_Expected_Type == « number ») then
l_value = tonumber(l_value)
l_value_Type = type(l_value)
if (l_Expected_Type ~= l_value_Type) then
my_notification (« Seb », « * Get_Container = " …l_device … » Variable = " …l_variable …" ***" , « Value Type = " …l_value_Type … », Expected_Type = " …l_Expected_Type,« 2 »)
l_value = 0
end
end
return l_value
end
– Fonction Set_Container (container, variable, valeur d’une variable)
function Set_Container(l_device, l_variable, l_value)
if (l_value == nil) then
my_notification (« Seb », « * Set_Container = " …l_device … » Variable = " …l_variable …" ***" , « Value = nil »,« 2 »)
end
l_value = string.format(l_value)
luup.variable_set(« urn:upnp-org:serviceId:VContainer1 »,« Variable »…l_variable, l_value, l_device)
return true
end
– Fonction Get_Switch (device, valeur par défaut en cas d’erreur)
function Get_Switch (l_device, l_default)
local l_value = « »
local l_device_category = luup.devices[l_device].category_num
–my_notification (« Seb », "* Get_Switch = " …l_device, "Type of switch= " …l_device_category,« 2 »)
if l_device_category == 0 then
l_value = luup.variable_get(« urn:upnp-org:serviceId:VSwitch1 », « Status », l_device)
if (l_value == nil) then
my_notification (« Seb », « * Get_Switch (Status) = " …l_device … » *" , « Value = nil »,« 2 »)
l_value = l_default
end
elseif l_device_category == 3 or l_device_category == 8 then
l_value = luup.variable_get(« urn:upnp-org:serviceId:SwitchPower1 »,« Status », l_device)
if (l_value == nil) then
my_notification (« Seb », « * Get_Sensor = " …l_device … » *" , « Value = nil »,« 2 »)
l_value = l_default
end
else
my_notification (« Seb », "* Get_Switch = " …l_device, "Type of switch not handled = "…l_device_category,« 2 »)
end
return l_value
end
– Fonction Set_Container (container, variable, valeur d’une variable)
function Set_Container(l_device, l_variable, l_value)
if (l_value == nil) then
my_notification (« Seb », « * Set_Container = " …l_device … » Variable = " …l_variable …" ***" , « Value = nil »,« 2 »)
end
l_value = string.format(l_value)
luup.variable_set(« urn:upnp-org:serviceId:VContainer1 »,« Variable »…l_variable, l_value, l_device)
return true
end
Scène « EDF Mesures » avec un schedule toutes les 5 minutes.
– EDF Mesures - Begining of scene - List of devices (modules)
local EDF_Global_CV = 11 – Variable Container
local EDF_HC_CV = 12 – Variable Container
local EDF_HP_CV = 13 – Variable Container
local T1_OPTARIF, T1_ISOUSC, T1_HCHC, T1_HCHP = « »
local T1_PTEC, T1_IINST, T1_ADPS, T1_IMAX = « »
local T1_PPAP, T1_HHPHC, T1_MOTDETAT, T1_PPOT = « »
– coût
local C1_Global, C1_HCHC, C1_HCHP = 0.0
local CD_Global, CD_HCHC, CD_HCHP = « »
– facture
local F1_HCHC, F1_HCHP = 0.0
local FD_HCHC, FD_HCHP = « »
– prix unitaire
local P1_Global, P1_HCHC, P1_HCHP = 0.0
local PD_Global, PD_HCHC, PD_HCHP = « »
– quantité consommée
local Q1_Global, Q1_HCHC, Q1_HCHP = 0.0
local QD_Global, QD_HCHC, QD_HCHP = « »
local WC_CEJ, WC_CEN = 0.0 – Compteur Electrique Jour, Compteur Electrique Nuit
local WD_CEJ, WD_CEN = « » – Compteur Electrique Jour, Compteur Electrique Nuit
local l_Time = os.date(‹ *t ›)
– CONSO EDF - lecture des valeurs de la carte ECO-DEVICES de GCE
local http = require(« socket.http »)
http.TIMEOUT = 4
local l_result, l_status = http.request(« http://‹ bip ›.‹ bip ›.‹ bip ›.‹ bip ›/protect/settings/teleinfo1.xml? »)
–my_log(« Tests_EDF_Teleinfo1 », " *** Status = " …l_status …" *** Result = " …l_result …" ***")
if l_status == 200 then
T1_OPTARIF = Extract2_XML(l_result, « T1_OPTARIF », « »)
T1_ISOUSC = Extract2_XML(l_result, « T1_ISOUSC », « »)
T1_BASE = Extract2_XML(l_result, « T1_BASE », « »)
T1_HCHC = Extract2_XML(l_result, « T1_HCHC », « »)
T1_HCHP = Extract2_XML(l_result, « T1_HCHP », « »)
T1_PTEC = Extract2_XML(l_result, « T1_PTEC », « »)
T1_IINST = Extract2_XML(l_result, « T1_IINST », « »)
T1_ADPS = Extract2_XML(l_result, « T1_ADPS », « »)
T1_IMAX = Extract2_XML(l_result, « T1_IMAX », « »)
T1_PPAP = Extract2_XML(l_result, « T1_PPAP », « »)
else
my_notification (« Seb », « * EDF_Teleinfo1 * » , "Code erreur = " …l_status,« 2 »)
end
– CONSO EDF - Début des calculs
T1_HCHC = tonumber(T1_HCHC) / 1000
T1_HCHP = tonumber(T1_HCHP) / 1000
– Recuperation des compteurs de la derniere facture
F1_HCHC = Get_Container(EDF_HC_CV ,2, « number »)
F1_HCHP = Get_Container(EDF_HP_CV ,2, « number »)
– Calcul du consomme
Q1_HCHC = T1_HCHC - F1_HCHC
Q1_HCHP = T1_HCHP - F1_HCHP
QD_HCHC = string.format(« %.3f », Q1_HCHC)
QD_HCHP = string.format(« %.3f », Q1_HCHP)
– Recuperation du prix au KWh
P1_HCHC = Get_Container(EDF_HC_CV ,4, « number »)
P1_HCHP = Get_Container(EDF_HP_CV ,4, « number »)
– Calcul du cout
C1_HCHC = Q1_HCHC * P1_HCHC
C1_HCHP = Q1_HCHP * P1_HCHP
CD_HCHC = string.format(« %.2f », C1_HCHC)
CD_HCHP = string.format(« %.2f », C1_HCHP)
– cumuls generaux
Q1_Global = Q1_HCHC + Q1_HCHP
C1_Global = C1_HCHC + C1_HCHP
P1_Global = C1_Global / Q1_Global
QD_Global = string.format(Q1_Global)
PD_Global = string.format(« %.4f », P1_Global)
CD_Global = string.format(« %.2f », C1_Global)
– cummul par jour & nuit
WC_CEJ = T1_HCHP
WC_CEN = T1_HCHC
WD_CEJ = string.format(WC_CEJ)
WD_CEN = string.format(WC_CEN)
– CONSO EDF - Mise à jour des containers de variables
Set_Container(EDF_HC_CV ,1, T1_HCHC)
Set_Container(EDF_HP_CV ,1, T1_HCHP)
Set_Container(EDF_HC_CV ,3, QD_HCHC)
Set_Container(EDF_HP_CV ,3, QD_HCHP)
Set_Container(EDF_HC_CV ,5, CD_HCHC)
Set_Container(EDF_HP_CV ,5, CD_HCHP)
Set_Container(EDF_Global_CV,1, T1_IMAX … " / " …T1_ISOUSC)
Set_Container(EDF_Global_CV,2, T1_PPAP )
Set_Container(EDF_Global_CV,3, QD_Global)
Set_Container(EDF_Global_CV,4, PD_Global)
Set_Container(EDF_Global_CV,5, CD_Global)
– CONSO EDF - Fin de la scene
return true