Page 2 of 2

Re: need help dzevets script solar Toon

Posted: Friday 30 May 2025 22:44
by Wiers
I have got it working!
Now I have one device with the most recent solarpower output and a device with the total today.
Tomorrow I am gonna try to get this in the Energy dashboard.

Thanks for putting me in the right direction Walter.

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 0:11
by waltervl
Probably not working like this but you never know...
You probably need the Electric (Instant and counter) for connecting Solar to the Energy Dashboard.

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 14:25
by Wiers
You are right.
But I made this from another piece of coding and adapted that to my needs.
Scherm­afbeelding 2025-05-31 om 14.15.56.png
Scherm­afbeelding 2025-05-31 om 14.15.56.png (53.86 KiB) Viewed 599 times
So the solarpower plus a zero device is now totalpower which shows up in the energy dashboard.

And I have total today also.

But I have 2 same scripts now, one with "current and one with "today"
I think this coud be running in one script but I have to figure that out.

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 15:29
by madpatrick
if you post your scripts we can have a look for you.

Post it as CODE (text in brackets) and not as a picture

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 19:02
by waltervl
If you are filling the right data to the general kWh device totalPower you can delete the other 2.
It will also calculate the daily production for you but it needs a running total counter and not a daily (resetting to 0) counter.
You probably have to add JSON value "total". Please check if that total counter is increasing the same as the "today" value. It will help you a lot if you do this.

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 23:10
by Wiers
This is the "solar" script.

return {
on = {
timer = { 'every 1 minutes' },
httpResponses = { 'solar' }
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.1.56/solar.html',
method = 'GET',
callback = 'solar'
})
elseif (item.isHTTPResponse) then
if (item.ok) then -- statusCode == 2xx
local current = item.json.solar.current
domoticz.devices('solar').updateEnergy(current)
domoticz.log(' current = ' .. current, domoticz.LOG_INFO )
end
end
end
}

And this is the "today" script.

return {
on = {
timer = { 'every 1 minutes' },
httpResponses = { 'solar' }
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.1.56/solar.html',
method = 'GET',
callback = 'solar'
})
elseif (item.isHTTPResponse) then
if (item.ok) then -- statusCode == 2xx
local today = item.json.solar.today
domoticz.devices('PanelsToday').updateEnergy(today)
domoticz.log(' today = ' .. today, domoticz.LOG_INFO )
end
end
end
}

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 23:15
by Wiers
I do not really need a total counter because I already have that on my Apsystems app.
Same as the lifetime calculator.
Most important for me is the "current" value to be used in the Energy Dashboard.

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 23:18
by waltervl
The totalPower device can be used in the energy dashboard as it is now so what is the problem?

Re: need help dzevets script solar Toon

Posted: Saturday 31 May 2025 23:27
by Wiers
There is no problem anymore.
You helped me in the right direction.
Only madpatrick asked me to show my 2 scripts so maybe we can combine them.

Re: need help dzevets script solar Toon

Posted: Sunday 01 June 2025 8:41
by madpatrick
try this

Code: Select all

return {
    on = {
        timer = { 'every 1 minutes' },
        httpResponses = { 'solar' }
    },
    execute = function(domoticz, item)
        if (item.isTimer) then
            domoticz.openURL({
                url = 'http://192.168.1.56/solar.html',
                method = 'GET',
                callback = 'solar'
            })
        elseif (item.isHTTPResponse) then
            if (item.ok) then -- statusCode == 2xx
                local current = item.json.solar.current
                local today = item.json.solar.today

                domoticz.devices('solar').updateEnergy(current)
                domoticz.devices('PanelsToday').updateEnergy(today)

                domoticz.log('current = ' .. current, domoticz.LOG_INFO)
                domoticz.log('today = ' .. today, domoticz.LOG_INFO)
            end
        end
    end
}
please use the code brackets to post script to make it readable
2025-06-01 08_42_00-Domoticz - Edit post.png
2025-06-01 08_42_00-Domoticz - Edit post.png (1.91 KiB) Viewed 493 times

Re: need help dzevets script solar Toon

Posted: Sunday 01 June 2025 8:55
by Wiers
It is working!
Thanks for helping me out.
Now I can delete one script.

Re: need help dzevets script solar Toon

Posted: Sunday 01 June 2025 10:48
by waltervl
Putting kWh data into a sensor created for Watt data is wrong. But if it works from you its fine for me. Just a warning for the next Toon user trying to do the same..

Re: need help dzevets script solar Toon

Posted: Sunday 01 June 2025 12:10
by Wiers
I tried but if I make a device "general kWh" named "solar"
I get this error.
2025-06-01 12:02:01.048 Error: dzVents: An error occurred when calling event handler CombinedSolar
2025-06-01 12:02:01.048 Error: dzVents: ...ticz/scripts/dzVents/generated_scripts/CombinedSolar.lua:18: attempt to call a nil value (field 'updateEnergy')

Re: need help dzevets script solar Toon

Posted: Sunday 01 June 2025 14:58
by waltervl
The update command for the general kWh device is
updateElectricity(power, energy)

Re: need help dzevets script solar Toon

Posted: Monday 02 June 2025 14:40
by Wiers
That did it.
Now I could get rid of a couple of extra coding.
Thanks Walter.