Operate power values

Moderator: leecollings

Post Reply
Sergio
Posts: 39
Joined: Friday 12 December 2014 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Operate power values

Post 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
User avatar
Siewert308SW
Posts: 290
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Operate power values

Post 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	
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
Sergio
Posts: 39
Joined: Friday 12 December 2014 13:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Operate power values

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest