Page 1 of 1

Switch controlled by power overproduction

Posted: Tuesday 10 September 2019 15:08
by muelle4u
Hello ,

i have a small photovoltaik and i use a sonoff pow r2(with tasmota) to messure the produced power. I works awsome!
Additional to that i get the acutall power consumption from the main electric meter.

Now i would like to switch on a second sonoff (with tasmota) ( something linke a charge station for laptops phones and so on ) if i produce more than 100 watts than i use. In math: ( incomming power-used power) > 100 then switch on
Is it possible to do it with a lua script or with a szenario? Is there an example available therefore my Google researche was not that usefull.

Thanks
Julian

Re: Switch controlled by power overproduction

Posted: Tuesday 10 September 2019 15:47
by waaren
muelle4u wrote: Tuesday 10 September 2019 15:08 I would like to switch on a second sonoff (with tasmota) if i produce more than 100 watts than i use.
Is it possible to do it with a lua script or with a szenario?
If you can give the information about the actual devices involved ( power produced / consumed sensors and the switch that controls the second sonoff ) it should be possible to create a dzVents (Lua) script for that.
Easiest is to collect the required information using http://<Domoticz IP>:<Domoticz Port>/json.htm?type=devices&rid=<device id>
The information needed is in the fields "Name", "Type", "SubType", "SwitchType" and "idx"

Re: Switch controlled by power overproduction

Posted: Tuesday 10 September 2019 16:49
by muelle4u
Thanks for the quick Response.
I got the informations:

This is from Sonoff pow r2 tasmota power producing sensor :

"Name" : "Solar_Leistung",
"Type" : "General",
"Usage" : "254 Watt",
"idx" : "4"
"SubType" : "kWh",
"SwitchTypeVal" : 0,


This is the sonoff pow r2 i want to switch :

"Name" : "Steckdosenleiste1_Schalter",
"SubType" : "Switch",
"SwitchType" : "On/Off",
"Type" : "Light/Switch",

"idx" : "8"

And the main power meter is :

"Name" : "Stromzaehler_Keller",

"SubType" : "Energy",

"Type" : "P1 Smart Meter",
"SwitchTypeVal" : 0,
"idx" : "5"


Thanks a lot.

Re: Switch controlled by power overproduction

Posted: Tuesday 10 September 2019 17:54
by waaren
muelle4u wrote: Tuesday 10 September 2019 16:49 I got the informations:
"Name" : "Solar_Leistung",
"Name" : "Steckdosenleiste1_Schalter",
"Name" : "Stromzaehler_Keller",
OK. Can you try this ?

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

 -- Use solar Power if surplus

 return 
 {
    on = { timer = { 'at daytime' } }, 
    
    logging =
    {   
        level = domoticz.LOG_DEBUG ,
        marker = 'surplusPower',
    },
    
    execute = function(dz )
        
        local P1 = dz.devices('Stromzaehler_Keller')
        local solar = dz.devices('Solar_Leistung')
        local sonoff = dz.devices('Steckdosenleiste1_Schalter')  -- Switch for sonoff
        local togglePreventionTime = 300 -- prevent too frequent switching (in seconds)
        
        local usedPower     =  P1.usage - P1.usageDelivered -- net result from P1 (don't know if solarPower already goes over this meter ?)
        local producedPower =  solar.WhActual -- result from Solarpanels 
        
        local surplusPower = producedPower > usedPower -- do we send something to the grid
        dz.log('produced ' .. producedPower .. ', used: ' .. usedPower,dz.LOG_DEBUG)
        
        if sonoff.lastUpdate.secondsAgo >  togglePreventionTime then
            if surplusPower then
                sonoff.switchOn().checkFirst()
            else
                sonoff.switchOff().checkFirst()
            end
        end
    end
}
        

Re: Switch controlled by power overproduction

Posted: Thursday 12 September 2019 8:46
by muelle4u
Hello Waaren,

thanks for your very fast awnser and thanks for the script an the comments ;)

yesterday i implemented the script and you are right only the p1 meter is necessary becaue i get a negativ power if i have a overproduction. Sorry for that. I changed the script a little bit like this.(hopefully normal mathematic arithmetic is possilbe)

Code: Select all

-- Use solar Power if surplus

 return 
 {
    on = { timer = { 'at daytime' } }, 
    
    logging =
    {   
        level = domoticz.LOG_DEBUG ,
        marker = 'surplusPower',
    },
    
    execute = function(dz )
        
        local P1 = dz.devices('Stromzaehler_Keller')
        local solar = dz.devices('Solar_Leistung')
        local sonoff = dz.devices('Steckdosenleiste1_Schalter')  -- Switch for sonoff
        local togglePreventionTime = 300 -- prevent too frequent switching (in seconds)
        
       -- local usedPower     =  P1.usage - P1.usageDelivered -- net result from P1 (don't know if solarPower already goes over this meter ?)
       -- local producedPower =  solar.WhActual -- result from Solarpanels 
       
        local usedPower     =  P1.usageDelivered *(-1)
        local producedPower = 100
        
        local surplusPower = producedPower < usedPower -- do we send something to the grid
        
        dz.log('produced ' .. producedPower .. ', used: ' .. usedPower,dz.LOG_DEBUG)
        
        if sonoff.lastUpdate.secondsAgo >  togglePreventionTime then
            if surplusPower then
                sonoff.switchOn().checkFirst()
            else
                sonoff.switchOff().checkFirst()
            end
        end
    end
}
But actually my P1 meter is not working correct any more. So the last days i was bussy to figure out why but i think i can fix it this eavening, so tomorrow i should be able to say if it works.