Page 1 of 1

Negative Value Smart meter P1

Posted: Sunday 20 October 2024 10:49
by Johan1974
Hello,
I want to switch a relay when more power is generated than 900 watts and it switches off again when 200 watts are supplied back.

It works with positive numbers, but not with negative ones (Smart meter)

Code: Select all

return {
    on = {
        timer   = {'every minute'}
           },


    execute = function(domoticz,state)
        local Relais                          = domoticz.devices (2157) -- Relais
        local SlimmeMeter               = domoticz.devices (22) -- Slimme meter
                     
        
                if (Relais.state == 'Off' and SlimmeMeter.actualWatt < -900 ) then 
                Relais.switchOn()
            end
            
                if (Relais.state == 'On' and SlimmeMeter.actualWatt > -200 ) then
                Relais.switchOff()
            end
        
        
         
        
    end
}

Re: Negative Value Smart meter P1

Posted: Sunday 20 October 2024 11:28
by waltervl
Try to log the values so you are sure you are getting the values from Domoticz you are expecting. What you see on the screen is not always what dzvents is reporting.

Re: Negative Value Smart meter P1

Posted: Monday 21 October 2024 15:04
by willemd
In the code shown it will switch ON when actualWatt for example -1000, -1100, -1200 etc. and switch OFF when for example -100,0, 100 etc.

Is that what you want?

Should the second statement maybe be "> 200" instead of "> -200" ?

Check you number signs and the > and < operators.

Re: Negative Value Smart meter P1

Posted: Monday 21 October 2024 15:10
by waltervl
No, what I mean is add log statements in you script to show in the log what dzvents is doing eg add the following line just below
local SlimmeMeter = domoticz.devices (22) -- Slimme meter

Code: Select all

domoticz.log('SlimmeMeter.actualWatt = ' .. SlimmeMeter.actualWatt, domoticz.LOG_INFO)
In the domoticz log file this log statement should be shown and then you see what dzvents is reading. Then you can check what value to switch on.

Re: Negative Value Smart meter P1

Posted: Monday 21 October 2024 15:15
by HvdW
Make it LOG_DEBUG, set logging to LOG_DEBUG and when you are satisfied later on set logging to LOG_ERROR.