Page 1 of 1

Operate power values

Posted: Wednesday 28 November 2018 20:50
by Sergio
I'm trying to process the values of several power devices to find the difference. Is there a way to directly get the Watts value of a power (usage) sensor without manually fiddling with separators? Like value = otherdevices['Lighting'][0].Value

What I'm trying to calculate is:

Code: Select all

    total = otherdevices['total'].Value
    lights = otherdevices['lights'].Value
    kitchen= otherdevices['kitchen'].Value
    plugs = otherdevices['plugs'].Value
    parasitic = total - lights - plugs - kitchen
    commandArray['UpdateDevice'] = idx..'|0|'..parasitic

Re: Operate power values

Posted: Wednesday 28 November 2018 21:51
by Siewert308SW
Something like this?
Use the following function for my events to see if someone is using a device or not.
But could also serve your purpose, i think.
It aint tested but should give you a headstart.
You could also include the "parasitic = total - lights - plugs - kitchen" into the function to make it cleaner

Code: Select all

	
	function powerusage(powerplug)
		local powerplug = powerplug
		local reading
		local usage
			  reading = otherdevices[powerplug] 
			_,_,usage = string.find(reading, "(.+)")

		  current_usage = tonumber(reading) 		
		  return current_usage
	end	
	
commandArray = {}

    total = powerusage['total']
    lights = powerusage['lights']
    kitchen=powerusage['kitchen']
    plugs = powerusage['plugs']
    parasitic = total - lights - plugs - kitchen
 
    commandArray['UpdateDevice']=tostring(parasitic)   
    
return commandArray	

Re: Operate power values

Posted: Wednesday 28 November 2018 22:20
by Sergio
Thanks siewert for your help. I just found in the stickies a file for custom functions that includes an array parser that serves my purpose. I'm doing tests.
Anyways, thank you.

Enviado desde mi MI 5s Plus mediante Tapatalk