Optimal LUA script to detect power usage when TV is on

Moderator: leecollings

Post Reply
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Optimal LUA script to detect power usage when TV is on

Post by BakSeeDaa »

Hi there!

Previously I have been detecting if my TV is on by pinging it. It worked, well -almost. Sometimes the TV doesn't respond to pings for several minutes. Very frustrating indeed.

Recently I bought a couple of Fibaro wall switches FGWPF-102 ZW5. They can be used as power meters, hence I can determine if the TV is on by the value of the power usage reported. The power consumption when my TV is on is about 114W but it's varying. It never goes below 50W. But there is no power threshold to set on the FGWPF-102 ZW5. It can only be set to report power usage when triggered by a minimum percentage change in active power.
wallplug.png
Working that way the FGWPF-102 ZW5 will send a quick series of power reports when i start or stop my TV. It's because the power usage raises and falls relatively slowly. My script needs to determine if the TV is "going down" or starting.

I have a virtual switch that indicates if the TV is on or off. It's named "LG 55UB820V"
The "TV Power Usage" device is electric usage device belonging to FGWPF-102 ZW5.

Below is my script. The problem is that several "devicechanged['TV Power Usage']" can occur quickly. The first time I may have issued "commandArray['LG 55UB820V'] = 'On'" but the device is still not "On" when the next "devicechanged['TV Power Usage']" happens. Now there is a gap between 10 and 90 watts where nothing will happen. It works but I feel my script is not optimal.

Code: Select all

if (devicechanged['TV Power Usage']) then
	reading = tonumber(devicechanged['TV Power Usage'])
	if ((reading <= 10) and (otherdevices['LG 55UB820V'] == 'On')) then
		commandArray['LG 55UB820V'] = 'Off'
		print('Turning off LG 55UB820V at Power Usage: ' .. reading)
	elseif ((reading >= 90) and (otherdevices['LG 55UB820V'] == 'Off')) then
		commandArray['LG 55UB820V'] = 'On'
		print('Turning on LG 55UB820V at Power Usage: ' .. reading)
	else
		print('LG 55UB820V Power Usage: ' .. reading .. ' (Doing nothing)')
	end
	return commandArray
end
Maybe someone else has a better way to do it.
pvm
Posts: 550
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: 4.10538
Location: NL
Contact:

Re: Optimal LUA script to detect power usage when TV is on

Post by pvm »

Did you try blocky checking for power usage > 10 watts?
(When your goal is only to detect it's on)
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest