sleeptimer for switch to measure powerconsumption Topic is solved

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

sleeptimer for switch to measure powerconsumption

Post by pvklink »

RPI 3b
Latest beta domoticz
LUA script
Problem:
After my switch turns on, i want to check if it uses power (otherwise my device is defect)
Problem is that when i put on the device it takes 15 seconds for the powerusage is available, so i need kind of sleep function.
i get print 07c with value 0.0 en when the script is finished it does give a value with print 07a! larger timer does not help...
I tried one, it does pause but it looks like the the powerconsumption cant be read during this lua

Code: Select all

local switchlint = 'warmtelint'             -- schakelaar die bij onderschreiding temperatuur aangezet wordt
local switchverbruik = 'Verbruikwarmtelint'             -- schakelaar die bij onderschreiding temperatuur aangezet wordt
local curwatlimit = 1                       -- minimale onderwaarde temperatuur
local wacht=2000

function round2(num, numDecimalPlaces)
  return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end

commandArray = {}

    curwat = otherdevices_svalues["Verbruikwarmtelint"]
    print ('07a Stroomlintverbruik heeft waarde' .. curwat .. '/')
    curwat=0
if devicechanged[switchlint] == 'On' then

    i = 1
    while i  <= wacht do
        ping_success=os.execute('ping -c1 -w 1 192.168.20.1')
        --print ('teller:'..tostring(i)..'') 
	    i = i + 1
    end
    
    curwat = otherdevices_svalues["Verbruikwarmtelint"]
  
    if tonumber(curwat) > tonumber(curwatlimit) then            -- lint gebruikt stroom, dus werkt
        print ('07b Stroomlint werkt. Verbruikt ' .. curwat)
    else
        print ('07c Stroomlint werkt niet. Verbruikt ' .. curwat)
    end
end

return commandArray
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: sleeptimer for switch to measure powerconsumption

Post by pvklink »

I have a working script, with dzvents is was much easier!
I like to learn what i dit wrong in my LUA script above...
So if someone finds my error(s) your welcome!

Code: Select all

return {
    	active = true,
    on = {
        timer = {'every 5 minutes'}
        },

execute = function(domoticz)
    local switchlint = 'warmtelint'             -- schakelaar die bij onderschreiding temperatuur aangezet wordt
    local switchverbruik = 'Verbruikwarmtelint' -- schakelaar die bij onderschreiding temperatuur aangezet wordt
    local curwatlimit = 1                       -- minimale onderwaarde temperatuur

    curwat = tonumber(domoticz.devices('Verbruikwarmtelint').WhActual)

    if domoticz.devices('warmtelint').state == 'On' then
        if tonumber(curwat) > tonumber(curwatlimit) then            -- lint gebruikt stroom, dus werkt
            domoticz.log('xx Stroomlint werkt. Verbruikt ' .. curwat)
        else
            domoticz.log('xx Stroomlint werkt niet! en switch staat aan!' .. curwat)
        end
    end
end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest