Power generated message
Moderator: leecollings
-
- Posts: 67
- Joined: Wednesday 10 May 2017 17:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Power generated message
Hi,
I have a SMA Converter for my solar panels, it's already connected in Domoticz via SBFspot so i can see the generated power.
The "Total generated" and "Generated today" are shown in the device under Utility.
Is it possible to receive a message when the generation of "today" has reached a value? like 20kwh.
I have a SMA Converter for my solar panels, it's already connected in Domoticz via SBFspot so i can see the generated power.
The "Total generated" and "Generated today" are shown in the device under Utility.
Is it possible to receive a message when the generation of "today" has reached a value? like 20kwh.
-
- Posts: 67
- Joined: Wednesday 10 May 2017 17:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Power generated message
I've created a basic script now, sends a message when the counterToday is higher then 12.000 kwh.
LOG:
2018-07-12 14:00:21.828 Status: dzVents: Info: Handling events for: "SMA_SolarMain", value: "2390.000;13887088.000"
2018-07-12 14:00:21.828 Status: dzVents: Info: ------ Start internal script: SMA_generation: Device: "SMA_SolarMain (SMA)", Index: 115
2018-07-12 14:00:21.828 Status: dzVents: Info: ------ Finished SMA_generation
2018-07-12 14:00:22.005 Status: Notification: SMA_generation
Problem is that it sends a message each 5minutes (SMA refresh rate is at 5minutes) when the target is met.
Going to try to only send a message when there's no more generation and 20kwh or higher is generated;
"Usage" (which is realtime generation) = 0 and "counterToday" > 20
Getting to send the "result" of "counterToday" inside the message is the next step.
That can also send multiple messages but i dont have a clue to only send 1.
Code: Select all
return {
on = {
devices = {'SMA_SolarMain'},
},
execute = function(domoticz, device)
if domoticz.devices("SMA_SolarMain").counterToday > 12 then
domoticz.notify("SMA Generated ","Generated 12kwh.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
end
end
}
2018-07-12 14:00:21.828 Status: dzVents: Info: Handling events for: "SMA_SolarMain", value: "2390.000;13887088.000"
2018-07-12 14:00:21.828 Status: dzVents: Info: ------ Start internal script: SMA_generation: Device: "SMA_SolarMain (SMA)", Index: 115
2018-07-12 14:00:21.828 Status: dzVents: Info: ------ Finished SMA_generation
2018-07-12 14:00:22.005 Status: Notification: SMA_generation
Problem is that it sends a message each 5minutes (SMA refresh rate is at 5minutes) when the target is met.
Going to try to only send a message when there's no more generation and 20kwh or higher is generated;
"Usage" (which is realtime generation) = 0 and "counterToday" > 20
Getting to send the "result" of "counterToday" inside the message is the next step.
That can also send multiple messages but i dont have a clue to only send 1.
-
- Posts: 19
- Joined: Monday 23 January 2017 17:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Power generated message
Hi instead of "on device" use "on timer"
Your code:
new code:
But you need use "device(idx)" where "idx" is idx of your device (or you can use name of device)
Your code:
Code: Select all
on = {
devices = {'SMA_SolarMain'},
},
Code: Select all
on = {
timer = {
-- timer triggers.. if one matches with the current time then the script is executed
'at 23:59',
}
Code: Select all
domoticz.devices(idx).counterToday
-
- Posts: 67
- Joined: Wednesday 10 May 2017 17:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Power generated message
onTimer is not what i what, then it sends out a message at a certain time. I want to have it send a message when it can.
I've now created the script below.
Check's the counterToday, when it's above the numerToNotify it checks if the WhActual is zero, then it sends out 1 message.
When there's no power generation only one "0" value will be created by SBFspot at the end of the day.
At that time, DzVents script will pick it up and sends out a message with the total generated power of that day.
I've now created the script below.
Check's the counterToday, when it's above the numerToNotify it checks if the WhActual is zero, then it sends out 1 message.
When there's no power generation only one "0" value will be created by SBFspot at the end of the day.
At that time, DzVents script will pick it up and sends out a message with the total generated power of that day.
Code: Select all
local sensorGenerator = 'SMA_SolarMain' -- fill in the sensor name which generated the power
local numberToNotify = 20
return {
on = {
devices = {sensorGenerator},
},
execute = function(domoticz, device)
local returnToday = domoticz.devices(sensorGenerator).counterToday
local returnCurrent = domoticz.devices(sensorGenerator).WhActual
if returnToday > numberToNotify and returnCurrent == 0 then
domoticz.notify('SMA Generated','Power generated today: '..returnToday, domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
end
end
}
-
- Posts: 470
- Joined: Thursday 26 October 2017 13:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Delft
- Contact:
Re: Power generated message
You can add a data section to your script, and in this section define a variable to hold the date the last message was sent. The value of the variables in the data section are stored after your script ran and restored before your script runs the next time.
Now whenever the script runs due to a device trigger and the value is at or above numberToNotify, you can check the date in this variable: only if it is before today's date you send out a message and then update the variable to today's date. The next time the device trigger runs again, value will still be over numberToNotify, but the date will be today's so no more messages will be sent.
B.t.w. I never done this myself in DzVents, so I have no example, but I suggest to store utc time in the persistent data, not local time, or you will get 2 notifications when daylight saving time (dutch: "zomertijd") changes.
Now whenever the script runs due to a device trigger and the value is at or above numberToNotify, you can check the date in this variable: only if it is before today's date you send out a message and then update the variable to today's date. The next time the device trigger runs again, value will still be over numberToNotify, but the date will be today's so no more messages will be sent.
B.t.w. I never done this myself in DzVents, so I have no example, but I suggest to store utc time in the persistent data, not local time, or you will get 2 notifications when daylight saving time (dutch: "zomertijd") changes.
-
- Posts: 67
- Joined: Wednesday 10 May 2017 17:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Power generated message
Guess that makes the script "too much" and this is the first script i created myself so im proud enough at the momentrrozema wrote: ↑Friday 13 July 2018 10:29 You can add a data section to your script, and in this section define a variable to hold the date the last message was sent. The value of the variables in the data section are stored after your script ran and restored before your script runs the next time.
Now whenever the script runs due to a device trigger and the value is at or above numberToNotify, you can check the date in this variable: only if it is before today's date you send out a message and then update the variable to today's date. The next time the device trigger runs again, value will still be over numberToNotify, but the date will be today's so no more messages will be sent.
B.t.w. I never done this myself in DzVents, so I have no example, but I suggest to store utc time in the persistent data, not local time, or you will get 2 notifications when daylight saving time (dutch: "zomertijd") changes.

It only sends out 1 message so far i can think off, haven't got a message today (17kwh) so will test out the next couple of days when there's 20kwh generated.
-
- Posts: 67
- Joined: Wednesday 10 May 2017 17:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Power generated message
How do i create that dataset in the script i created?rrozema wrote: ↑Friday 13 July 2018 10:29 You can add a data section to your script, and in this section define a variable to hold the date the last message was sent. The value of the variables in the data section are stored after your script ran and restored before your script runs the next time.
Now whenever the script runs due to a device trigger and the value is at or above numberToNotify, you can check the date in this variable: only if it is before today's date you send out a message and then update the variable to today's date. The next time the device trigger runs again, value will still be over numberToNotify, but the date will be today's so no more messages will be sent.
B.t.w. I never done this myself in DzVents, so I have no example, but I suggest to store utc time in the persistent data, not local time, or you will get 2 notifications when daylight saving time (dutch: "zomertijd") changes.
I got multiple messages this evening, each 5minutes.
2018-07-14 21:55:22.110 Status: Notification: SMA Generated
2018-07-14 22:00:22.263 Status: Notification: SMA Generated
2018-07-14 22:05:22.364 Status: Notification: SMA Generated
2018-07-14 22:10:21.518 Status: Notification: SMA Generated
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Power generated message
with datasection defined with history = true (explained in wiki here) and check on time, it looks like something belowterrorsource wrote: ↑Saturday 14 July 2018 22:20How do i create that dataset in the script i created?rrozema wrote: ↑Friday 13 July 2018 10:29 You can add a data section to your script, and in this section define a variable to hold the date the last message was sent. The value of the variables in the data section are stored after your script ran and restored before your script runs the next time.
----
...
Code: Select all
local sensorGenerator = 'SMA_SolarMain' -- fill in the sensor name which generated the power
local numberToNotify = 20
return {
on = { devices = {sensorGenerator} },
data = { notificationSent = { history = true, maxItems = 1 }},
execute = function(domoticz, device)
local returnToday = domoticz.devices(sensorGenerator).counterToday
local returnCurrent = domoticz.devices(sensorGenerator).WhActual
if returnToday > numberToNotify and returnCurrent == 0 then
local messageSent = domoticz.data.notificationSent.getLatest()
if not(messageSent) or not(messageSent.time.isToday) then -- not(MessageSent) for the case where data is not yet created)
domoticz.notify('SMA Generated','Power generated today: '..returnToday, domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
domoticz.data.notificationSent.add('Power generated today: '..returnToday)
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
Who is online
Users browsing this forum: No registered users and 1 guest