In the first part of the script I have defined the persistent data:
Code: Select all
return {
active = true,
logging = {
level = domoticz.LOG_INFO, -- Uncomment to override the dzVents global logging setting
marker = 'TEST '
},
on = {
devices = {
'Wasmachine (W)',
'Wasmachine',
'Slaapkamer Paul Schakelaar',
'Slaapkamer Paul Schakelaar (W)',
'Dimmer WC 1ste',
'Dimmer WC 1ste (W)',
'Dimmer WC BG',
'Dimmer WC BG (W)',
'Espressomachine',
'Espressomachine (W)'
},
},
data = {
WattWasmachine = { history = true, maxMinutes = 6 },
WattSlaapkamerPaulSchakelaar = { history = true, maxMinutes = 10 },
WattDimmerWC1ste = { history = true, maxMinutes = 10 },
WattDimmerWCBG = { history = true, maxMinutes = 10 },
WattEspressomachine = { history = true, maxMinutes = 10 }
},
domoticz.data.WattWasmachine.add(sensor.WhActual)
This works. But I want more flexibility.
The part 'WattWasmachine' in 'domoticz.data.WattWasmachine.add(sensor.WhActual)' is the part that changes. So for my 5 persistent data entries I have to create 5 lines of code:
Code: Select all
domoticz.data.WattWasmachine.add(sensor.WhActual)
domoticz.data.WattSlaapkamerPaulSchakelaar.add(sensor.WhActual)
domoticz.data.WattDimmerWC1ste.add(sensor.WhActual)
domoticz.data.WattDimmerWCBG.add(sensor.WhActual)
domoticz.data.WattEspressomachine.add(sensor.WhActual)
Code: Select all
domoticz.data.persistentdata(WattWasmachine).add(sensor.WhActual)
Code: Select all
WattDevice = "Watt" .. string.gsub(device.name, "%s+", "")
domoticz.data.persistentdata(WattDevice).add(sensor.WhActual)