Help wanted with cleaning up script
Posted: Sunday 05 February 2017 12:23
Hi all,
As I am not very experienced in scripting, I get my scripts working working most of the time but they are not very clean.
Anybody willing to help me cleanup/simplify this script? It gets the "counterToday" from several powermeters and reports the cost, with currently updating only one virtual counter.
Thanks in advance!
As I am not very experienced in scripting, I get my scripts working working most of the time but they are not very clean.
Anybody willing to help me cleanup/simplify this script? It gets the "counterToday" from several powermeters and reports the cost, with currently updating only one virtual counter.
Code: Select all
return {
active = true,
on = {
['timer'] = 'every 20 minutes'
},
execute = function(domoticz)
local Boil = domoticz.devices['kWhboiler']
local Sec = domoticz.devices['kWh-secadora']
local Bed = domoticz.devices['kWh-bedheat']
local Rad1 = domoticz.devices['radiador1-kwh']
local Rad2 = domoticz.devices['kWradiador2']
local Fridge = domoticz.devices['fridgekWh Meter']
local Bath = domoticz.devices['kWhbath']
local Wash = domoticz.devices['kWh-wash']
local CCost = domoticz.devices['CostHeating']
local dBoil = Boil.counterToday
local sdBoil = tonumber(string.sub(dBoil, 1, -5)) *0.15
local rdsBoil = math.floor(sdBoil * 100 +0.5) / 100
local dSec = Sec.counterToday
local sdSec = tonumber(string.sub(dSec, 1, -5)) * 0.15
local rdsSec = math.floor(sdSec * 100 +0.5) / 100
local dBed = Bed.counterToday
local sdBed = tonumber(string.sub(dBed, 1, -5)) * 0.15
local rdsBed = math.floor(sdBed * 100 +0.5) / 100
local dRad1 = Rad1.counterToday
local sdRad1 = tonumber(string.sub(dRad1, 1, -5)) * 0.15
local rdsRad1 = math.floor(sdRad1 * 100 +0.5) / 100
local dRad2 = Rad2.counterToday
local sdRad2 = tonumber(string.sub(dRad2, 1, -5)) * 0.15
local rdsRad2 = math.floor(sdRad2 * 100 +0.5) / 100
local dFridge = Fridge.counterToday
local sdFridge = tonumber(string.sub(dFridge, 1, -5)) * 0.15
local rdsFridge = math.floor(sdFridge * 100 +0.5) / 100
local dBath = Bath.counterToday
local sdBath = tonumber(string.sub(dBath, 1, -5)) * 0.15
local rdsBath = math.floor(sdBath * 100 +0.5) / 100
local dWash = Wash.counterToday
local sdWash = tonumber(string.sub(dWash, 1, -5)) * 0.15
local rdsWash = math.floor(sdWash * 100 +0.5) / 100
local Csalon = rdsRad1 + rdsRad2
local totheat = Csalon + rdsBath + rdsBed
domoticz.log('Bedroom heating cost today € ' .. rdsBed, domoticz.LOG_INFO)
domoticz.log('Salon heating cost today € ' .. Csalon, domoticz.LOG_INFO)
domoticz.log('Bathroom heating cost today € ' .. rdsBath, domoticz.LOG_INFO)
domoticz.log('Boiler cost today € ' .. rdsBoil, domoticz.LOG_INFO)
domoticz.log('Fridge cost today € ' .. rdsFridge, domoticz.LOG_INFO)
domoticz.log('Washer cost today € ' .. rdsWash, domoticz.LOG_INFO)
domoticz.log('Dryer cost today € ' .. rdsSec, domoticz.LOG_INFO)
domoticz.log('==================================== ', domoticz.LOG_INFO)
domoticz.log('Heating total cost today € ' .. totheat, domoticz.LOG_INFO)
domoticz.log('==================================== ', domoticz.LOG_INFO)
CCost.updateCounter(totheat * 1000)
end
}