Power generated message

Easy to use, 100% Lua-based event scripting framework.
Post Reply
terrorsource
Posts: 40
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Power generated message

Post by terrorsource » Thursday 12 July 2018 13:08

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.

terrorsource
Posts: 40
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Power generated message

Post by terrorsource » Thursday 12 July 2018 14:10

I've created a basic script now, sends a message when the counterToday is higher then 12.000 kwh.

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
}
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.

MiloshCZ
Posts: 21
Joined: Monday 23 January 2017 18:15
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Power generated message

Post by MiloshCZ » Thursday 12 July 2018 15:08

Hi instead of "on device" use "on timer"
Your code:

Code: Select all

	on = {
		devices = {'SMA_SolarMain'},
	},
new code:

Code: Select all

	on = {
		timer = {
			-- timer triggers.. if one matches with the current time then the script is executed
			'at 23:59',
		}
But you need use "device(idx)" where "idx" is idx of your device (or you can use name of device)

Code: Select all

domoticz.devices(idx).counterToday

terrorsource
Posts: 40
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Power generated message

Post by terrorsource » Friday 13 July 2018 8:09

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.

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
}

rrozema
Posts: 107
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi
Domoticz version: beta
Location: Delft
Contact:

Re: Power generated message

Post by rrozema » 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.

terrorsource
Posts: 40
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Power generated message

Post by terrorsource » Friday 13 July 2018 19:29

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.
Guess that makes the script "too much" and this is the first script i created myself so im proud enough at the moment :D
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.

terrorsource
Posts: 40
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Power generated message

Post by terrorsource » Saturday 14 July 2018 22:20

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.
How do i create that dataset in the script i created?
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

User avatar
waaren
Posts: 689
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Power generated message

Post by waaren » Sunday 15 July 2018 7:46

terrorsource wrote:
Saturday 14 July 2018 22:20
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.
----
How do i create that dataset in the script i created?
...
with datasection defined with history = true (explained in wiki here) and check on time, it looks like something below

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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest