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
Switch controlled by power overproduction Topic is solved
Moderators: leecollings, remb0
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Switch controlled by power overproduction
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"
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 5
- Joined: Saturday 31 August 2019 10:57
- Target OS: Windows
- Domoticz version:
- Contact:
Re: Switch controlled by power overproduction
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.
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.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Switch controlled by power overproduction
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 5
- Joined: Saturday 31 August 2019 10:57
- Target OS: Windows
- Domoticz version:
- Contact:
Re: Switch controlled by power overproduction
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)
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.
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
}
Who is online
Users browsing this forum: No registered users and 1 guest