energy meter day - night

Moderator: leecollings

Post Reply
Jojik1
Posts: 16
Joined: Monday 06 January 2020 23:57
Target OS: -
Domoticz version:
Contact:

energy meter day - night

Post by Jojik1 »

Hello my English bad.
I use: SDM 630 https://github.com/MFxMF/SDM630-Modbus - connected domoticz OK.
import energy measurement day and night
when day domoticz idx 108 off
when night domoticz idx 108 on

when idx(27) --OWL !!! other meter Type: General,kWh !!! OK
when idx(341) --OWL !!! meter SDM 630 Type: RFXMeter, RFXMeter, Counter !!! does not work

log domoticz:
2020-01-29 17:12:43.021 Error: EventSystem: in day_night: [string "function log(p_message)..."]:25: attempt to concatenate a nil value (global 'consEnergy')

I need:
change the script to read the value RFXMeter,Counter
or:
or convert RFXMeter, Counter to the value General, kWh

I use this solution:

Code: Select all

function log(p_message)
-- print("[HPHC] " .. p_message)
end
function getdevname4idx(deviceIDX)
 for i, v in pairs(otherdevices_idx) do
   if v == deviceIDX then
     return i
   end
 end
 return 0
end

commandArray = {}
DEBUG = false

local nomCompteurPrincipal = getdevname4idx(341) --OWL
local idxCompteurIntelligent = 363
local nomCompteurIntelligent = getdevname4idx(idxCompteurIntelligent)--HPHC
local nomHeureCreuse = getdevname4idx(108) -- Switch Heures Creuses

for deviceName,deviceValue in pairs(devicechanged) do
 if (deviceName==nomCompteurPrincipal) then
   -- On récupère la valeur du compteur unique => consEnergy
   ConsPower, consEnergy = string.match(otherdevices_svalues[nomCompteurPrincipal], "(%d+%.*%d*);(%d+%.*%d*)")
   log(ConsPower.."-"..consEnergy)
   --on somme les compteurs HP et HC => EnergyImport
   --http://www.domoticz.com/wiki/Upload_energy_data_to_PVoutput
   EnergyImportLow, EnergyImportHigh, EnergyExportLow, EnergyExportHigh, PowerImport, PowerExport = otherdevices_svalues[nomCompteurIntelligent]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
  
   -- For the first time, the value are not initilize in the smart counter, we set 0 by default.
   if(EnergyImportLow == nil)then
     EnergyImportLow = 0
     EnergyImportHigh = 0
     EnergyExportLow = 0
     EnergyExportHigh = 0
     PowerImport = 0
     PowerExport = 0
   end
   -- Lors du changement de pile du compteur unique, consEnergy a été réinitialisé, faussant complémtement les valeurs de EnergyImportLow/EnergyImportHigh
   if((EnergyImportLow+0) < 0 or (EnergyImportHigh+0) < 0) then
     EnergyImportLow =0
     EnergyImportHigh =0
     log("  ----- Reinit de EnergyImportLow/EnergyImportHigh");
   end

   EnergyImport = EnergyImportLow + EnergyImportHigh
   EnergyExport = EnergyExportLow + EnergyExportHigh

   log(" ----- PowerImport = " .. PowerImport .. " W");
   log(" ----- EnergyImportLow = " .. EnergyImportLow .. " Wh");
   log(" ----- EnergyImportHigh = " .. EnergyImportHigh .. " Wh");
   log(" ----- EnergyImport = " .. EnergyImport .. " Wh");
   log(" ----- PowerExport = " .. PowerExport .. " W");
   log(" ----- EnergyExportLow = " .. EnergyExportLow .. " Wh");
   log(" ----- EnergyExportHigh = " .. EnergyExportHigh .. " Wh");
   log(" ----- EnergyExport = " .. EnergyExport .. " Wh");
 
   --On calcule le delta avec le compteur actuel
   delta = consEnergy - EnergyImport
 
   --On ajoute le delta sur le bon tarif
   if (otherdevices[nomHeureCreuse] == 'On') then
     EnergyImportLow = EnergyImportLow + delta
   else
     EnergyImportHigh = EnergyImportHigh + delta
   end
 
   --On modifie le compteur intelligent
   commandArray['UpdateDevice'] = idxCompteurIntelligent.."|0|"..EnergyImportLow..";"..EnergyImportHigh..";0;0;"..ConsPower..";0"

 end
end

return commandArray
thank you very much for your help
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: energy meter day - night

Post by bewo »

What's the output of

Code: Select all

commandArray = {}
print(otherdevices_svalues[nomCompteurPrincipal])
return commandArray
And why are you loop over all devices? I don't see the need for this. I think in case of your script just an "if" would be enough.
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Jojik1
Posts: 16
Joined: Monday 06 January 2020 23:57
Target OS: -
Domoticz version:
Contact:

Re: energy meter day - night

Post by Jojik1 »

thank you for your reply, but I don't understand.
value RFXMeter, Counter I use because it is the only one giving the exact value of consumption (calculated SDM630)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest