Page 1 of 1

S0 device issues

Posted: Thursday 20 February 2025 12:57
by HvdW
rron wrote: Saturday 08 February 2025 13:35 There is some progress when I use your call. Only "Vandaag"is giving a value but not on top. Have I forgotten something?
Here is a test script you can use.
It gets the data from this S0 Pulse Meter.
I tried it at first with a 'normal'script.

Code: Select all

return {
	on = {
		devices = {'YourSwitch'},
		timer = {},
		variables = {},
		scenes = {},
		groups = {},
		security = {},
		httpResponses = {},
		shellCommandResponses = {},
		customEvents = {},
		system = {},
	},
	data = {
	    whToday = { initial = nil },
	    whTotal = { initial = nil },
	    },
	logging = {},
	execute = function(domoticz, triggeredItem)
        domoticz.devices('Laadpaal').dump()
        domoticz.data.whTotal = domoticz.devices('Laadpaal').whTotal -- 3108061.75
        domoticz.data.whToday = domoticz.devices('Laadpaal').whToday
        domoticz.log("domoticz.data.whTotal" .. domoticz.data.whTotal, domoticz.LOG_INFO)
        domoticz.log("domoticz.data.whToday" .. domoticz.data.whToday, domoticz.LOG_INFO)
	end
}
This script returned NIL values.
Using a json call you will receive the data you want to receive.

Code: Select all

return {
    on = {
        devices = {'YourSwitch'},
        timer = {},
        variables = {},
        scenes = {},
        groups = {},
        security = {},
        httpResponses = {'LaadpaalData'}, -- Voeg een HTTP-response handler toe
        shellCommandResponses = {},
        customEvents = {},
        system = {},
    },
    data = {
        whToday = { initial = nil },
        whTotal = { initial = nil },
    },
    logging = {
        level = domoticz.LOG_DEBUG, -- Zet logging op DEBUG voor meer details
        marker = "Laadpaaltest",
    },
    execute = function(domoticz, triggeredItem)
        -- Controleer of de trigger een HTTP-response is
        if triggeredItem.isHTTPResponse then
            -- Log de volledige JSON-response voor debugging
            domoticz.log("Volledige JSON-response: " .. triggeredItem.data, domoticz.LOG_DEBUG)

            -- Verwerk de JSON-response
            local json = triggeredItem.json
            if json and json.result and json.result[1] then
                -- Haal de waarden uit Data en CounterToday
                local data = json.result[1].Data -- Bijvoorbeeld "3108.063 kWh"
                local counterToday = json.result[1].CounterToday -- Bijvoorbeeld "3.882 kWh"

                -- Verwijder de eenheid "kWh" en converteer naar een getal
                domoticz.data.whTotal = tonumber(data:match("%d+%.%d+")) -- Haal alleen het numerieke deel
                domoticz.data.whToday = tonumber(counterToday:match("%d+%.%d+")) -- Haal alleen het numerieke deel

                -- Log de waarden
                domoticz.log("domoticz.data.whTotal: " .. tostring(domoticz.data.whTotal), domoticz.LOG_INFO)
                domoticz.log("domoticz.data.whToday: " .. tostring(domoticz.data.whToday), domoticz.LOG_INFO)
            else
                domoticz.log("Geen geldige JSON-response ontvangen", domoticz.LOG_ERROR)
            end
        else
            -- Als de trigger een apparaat is, stuur dan een JSON-call
            domoticz.openURL({
                url = 'http://192.168.2.100:8383/json.htm?type=devices&rid=2457',
                method = 'GET',
                callback = 'LaadpaalData', -- Gebruik dezelfde naam als de HTTP-response handler
            })
            domoticz.log("JSON-call gestuurd om Laadpaal-gegevens op te halen", domoticz.LOG_INFO)
        end
    end
}
Hope this helps.

BTW
For testing purposes I use a switch device 'YourSwitch' to trigger a script. I used to use 'every 1 minutes' as a trigger but like the switch trigger better.

Re: Energy Dashboard (Build in)

Posted: Friday 21 February 2025 20:28
by Kedi
@HvdW What does this 'stripped' script return?

Code: Select all

return {
	on = {
		devices = {'YourSwitch'},
		},
	execute = function(dz, Item)
	        dz.log("whTotal " .. dz.devices('Laadpaal').whTotal, dz.LOG_INFO)
        	dz.log("whToday " .. dz.devices('Laadpaal').whToday, dz.LOG_INFO)
	end
}

S0 meter

Posted: Saturday 22 February 2025 11:16
by HvdW
Here you go:

Code: Select all

2025-02-22 10:59:32.684 dzVents: Handling events for: "YourSwitch", value: "On"
2025-02-22 10:59:32.684 dzVents: -------- YOUR TEST SCRIPT --------: ------ Start internal script: Your Test Script: Device: "YourSwitch (Dummy)", Index: 599
2025-02-22 10:59:32.686 dzVents: Debug: -------- YOUR TEST SCRIPT --------: Processing device-adapter for Laadpaal: kWh device adapter
2025-02-22 10:59:32.687 Error: dzVents: -------- YOUR TEST SCRIPT --------: An error occurred when calling event handler Your Test Script
2025-02-22 10:59:32.687 Error: dzVents: -------- YOUR TEST SCRIPT --------: ...z/scripts/dzVents/generated_scripts/Your Test Script.lua:29: attempt to concatenate a nil value (field 'whTotal')
2025-02-22 10:59:32.687 dzVents: -------- YOUR TEST SCRIPT --------: ------ Finished Your Test Script
The json call I showed before returns these values.

Code: Select all

2025-02-22 11:02:06.577 dzVents: Laadpaaltest: domoticz.data.whTotal: 3140.213
2025-02-22 11:02:06.577 dzVents: Laadpaaltest: domoticz.data.whToday: 11.976
2025-02-22 11:02:06.578 dzVents: Laadpaaltest: ------ Finished Your Test Script
I have been struggling quite some time wirh this S0 device.
Another observation was that after switching the 'Laadpaal' (Charging Pole/Charging Point) the displayed values in the domoticz sensor changed over a time span of more than a minute from (example) 3500 W to 0 W.
I can imagine that the on-board charger (OBC) doesn't switch off at once, but more than a minute?

My thoughts: The S0 device does fill values in a sensor and an dump() gives values, so why do I receive why these nil values, using value = domoticz.devices('Laadpaal').whTotal?

In the end the step to json resolved the problem.

Still: HOW COME ?!

Sorry for posting this in the Energy Dashboard (Built-in).
Maybe some posts should be placed in an item like S0 meters.

Re: S0 device issues

Posted: Saturday 22 February 2025 18:01
by waltervl
Splitted of the energy dashboard topic.
Not clear for me what the issue with the S0 device is.
When going to the website I read in the comments there is a new firmware that fixes some issues:
https://www.sossolutions.nl/5-kanaals-s ... ter-op-usb

https://www.smartmeterdashboard.nl/blog ... eschikbaar

Re: S0 device issues

Posted: Saturday 22 February 2025 20:21
by waltervl
What line is giving nil values? The one of persistent data value or the one from the device itself?
The log you showed cannot be the log from the simple script of @Kedi as that has only 9 lines and your log gives an error on line 29.