Need help with script value

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
hemant5400z
Posts: 101
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

Need help with script value

Post 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
User avatar
waltervl
Posts: 5770
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Need help with script value

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 600
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Need help with script value

Post 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.
Last edited by HvdW on Monday 26 May 2025 15:11, edited 2 times in total.
Bugs bug me.
User avatar
waltervl
Posts: 5770
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Need help with script value

Post 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....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hemant5400z
Posts: 101
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

Re: Need help with script value

Post 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
User avatar
waltervl
Posts: 5770
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Need help with script value

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hemant5400z
Posts: 101
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

Re: Need help with script value

Post 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
User avatar
waltervl
Posts: 5770
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Need help with script value

Post by waltervl »

No, else this would not need a complex script :-)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest