unexpected behavior managed counter

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

Moderator: leecollings

Post Reply
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

unexpected behavior managed counter

Post by Hansh »

I am busy reading the data from my solis inverter and saving it in Domoticz. I use a script in dzventz for this. I'm so far that I can read that correctly, only processing in a managed counter does not give the desired result. Even after several searches on the internet I have not come up with a solution.

In the script I write the found value to the managed counter with the following commands:

Code: Select all

SolarPanel.updateCounter(D.curPower)
SolarPanel.updateHistory(historyTime.rawDateTime,'10;' .. D.curPower) 
SolarPanel.updateHistory(domoticz.time.rawDate,'10;' .. (D.energyToday*1000))
This works fine all day long, I see all the values in the right places. only when moving to the next day does it go wrong. Inexplicably, a value of 0 is added in the history, which makes the chart look strange. (see the screenshots)


Schermafbeelding grafiek.jpg
Schermafbeelding grafiek.jpg (120.83 KiB) Viewed 794 times


in the database it looks like this


Schermafbeelding database.jpg
Schermafbeelding database.jpg (46.88 KiB) Viewed 794 times

The question now is does anyone have an idea why this is happening and/or can someone explain how the managed counter works. I have already checked the div wikis of domoticz for this and I can't get any further with this.
A second question is what is the function of the value 10 in:
updateHistory(historyTime.rawDateTime,'10;' .. D.curPower)

I hope someone can help me on my way
Thanks for the effort
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
User avatar
waltervl
Posts: 5842
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: unexpected behavior managed counter

Post by waltervl »

Why do you use a managed counter?
You better use a "Electricity (instant and counter)", Counter or Incremental Counter device as it will do all the history logging for you. See also https://www.domoticz.com/wiki/Dummy_for ... l_Switches for some extra explanation.

How do you calculate or read from your solarpanels the D.energyToday? What is the meaning of this value?

If you use the "Electricity (instant and counter)" you can send D.curPower and the D.energyToday counter if D.energyToday is calculated as the total power generated until current time.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

Re: unexpected behavior managed counter

Post by Hansh »

@waltervl
thanks for your reaction

I use a managed counter because it can be adjusted to your own liking.
I'll give the Electricity one a try. The problem is that the div wiki of domoticz give different explanations

https://www.domoticz.com/wiki/Dummy_for ... counter.29
tell you to use the following values

POWER = current power
ENERGY = cumulative energy in Watt-hours (Wh) This is an incrementing counter.

https://www.domoticz.com/wiki/DzVents:_ ... counter.29

tell you to use the following values

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

this confuses me

the value D.energyToday is the daily total value of the generated power and comes directly from the solis inverter without calculation

I will let you know my findings with electricity
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
User avatar
waltervl
Posts: 5842
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: unexpected behavior managed counter

Post by waltervl »

It is the same info.
In dzVents only .updateElectricity(power, energy) is a valid option to set/update the values of the counter. The rest are all options to read, not set.
POWER = current power
ENERGY = cumulative energy in Watt-hours (Wh) This is an incrementing counter. So D.EnergyToday cannot be used, you need someting like D.EnergyTotal
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

Re: unexpected behavior managed counter

Post by Hansh »

Thanks again for the response

I've been playing around with electricity for a while.

Basically it does what I want. Only the daily yield is a problem. The data that I collect once every 5 min only contains the daily yield (besides a lot more info) and not the total yield. Now, of course, I can calculate this in my script. This has to be done via a variable that is only adjusted once a day. A problem then arises. The solar panels stop at too little yield and the script then stops working (nonsense to run a script if it is not necessary). This stop does not happen at a fixed time. It is important that at the last execution of the script I update the aforementioned variable so that I start the day later with the correct value.
Adjusting the operating mode of Electricity so that you only have to pass on the power is not a real option either. The values ​​will then get out of line and that is not the intention (the calculated value will end up with the value passed on by the inverter)

All in all, when using Electricity, there are enough challenges for me to make it work the way I want it to.
The managed counter also shows what I want, only there is the problem that a 0 value is set in the database when the day changes. In another application where I use a managed counter this does not happen. At "find the 7 differences" between these applications I can't find anything that explains the 0 value.
So hence my original question.
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
User avatar
waltervl
Posts: 5842
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: unexpected behavior managed counter

Post by waltervl »

The history on the managed counter is managed by you so you are sending that 0 value. Perhaps make a check or do some extra loggings?
For now, you know you can delete those 0 entries by hand by clicking on the 0 value in the month graph while having the SHIFT key pressed. A popup will be shown to accept the removal https://www.domoticz.com/wiki/Managing_ ... m_database
But I am not sure you can get those 0 values as they are on the same date as the good values.

From what brand solar panel inverter do you get those values? Perhaps there is a plugin? https://www.domoticz.com/wiki/Plugins
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Toulon7559
Posts: 858
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: unexpected behavior managed counter

Post by Toulon7559 »

Hansh in his first message of this thread hints to a Solis-inverter and a dzvents-script.
Perhaps he can 'refine' the information by giving the type/model of the inverter and by linking to a message or to a location where the script can be found.
Might be that we can link his question to this thread.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

Re: unexpected behavior managed counter

Post by Hansh »

@Toulon7559

I have read the commented thread. I got a lot of inspiration and code from this thread to make my script

The inverter used is a solis-S5 mini 700W

Below my script a lot of inspiration and code examples are taken from the internet
a little explanation
It is intended that when the solar panels are on, the value is displayed in domoticz.
The part where it is determined whether the panels deliver has yet to be made. To simulate this I took sunset and sunrise

Code: Select all

return {
	on = {
		    timer = {'every 5 minutes'},		
		    httpResponses = {'solisInlog','solisData'},
	},
	
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'solarpanel',
    },
	    
	execute = function(domoticz, item)
	    
        domoticz.log('Timer event was triggered by ' .. item.trigger, domoticz.LOG_DEBUG)
        
        -- ****** Start of personal settings *****
        local username = "USERNAME"
        local pw="PASSW"
        
        --devices
        local SolarPanelState = domoticz.devices(185) --schakelaar die aangeeft of panelen aan of uit staan
        local SolarPanel = domoticz.devices(186) --managed counter voor weergeven van de data
        
        -- ****** End of personal settings *****
        
        
        
        local function callInlog()
            
            domoticz.log("function callInlog", domoticz.LOG_INFO)
            
            --logt in bij ginlog om de gegevens op te halen
           domoticz.openURL({
               url='http://m.ginlong.com/cpro/login/validateLogin.json?userName='.. username..'&password='..pw..'&lan=2&domain=m.ginlong.com&userType=C',
               method = 'post',
               callback='solisInlog',
                
           })
       
        end
        
        local function procesInlogData(results)
            
            domoticz.log("function procesInlogData", domoticz.LOG_DEBUG)
            
            return results.isAccept
            
        end    
        
        local function callData()
            
            domoticz.log("function callData", domoticz.LOG_DEBUG)
            
            --Haalt de data op van de ginlog site
           domoticz.openURL({
               url='https://m.ginlong.com/cpro/epc/plantview/view/doPlantList.json',
               method = 'post',
               callback='solisData',
                
           })
       
        end
        
        local function procesData(Data)
            
            domoticz.log("Function procesData", domoticz.LOG_DEBUG)
            
            
            for index, D in ipairs(Data) do
                
                domoticz.log("Actuele opbrengst: "..D.curPower, domoticz.LOG_INFO)
                domoticz.log("Dagopbrengst: "..D.energyToday, domoticz.LOG_INFO)
                
                --Tijd in variabele om timing problemen te voorkomen
                local historyTime = domoticz.time
                
                SolarPanel.updateCounter(D.curPower)
                SolarPanel.updateHistory(historyTime.rawDateTime,'10;' .. D.curPower)
                SolarPanel.updateHistory(historyTime.rawDate,'10;' .. (D.energyToday*1000))
                
            end
            
            
            
        end
        
        
        
        -- Main programma executie
        
        --uitvoeren wanneer deze ligt tussen zonsopgang en zonsondergang
        if (domoticz.time.matchesRule("between sunrise and sunset")) then
            
            SolarPanelState.switchOn().checkFirst()
                
            if (item.isTimer) then
                
                callInlog()
                
            end
        
            --uitvoeren bij de juiste callback
            if (item.isHTTPResponse and item.isJSON) then
                
                if item.trigger=='solisInlog' then -- bij inlog calback
                    
                    domoticz.log("httresponse solislogin", domoticz.LOG_DEBUG)
                    
                    --uitvoeren bij een geaccepteerde login
                    if procesInlogData(item.json.result) then
                        
                        callData()
                        
                    end
                    
                elseif item.trigger=='solisData' then --bij data callback
                
                    domoticz.log("httresponse solisData", domoticz.LOG_DEBUG)
                    
                    procesData(item.json.result.pagination.data)
                    
                end
                
            end
        else -- tijdens de 'nacht' de paneelschakelaar uit zetten
            
            SolarPanel.updateCounter(1)
            SolarPanelState.switchOff().checkFirst()
                
        end
    end
}

The problem is not getting the data. That works well. The strange behavior of the manage counter is the problem.

I created a second counter where I don't use the following line
SolarPanel.updateHistory(historyTime.rawDateTime,'10;' .. D.curPower)
and there I don't get the strange 0 value ???????

maybe a timing problem?

i'm out of options
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
User avatar
Hansh
Posts: 22
Joined: Sunday 17 February 2019 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Rotterdam
Contact:

Re: unexpected behavior managed counter

Post by Hansh »

Reading my post the following thought came to mind;
maybe the problem can be avoided by not executing the whole script between sunset and sunrise by adjusting the trigger with:

timer = {'every 5 minutes between sunrise and sunset'},

If this prevents the problem, then we know a little more where to look
It remains strange that two values ​​can be written in the history of a managed counter for the same day. The only question is how this is possible
All my texts are translated from Dutch to English by Google translate>
Sorry for weird sentence structure
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest