Prevent other script to run for X sec

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
Varazir
Posts: 483
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Prevent other script to run for X sec

Post by Varazir »

Hello

I have this two events and I think they work just fine by them self.
The "problem" is that the Tv has so low standby consumption that the script 1 is triggered right away and turns off the Onkyo.

I came up with a ide while I was writing this post is to create a third script that sets a variable when Samsung_Curent_Consumption.WhActual
is higher then 20.

Add that variable to the if statement in script 1

The TV switch is in general always going to be on as it ha so low stand by.

Any other ideas ?


Script 1)

Code: Select all

return {
    active = true,
	on = {
		devices = {
			'Onkyo',
			'Samsung_Curent_Consumption'
		}
	},
	execute = function(domoticz, device)
		if ((device.name == 'Onkyo' and device.state == 'On') and 
		    (device.name == 'Samsung_Curent_Consumption' and device.WhActual <= 1)) then
		    domoticz.device('Onkyo').switchOff()
		elseif ((device.name == 'Onkyo' and device.state == 'Off') and 
		    (device.name == 'Samsung_Curent_Consumption' and device.WhActual >= 2)) then
		    domoticz.device('Onkyo').switchOn()
		end
	end
}
Script 2)

Code: Select all

return {
	on = {
		devices = {
			'TV'
		}
	},
	execute = function(domoticz, device)
		if(device.staus == 'On') then
		    domoticz.device('Onkyo').switchOn()
		end
	end
}
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Prevent other script to run for X sec

Post by BakSeeDaa »

I can't say if this is relevant for your situation but below is my single script.

'LG 55UB820V' is a virtual switch device used only for indicating if the TV status (Telling me if it's turned on or not). Other scripts for illumination etc acts upon it.

The device 'TV Power Usage' is measuring and reporting the power used by TV. While turning on and while switching off the TV, the device 'TV Power Usage' typically creates a series of events . For example when turning on the TV I might create events for 5, 22, 75 and finally 120W. It's all a bit random but my scripts works fine here.

Code: Select all

local LOGGING = true

return {
	active = true,
	logging = {
		--level = domoticz.LOG_DEBUG, -- Select one of LOG_DEBUG, LOG_INFO, LOG_ERROR, LOG_FORCE to override system log level
		marker = "tvStatus"
	},
	on = {
		devices = {
			'TV Power Usage'
		},
	},
	execute = function(domoticz, device)
		local TV = domoticz.devices('LG 55UB820V')
		if TV.lastUpdate.secondsAgo > 10 then
			local reading = tonumber(device.WhActual)
			domoticz.log('LG 55UB820V Power Usage: ' .. reading, domoticz.LOG_MODULE_EXEC_DEBUG)
			if reading < 80 and TV.active then
				TV.switchOff()
				domoticz.log('Turning off LG 55UB820V at Power Usage: ' .. reading, domoticz.LOG_MODULE_EXEC_INFO)
			elseif reading > 10 and not TV.active then
				TV.switchOn()
				domoticz.log('Turning on LG 55UB820V at Power Usage: ' .. reading, domoticz.LOG_MODULE_EXEC_INFO)
			end
		end
	end
}
User avatar
Varazir
Posts: 483
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Prevent other script to run for X sec

Post by Varazir »

BakSeeDaa wrote: Monday 20 November 2017 15:20 I can't say if this is relevant for your situation but below is my single script.

TV is a virtual switch device used only for indicating if the TV status (Telling me if it's turned on or not). Other scripts for illumination etc acts upon it.

The device 'TV Power Usage' is measuring and reporting the power used by TV. While turning on and while switching off the TV, the device 'TV Power Usage' typically creates a series of events . For example when turning on the TV I might create events for 5, 22, 75 and finally 120W. It's all a bit random but my scripts works fine here.

Code: Select all

local LOGGING = true

return {
	active = true,
	logging = {
		--level = domoticz.LOG_DEBUG, -- Select one of LOG_DEBUG, LOG_INFO, LOG_ERROR, LOG_FORCE to override system log level
		marker = "tvStatus"
	},
	on = {
		devices = {
			'TV Power Usage'
		},
	},
	execute = function(domoticz, device)
		local TV = domoticz.devices('LG 55UB820V')
		if TV.lastUpdate.secondsAgo > 10 then
			local reading = tonumber(device.WhActual)
			domoticz.log('LG 55UB820V Power Usage: ' .. reading, domoticz.LOG_MODULE_EXEC_DEBUG)
			if reading < 80 and TV.active then
				TV.switchOff()
				domoticz.log('Turning off LG 55UB820V at Power Usage: ' .. reading, domoticz.LOG_MODULE_EXEC_INFO)
			elseif reading > 10 and not TV.active then
				TV.switchOn()
				domoticz.log('Turning on LG 55UB820V at Power Usage: ' .. reading, domoticz.LOG_MODULE_EXEC_INFO)
			end
		end
	end
}
Nice solution :) I didn't think of using a virtual switch, doing that for some other solutions I have.

Thanks
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest