first script to control lamps when im watching TV

Post Reply
markjgabb
Posts: 127
Joined: Wednesday 25 January 2017 0:00
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Australia
Contact:

first script to control lamps when im watching TV

Post by markjgabb » Saturday 05 August 2017 10:05

Hi guys
this is my first script to control a set of milights in my lounge room when diffrent actions occur on the TV

i get an error about expected actions on line 35

im really no programer at all.....
anyone alble to just highlight what i need to change?
any improvement suggestions are appriciated

Code: Select all

-- Check the wiki at
-- http://www.domoticz.com/wiki/%27dzVents%27:_next_generation_LUA_scripting
return {

	-- 'active' controls if this entire script is considered or not
	active = true, -- set to false to disable this script

	-- trigger
	-- can be a combination:
	on = {
		devices = {
			-- scripts is executed if the device that was updated matches with one of these triggers
			'Lounge Kodi', -- kodi media centre in Lounge
			},
		timer = {
		    'at nighttime',
		    },
	},

	-- actual event code
	-- in case of a timer event or security event, device == nil
	execute = function(domoticz, device)
		--[[

		The domoticz object holds all information about your Domoticz system. E.g.:

		local myDevice = domoticz.devices('myDevice')
		local myVariable = domoticz.variables('myUserVariable')
		local myGroup = domoticz.groups('myGroup')
		local myScene = domoticz.sceneds('myScene')

		The device object is the device that was triggered due to the device in the 'on' section above.
		]] --
		-- example
		if ('Lounge Kodi'.state == 'Video') then
			domoticz.setScene('TV Playing', 'On')
			domoticz.notify('Lounge kodi', 'mood lights on')
		elseif ('Lounge Kodi'.state == 'Paused') or (device.state == 'on') then
		    domoticz.setScene('Lounge Normal Lights', 'On')
		    domoticz.notify('Lounge kodi', 'mood lights on')
		end
	end
},
V 3.8153 RPI 3
RFlink 334 mhz
mysensors
broadlink
wemo

User avatar
BakSeeDaa
Posts: 517
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: first script to control lamps when im watching TV

Post by BakSeeDaa » Saturday 05 August 2017 10:35

Hi.

Try changing

Code: Select all

'Lounge Kodi'.state
to

Code: Select all

device.state
Remove the comma sign at the end of the code.

Remove the timer trigger, you probably do not want it. However you might want to limit the script to do anything in daytime?
Then You can put a time rule constraint on the device trigger. That is, change

Code: Select all

'Lounge Kodi', -- kodi media centre in Lounge
into

Code: Select all

['Lounge Kodi'] = 'at nighttime', -- kodi media centre in Lounge
Best wishes

// บักสีดา

markjgabb
Posts: 127
Joined: Wednesday 25 January 2017 0:00
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Australia
Contact:

Re: first script to control lamps when im watching TV

Post by markjgabb » Saturday 05 August 2017 10:56

yeah that was my plan....i or wil lthat make it go very minute during nighttime?


im now getting the following
dzVents: Error: An error occured when calling event handler Lights on TV Actions
2017-08-05 18:55:00.081 Error: dzVents: Error: ...ripts/dzVents/generated_scripts/Lights on TV Actions.lua:35: attempt to index local 'device' (a nil value)
V 3.8153 RPI 3
RFlink 334 mhz
mysensors
broadlink
wemo

markjgabb
Posts: 127
Joined: Wednesday 25 January 2017 0:00
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Australia
Contact:

Re: first script to control lamps when im watching TV

Post by markjgabb » Saturday 05 August 2017 11:20

thanks heaps...removing the timer part has stopped the error....i think if i can get a few more scripts running with help i should be able to wrap my head around this... i love the idea of event only evaluating on speciifc predefined actions...that part of this is brilliant...then on top of that having and if statement ability should be great
V 3.8153 RPI 3
RFlink 334 mhz
mysensors
broadlink
wemo

markjgabb
Posts: 127
Joined: Wednesday 25 January 2017 0:00
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Australia
Contact:

Re: first script to control lamps when im watching TV

Post by markjgabb » Saturday 05 August 2017 11:54

is this a valid statement

elseif domoticz.time.isNightTime and ((device.state == 'Paused') or (device.state == 'on')) then

so i would like it run on if its night time and one of those two is true....?
V 3.8153 RPI 3
RFlink 334 mhz
mysensors
broadlink
wemo

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest