How to update a virtual 'Instant+counter' sensor with Lua

nood
Posts: 21
Joined: Sunday 26 July 2015 13:33
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to update a virtual 'Instant+counter' sensor with Lua

Post by nood » Tuesday 03 April 2018 11:30

I just figured out how to scrape the local url too! I shared my python script here
Hieron wrote:
Sunday 01 April 2018 13:20
Only thing I'm still trying to figure out is how to properly show the value for todays output. The correct value from the inverter is 0.440 kWh. So what is the value "Today: 0.060 kWh"?
I think you only have to find the total value, Domoticz will automaticaly calculate the difference with yesterday's total.

Hieron
Posts: 2
Joined: Saturday 31 March 2018 20:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to update a virtual 'Instant+counter' sensor with Lua

Post by Hieron » Friday 06 April 2018 20:30

yea it works well, after 1 day the totals and all show up fine.

annegerben
Posts: 25
Joined: Wednesday 03 August 2016 12:34
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: How to update a virtual 'Instant+counter' sensor with Lua

Post by annegerben » Friday 03 August 2018 22:26

gsmink wrote:
Sunday 30 July 2017 11:04
Hi Annegerben,

Can you share the code with the ping option
annegerben wrote: Thanks for your code!
I've been using it quite a while, but recently I've added a ping check so the script doesn't have to run completely when the inverter is offline.
reply is a bit late, sorry.
But I'm using the builtin ping and change the code a bit :

if statement on the switch in the beginning and closing it at the end.
Spoiler: show

Code: Select all

commandArray = {}
lineNo = 0
now    = 0
temp   = 0
today  = 0
total  = 0
v1     = 0
v2     = 0
i1     = 0
i2     = 0
ip     = 'ip'
i = 1

-- Only run during day or saj can be pinged
-- if ( uservariables["dark"] == "False" ) then
if (otherdevices['saj'] == "On") then
--if (uservariables["saj_online"] == "on") then
    function UpdateDevice(device, data)
        idx = otherdevices_idx[device]
        if (idx == nil) then
            print('** Unknown device '..device)
        else
            commandArray[i] = {['UpdateDevice'] = idx..'|0|'..data}
            i = i+1
        end
    end

	--Get the XML data from the inverter
    local url = 'curl http://'..ip..'/real_time_data.xml'
    local data = assert(io.popen(url))

    for line in data:lines() do

        if (lineNo == 0 and string.find(line,'Normal') ~= nil) then
            lineNo = 1
        elseif (lineNo > 0) then
            if     (lineNo == 4) then now   = string.match(line, "%d+")
            elseif (lineNo == 5) then temp  = string.match(line, "%d+%.%d+")
            elseif (lineNo == 6) then today = string.match(line, "%d+%.%d+")
            elseif (lineNo == 8) then total = string.match(line, "%d+%.%d+")
            end
            lineNo = lineNo + 1
        end
    end

    data:close()

    if (lineNo >= 14) then
        -- Update the Domoticz GUI
        ep = v1*i1
        wp = v2*i2
        UpdateDevice('Solar', now..";".. total*1000)
        UpdateDevice('Invtemp', temp)

		-- Upload the data to PVoutput every 10 mins
		-- date = os.date("*t")
		-- if (date.min % 10 == 0) then
		--     baseURL="http://pvoutput.org/service/r2/addstatus.jsp?"
		--     API="yourAPIkey"
		--     PVO_URL= baseURL .. "sid=36263&key=" .. API .. "&d=" .. os.date("%Y%m%d") .. "&t=" .. os.date("%H:%M")
		--     PVO_URL = PVO_URL .. "&v1=" .. (today*1000) .. "&v2=" .. now
		--     commandArray['OpenURL'] = PVO_URL
		-- end
   end
end
return commandArray

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest