Page 1 of 1

Need help with script value

Posted: Monday 26 May 2025 12:32
by hemant5400z
Hi All,

I'm trying to get data from General Kwh (Enphase) plugin.

local Produktiekwh = dz.devices(339)

however i'm getting error: attempt to perform arithmetic on a table value (local 'Produktiekwh')

I'm trying to pull value from: "Data" : "8865.927 kWh".


tried:
Produktiekwh = dz.devices(339).counter
Produktiekwh = dz.devices(339).Svalue


Any help appreciated, i know noob question :(

Thanks in advance
Hemant

Re: Need help with script value

Posted: Monday 26 May 2025 13:55
by waltervl
See wiki section kWh, Electricity (instant and counter) as that is the general kWh Sensor
https://wiki.domoticz.com/DzVents:_next ... d_counter)
kWh, Electricity (instant and counter)
.actualWatt: Number. Actual usage in Watt.
.counterToday: Number.
.updateElectricity(power, energy): Function. Supports command options.
.usage: Number.
.WhToday: Number. Total Wh usage of the day. Note the unit is Wh and not kWh!
.WhTotal: Number. Total Wh usage.
.WhActual: Number. Actual reading in Watt. Please use actualWatt
So it depends exactly what you want but I think it is WhTotal: Number. Total Wh usage.
Then the dzvents line should be

Code: Select all

local Produktiekwh = dz.devices(339).WhTotal

Re: Need help with script value

Posted: Monday 26 May 2025 14:06
by HvdW
Try dz.devices(339).dump()
or maybe better, try this script

Code: Select all

--[[
=== DOMOTICZ DEBUG HELPER SCRIPT ===
Geschreven voor dzVents 3.0+
Laatste update: 2024-06-15

FUNCTIES:
1. Toont systeeminformatie (Domoticz/dzVents versie)
2. Inspecteert devices (basisinfo + volledige structuur)
3. Toont tijdberekeningen (datum, zonnetijden)
4. Werkt via switch of custom event trigger

GEBRUIK:
1. Zet 'YourSwitchSelector' aan/uit om te triggeren
OF
2. Gebruik commando: dzVents.emit('DebugRequest')

CONFIGURATIE:
- Pas de TEST_DEVICES lijst aan voor je eigen devices
- Zet LOG_LEVEL op LOG_ERROR voor productie
--]]

-- Configuratieblok (buiten execute aanpasbaar)
local TEST_DEVICES = { 
    'Power',
    --'TFA1 kamer', 
    --'YourSwitch', 
    --'YourTextSensor',
    --'Zonnepanelen',
    --'SmartEVSE'
}

local LOG_LEVEL = domoticz.LOG_DEBUG  -- LOG_ERROR voor productie
local TRIGGER_DEVICE = 'YourSwitchSelector'

-- Script hoofdstructuur
return {
    active = true,
    on = {
        devices = { TRIGGER_DEVICE },
        customEvents = { 'DebugRequest' },
        timer = {
            'every 1 minutes' -- every  x minutes
        },
    },

    logging = {
        level = LOG_LEVEL,
        marker = 'DEBUG HELPER',
    },
    
    execute = function(dz, item)
        -- ===== SYSTEEMINFO =====
        dz.log('\n=== SYSTEEMINFORMATIE ===', dz.LOG_INFO)
        dz.log('Domoticz versie: ' .. (dz.settings.domoticzVersion or "Onbekend"), dz.LOG_INFO)
        dz.log('dzVents versie: ' .. (dz.utils.DZVERSION or "Onbekend"), dz.LOG_INFO)
        
        -- ===== DEVICE INSPECTIE =====
        dz.log('\n=== DEVICE INSPECTIE ===', dz.LOG_INFO)
        for _, devName in ipairs(TEST_DEVICES) do
            local device = dz.devices(devName)
            if device then
                dz.log(string.format('\nšŸ› ļø  %s (IDX: %d)', devName, device.id), dz.LOG_INFO)
                
                -- Basis device info
                dz.log('BASIS INFO:', dz.LOG_DEBUG)
                pcall(function() dz.log(device.dump(), dz.LOG_DEBUG) end)
                
                -- Uitgebreide info
                dz.log('UITGEBREIDE STRUCTUUR:', dz.LOG_DEBUG)
                pcall(function()
                    dz.log(dz.utils.toJSON({
                        name = device.name,
                        state = device.state,
                        lastUpdate = device.lastUpdate.raw,
                        data = device.rawData or "Geen rawData",
                        deviceType = device.deviceType,
                        deviceSubType = device.deviceSubType
                    }), dz.LOG_DEBUG)
                end)
            else
                dz.log('āŒ Device niet gevonden: ' .. devName, dz.LOG_ERROR)
            end
        end
        
        -- ===== TIJD BEREKENINGEN =====
        dz.log('\n=== TIJDGEGEVENS ===', dz.LOG_INFO)
        pcall(function()
            local now = os.date('*t')
            local lastDay = os.date('*t', os.time{year=now.year, month=now.month+1, day=0})
            
            dz.log('šŸ“… Datum: ' .. os.date('%A %d %B %Y'), dz.LOG_INFO)
            dz.log('ā° Tijd: ' .. os.date('%H:%M:%S'), dz.LOG_INFO)
            dz.log('šŸ—“ļø Laatste dag van de maand: ' .. lastDay.day, dz.LOG_INFO)
            dz.log('šŸŒ… Zon op/onder: ' .. dz.time.sunriseInMinutes .. '/' .. dz.time.sunsetInMinutes, dz.LOG_INFO)
        end)
        
        dz.log('\n=== DEBUG VOLTOOID ===\n', dz.LOG_INFO)
    end
}
You can use a virtual switch or the timer to execute the script.
Replace the name under TEST_DEVICES with the nam of your device.

PS
In many programming scripts one users camelCase where nValue and sValue are written like first word starting with lowercase and the second, third party starting in uppercase.
So sValue has a better chance than Svalue.

Re: Need help with script value

Posted: Monday 26 May 2025 14:59
by waltervl
HvdW wrote: ↑Monday 26 May 2025 14:06 Try dz.devices(339).dump()
Seems to be overkill for something a noob, as Topic Starter claims is, can read in the docs....

Re: Need help with script value

Posted: Monday 26 May 2025 16:05
by hemant5400z
waltervl wrote: ↑Monday 26 May 2025 13:55 See wiki section kWh, Electricity (instant and counter) as that is the general kWh Sensor
https://wiki.domoticz.com/DzVents:_next ... d_counter)
kWh, Electricity (instant and counter)
.actualWatt: Number. Actual usage in Watt.
.counterToday: Number.
.updateElectricity(power, energy): Function. Supports command options.
.usage: Number.
.WhToday: Number. Total Wh usage of the day. Note the unit is Wh and not kWh!
.WhTotal: Number. Total Wh usage.
.WhActual: Number. Actual reading in Watt. Please use actualWatt
So it depends exactly what you want but I think it is WhTotal: Number. Total Wh usage.
Then the dzvents line should be

Code: Select all

local Produktiekwh = dz.devices(339).WhTotal
Ah yes that is what I was after with one minor addition, the

Whtotal is a kind of counter i would like to have
whtotal - whtotal from (18-02-2025) = actual production of contract year :) assuming the value in calendar_meter on 18-02 is 0:00 which is may start date.

hemant

Re: Need help with script value

Posted: Monday 26 May 2025 16:17
by waltervl
That is possible but not an easy script, I believe there are already scripts available on this subject in this forum.
You generally have to search and summarize all daily total values from your contract date.

Edit: See for example viewtopic.php?t=42454

Re: Need help with script value

Posted: Monday 26 May 2025 17:53
by hemant5400z
Ah yes something similar,

in my case http://xxxx:8080/json.htm?type=command& ... 2026-02-17.
What i get is a large range of daily values, is it possible to do a SUM directly?

Hemant

Re: Need help with script value

Posted: Monday 26 May 2025 19:44
by waltervl
No, else this would not need a complex script :-)