Page 1 sur 2
[LUA] Récupérer sa conso linky avec ecocompteur legrand
Publié : 01 janv. 2019, 14:50
par jcligny
Bonjour.
Je vous partage un petit script LUA qui permet de récupérer la consommation de votre linky en téléinfo si vous êtes déjà équipés d'un écocompteur legrand :
Il vous faut un capteur virtuel nommé Linky de type RFXMeter
L'url locale de votre ecocompteur legrand que je vous conseille de rendre statique via DHCP
Je me suis basé que un script existant mais je ne sais plus de qui donc désolé de ne pas donner de source
Code : Tout sélectionner
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------
------ Configuration ------
----------------------------------------------
-- domoticz
local url = 'http://192.168.0.25/data.json' -- url locale de votre écocompteur legrand
linkyidx = otherdevices_idx['Linky']
local function removeZeros(Id)
while true do
if Id:sub(1,1) == '0' then
Id = Id:sub(2)
else
break
end
end
return Id
end
----------------------------------------------
-- Fin de la partie configuration --
----------------------------------------------
commandArray={}
--import des fontions pour lire le JSON
json = (loadfile "/home/odroid/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen("curl '"..url.."'"))
local location = removeZeros(config:read('*all'))
local trouve = string.find(location,'"conso_base" : ')
local consobase = removeZeros(string.sub(location,trouve+15,trouve +23))
config:close()
if Debug == "YES" then
print(trouve)
print(location)
print(consobase)
end
commandArray['UpdateDevice'] = linkyidx ..'|0|'.. consobase
return commandArray
voici le résultat :

Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 02 nov. 2019, 17:33
par aeronne
Bonjour,
Merci pour ce tuto.
J'ai suivi toute les informations à la lettre et j'ai modifié le script lua pour qu'il corresponde à ma configuration:
Code : Tout sélectionner
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------
------ Configuration ------
----------------------------------------------
-- domoticz
local url = 'http://192.168.xxx.xxx/data.json' -- url locale de votre écocompteur legrand
linkyidx = otherdevices_idx['Linky']
local function removeZeros(Id)
while true do
if Id:sub(1,1) == '0' then
Id = Id:sub(2)
else
break
end
end
return Id
end
----------------------------------------------
-- Fin de la partie configuration --
----------------------------------------------
commandArray={}
--import des fontions pour lire le JSON
json = (loadfile "/home/$user/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen("curl '"..url.."'"))
local location = removeZeros(config:read('*all'))
local trouve = string.find(location,'"conso_base" : ')
local consobase = removeZeros(string.sub(location,trouve+15,trouve +23))
config:close()
if Debug == "YES" then
print(trouve)
print(location)
print(consobase)
end
commandArray['UpdateDevice'] = linkyidx ..'|0|'.. consobase
return commandArray
Que j'ai appelé script_time_ecoCompteur.lua et mis dans: /home/$user/domoticz/scripts/lua/
Puis j'ai créé un nouveau matériel: Dummy (Does nothing, use for virtual switches only).
J'ai ensuite créer un capteur virtuel nommé "Linky" mais je coince bêtement sur le type rfxmeter. Il n'existe pas dans le menu déroulant des types proposé et j'ai bien un rfxcom mais je ne pense pas que ce soit nécessaire.
En bref, je suis perdu sur le type à ajouter
Si quelqu'un à une idée, je suis preneur

Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 03 nov. 2019, 14:48
par damolc
Bonjour moi j ai pris " electrique instantané et compteur"
Mais ce qui serait intéressant dans ce script c est d ajouter "conso_hc" et "conso_hp"
j ai tenté de changer "conso_basal" par l un des deux mais ça ne fonctionne pas
auriez vous une idée?
je ne sais absolument pas programmer
Merci
Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 07 nov. 2019, 19:32
par damolc
bonjour
quand j interroge Eco compteur legrand avec :
http://192.168.1.46/data.json
j ai :
"option_tarifaire" : 1,
"tarif_courant" : 2,
"isousc" : 30,
"conso_base" : 0,
"conso_hc" : 001143021,
"conso_hp" : 003609170,
je cherche a modifier ce script pour récupérer "conso_hc" et "conso_hp"
Pouvez vous m aider dans les modifications ne sachant par programmer?
Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 09 nov. 2019, 13:19
par damolc
Bonjour
j ai avancé dans le script pour reccuperer HP et HC :
Code : Tout sélectionner
Debug = "YES" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------
------ Configuration ------
----------------------------------------------
-- domoticz
local url = 'http://192.168.1.xx/data.json' -- url locale de votre écocompteur legrand
hcidx = otherdevices_idx['HeureCreuse']
hpidx = otherdevices_idx['HeurePleine']
local function removeZeros(Id)
while true do
if Id:sub(1,1) == '0' then
Id = Id:sub(2)
else
break
end
end
return Id
end
----------------------------------------------
-- Fin de la partie configuration --
----------------------------------------------
commandArray={}
--import des fontions pour lire le JSON
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen("curl '"..url.."'"))
local location = removeZeros(config:read('*all'))
local trouve = string.find(location,'"conso_hc"')
local trouve = string.find(location,'"conso_hp"')
local consoHC = removeZeros(string.sub(location,trouve+15,trouve+23))
local consoHP = removeZeros(string.sub(location,trouve+15,trouve+23))
config:close()
if Debug == "YES" then
print(trouve)
print(location)
print(consoHC)
print(consoHP)
end
commandArray['UpdateDevice'] = hcidx ..'|0|'.. consoHC
commandArray['UpdateDevice'] = hpidx ..'|0|'.. consoHP
return commandArray
mais la valeur de HP n est pas reccuperée?
j ai choisi comme Idx : Compteur
pourriez vous m indiquer ou il y a une erreur dans le script?
Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 09 nov. 2019, 20:44
par denis_brasseur
Et que donne ceci :
Code : Tout sélectionner
local trouve = string.find(location,'"conso_hc"')
local consoHC = removeZeros(string.sub(location,trouve+15,trouve+23))
local trouve = string.find(location,'"conso_hp"')
local consoHP = removeZeros(string.sub(location,trouve+15,trouve+23))
Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 09 nov. 2019, 21:04
par damolc
non ça ne fonction pas plus
j ai la solution mais elle n est par parfaite : deux scripts lua distincts
j en met un et il faut adapter l autre :
Code : Tout sélectionner
[*]
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------
------ Configuration ------
----------------------------------------------
-- domoticz
local url = 'http://XXX.XXX.X.XX/data.json' -- url locale de votre écocompteur legrand
hcidx = otherdevices_idx['HeureCreuse']
local function removeZeros(Id)
while true do
if Id:sub(1,1) == '0' then
Id = Id:sub(2)
else
break
end
end
return Id
end
----------------------------------------------
-- Fin de la partie configuration --
----------------------------------------------
commandArray={}
--import des fontions pour lire le JSON
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen("curl '"..url.."'"))
local location = removeZeros(config:read('*all'))
local trouve = string.find(location,'"conso_hc"')
local consoHC = removeZeros(string.sub(location,trouve+15,trouve +23))
config:close()
if Debug == "YES" then
print(trouve)
print(location)
print(consoHC)
end
commandArray['UpdateDevice'] = hcidx ..'|0|'.. consoHC
return commandArray
Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 11 nov. 2019, 19:56
par damolc
j ai finalisé le script lua avec 3 devices ( Linky pour le total du courant electrique avec un Idx double valeur : P1 compteur intelligent, et deux Idx compteurs pour HP et HC
tout a l air de bien fonctionner :
Code : Tout sélectionner
Debug = "NO" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------
------ Configuration ------
----------------------------------------------
-- domoticz
local url = 'http://192.168.1.46/data.json' -- url locale de votre écocompteur legrand
htidx = otherdevices_idx['Linky'] -- Idx P1 Compteur intelligent (électrique)
hcidx = otherdevices_idx['HC'] -- Idx Compteur
hpidx = otherdevices_idx['HP'] -- Idx Compteur
local function removeZeros(Id)
while true do
if Id:sub(1,1) == '0' then
Id = Id:sub(2)
else
break
end
end
return Id
end
----------------------------------------------
-- Fin de la partie configuration --
----------------------------------------------
commandArray={}
--import des fontions pour lire le JSON
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
--recuperation des mesure HP et HC sur data.json
local config=assert(io.popen("curl '"..url.."'"))
local location = removeZeros(config:read('*all'))
local trouve = string.find(location,'"conso_hp"')
local consoHP = removeZeros(string.sub(location,trouve+15,trouve +23))
local trouve = string.find(location,'"conso_hc"')
local consoHC = removeZeros(string.sub(location,trouve+15,trouve +23))
config:close()
if Debug == "YES" then
print(trouve)
print(location)
print(consoHP)
print(consoHC)
end
--import des valeurs dans les Idx
commandArray[htidx] = { ['UpdateDevice'] = htidx ..'|0|'.. consoHP .. ";" .. consoHC.. ";" .. "0" .. ";" .. "0" .. ";" .. "0" .. ";" .. "0" }
commandArray[hpidx] = { ['UpdateDevice'] = hpidx ..'|0|'.. consoHP }
commandArray[hcidx] = { ['UpdateDevice'] = hcidx ..'|0|'.. consoHC }
return commandArray
Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 12 nov. 2019, 01:30
par aeronne
@damolc
Merci pour l'info "P1 compteur intelligent, et deux Idx compteurs pour HP et HC""
Pour le reste, super travail! J'ai hâte de trouver 5mn pour tester. Si j'ai bien lu, un script pour trois périphériques qui récupère les infos HC et HP la consommation totale.
Parfait pour moi. Merci
Re: Récupérer sa conso linky avec ecocompteur legrand
Publié : 12 nov. 2019, 07:58
par damolc
Oui c est bien ça ;
