Help needed with LUX script

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

Moderator: leecollings

Post Reply
Boredcat
Posts: 38
Joined: Friday 17 March 2017 9:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Netherlands
Contact:

Help needed with LUX script

Post by Boredcat »

I am trying to create my first DzVents script. It should turn on the lights when the LUX is below 21. A very simple script. But it doesn't work..

Below is the error and script.
It looks likes the if then statement is comparing a number with a string. But according to the documentation the Device.lux is a number and not a string.

Appreciate any help.

<br/>
2017-09-28 08:18:00.322 dzVents: Info: ------ Start internal script: Lux_Meter:, trigger: every 1 minutes<br/>
2017-09-28 08:18:00.347 dzVents: Info: 3.62<br/>
2017-09-28 08:18:00.348 dzVents: Info: On<br/>
2017-09-28 08:18:00.348 Error: dzVents: Error: An error occured when calling event handler Lux_Meter<br/>
2017-09-28 08:18:00.348 Error: dzVents: Error: ...m Files (x86)\Domoticz\scripts\dzVents\runtime/Utils.lua:61: attempt to compare string with number<br/>
2017-09-28 08:18:00.348 dzVents: Info: ------ Finished Lux_Meter<br/>
2017-09-28 08:18:00.349 EventSystem: Script event triggered: y:\Program Files (x86)\Domoticz\scripts\dzVents\runtime\dzVents.lua</r>

Code: Select all

</s>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 = {
	

		timer = {
			-- timer triggers.. if one matches with the current time then the script is executed
		
			'every 1 minutes'
		}
	},

	-- actual event code
	-- in case of a timer event or security event, device == nil
	execute = function(domoticz, device)
     
		local myDevice1 = domoticz.devices('LUX Meter')
		local myDevice2 = domoticz.devices('ALLES AAN REMOTE')
        domoticz.log(myDevice1.lux)
        domoticz.log(myDevice2.state)
		if (myDevice1.lux < 21 ) then
			myDevice2.switchOn()
			domoticz.log('Light info', 'The light ' .. myDevice2.name .. ' will be switched on due to LUX')
		end
	end
}
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Help needed with LUX script

Post by DewGew »

Trigger line seems to be wrong:

Code: Select all

timer = {
	'every minute'
		}
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Help needed with LUX script

Post by DewGew »

I rewrite your script. my suggest:

Code: Select all

return {

	active = true,
	
	on = {
	

		timer = {
			'every minute'
		}
	},

	execute = function(domoticz)
     
		local myDevice1 = domoticz.devices('LUX Meter')
		local myDevice2 = domoticz.devices('ALLES AAN REMOTE')
        domoticz.log(myDevice1.lux)
        domoticz.log(myDevice2.state)
		if (myDevice1.lux <= 21 ) then
			myDevice2.switchOn()
			domoticz.log('Light info', 'The light ' .. myDevice2.name .. ' will be switched on due to LUX')
		else 
			myDevice2.switchOff()
		end
	end
}
//Pierre
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
Boredcat
Posts: 38
Joined: Friday 17 March 2017 9:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Help needed with LUX script

Post by Boredcat »

@DewGew Thnx, Adjusted the script as suggested. No luck same error on string vs number compare

Code: Select all

attempt to compare string with number
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Help needed with LUX script

Post by DewGew »

This might work better:

Code: Select all

return {

	active = true,
	
	on = {
		timer = {
			'every minute'
		}
	},

	execute = function(domoticz)
     
		local myDevice1 = domoticz.devices('LUX Meter')
		local myDevice2 = domoticz.devices('ALLES AAN REMOTE')
                local LUX = myDevice1.lux
        domoticz.log(myDevice1.name .. ' ' .. LUX, domoticz.LOG_INFO)
        domoticz.log(myDevice2.name .. ' ' .. myDevice2.state, domoticz.LOG_INFO)
		if (LUX <= 21 ) then
			myDevice2.switchOn()
			domoticz.log('Light info, The light ' .. myDevice2.name .. ' will be switched on due to LUX', domoticz.LOG_INFO)
		else 
			myDevice2.switchOff()
		end
	end
}
Last edited by DewGew on Thursday 28 September 2017 12:08, edited 2 times in total.
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Help needed with LUX script

Post by EdwinK »

Thanks, was looking to make something like this.

But, now I get this error:

Code: Select all

2017-09-28 12:01:00.636 Error: dzVents: Error: An error occured when calling event handler Low Lux
2017-09-28 12:01:00.636 Error: dzVents: Error: /usr/local/domoticz/var/scripts/dzVents/runtime/Utils.lua:61: attempt to compare string with number
edit: since updating to script in post above this one, it works without errors.
Last edited by EdwinK on Thursday 28 September 2017 12:33, edited 1 time in total.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: Help needed with LUX script

Post by DewGew »

Boredcat wrote: Thursday 28 September 2017 8:30
2017-09-28 08:18:00.322 dzVents: Info: ------ Start internal script: Lux_Meter:, trigger: every 1 minutes
2017-09-28 08:18:00.347 dzVents: Info: 3.62
2017-09-28 08:18:00.348 dzVents: Info: On
2017-09-28 08:18:00.348 Error: dzVents: Error: An error occured when calling event handler Lux_Meter
2017-09-28 08:18:00.348 Error: dzVents: Error: ...m Files (x86)\Domoticz\scripts\dzVents\runtime/Utils.lua:61: attempt to compare string with number
2017-09-28 08:18:00.348 dzVents: Info: ------ Finished Lux_Meter
2017-09-28 08:18:00.349 EventSystem: Script event triggered: y:\Program Files (x86)\Domoticz\scripts\dzVents\runtime\dzVents.lua

Is your lux meter showing with decimals?
Mine always shows without decimals. Are you running beta version? if you do look at this thread viewtopic.php?f=59&t=19581
// Pierre
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
Boredcat
Posts: 38
Joined: Friday 17 March 2017 9:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Help needed with LUX script

Post by Boredcat »

The LUX meter is an BH1750 connected to a Wemos D1 (with ESPEASY) and configured to give the Lux value to domoticz with 2 decimals. I will change ESPEASY to just give the number to Domoticz and use your script (I already used a script like that, I think the decimals are causing the issue).

It works, even with the extra decimals.. Great so adding the extra variable did the job.

Thanks for all your help. Now expanding the script with some more checks.
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Help needed with LUX script

Post by felix63 »

I was just wondering, why do you use a time trigger? Why not trigger on lux device?
Boredcat
Posts: 38
Joined: Friday 17 March 2017 9:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Help needed with LUX script

Post by Boredcat »

Hmm trigger on the LUX device. Nice idea.. doing almost the same then since my LUX sensor is updated every 60 seconds. But when the LUX value is the same as the last LUX I could have lesser events.

Not sure if the timer should be every minute (did is just for testing), using it to switch on the lights in the living room so the interval can be 5 minutes.
I like you idea of the LUX trigger, going to test that also.

As already said these are my first (baby)-steps into Domoticz scripting (I used to use blocky)
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Help needed with LUX script

Post by EdwinK »

I've been using the script for a few months, but after reinstalling some scripts, it doesn't work anymore :(

Code: Select all

return {

	active = true,
	
	on = {
		timer = {
			'every minute'
		}
	},

	execute = function(domoticz)
     
		local myDevice1 = domoticz.devices('Lux')
		local myDevice2 = domoticz.devices('Berging')
                local LUX = myDevice1.lux
        domoticz.log(myDevice1.name .. ' ' .. LUX, domoticz.LOG_INFO)
        domoticz.log(myDevice2.name .. ' ' .. myDevice2.state, domoticz.LOG_INFO)
		if (LUX <= 750 ) then
			myDevice2.switchOn()
			domoticz.log('Light info, The light ' .. myDevice2.name .. ' will be switched on due to LUX', domoticz.LOG_INFO)
		else 
			myDevice2.switchOff()
		end
	end
}
2017-11-24 15:59:45.244 Error: EventSystem: Lua script Low Lux did not return a commandArray
I copied and pasted it again from the post a couple posts above me. So, I am at a lost what went wrong.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Help needed with LUX script

Post by EdwinK »

When I add return commandArray a little 'x' is shown in the internal editor, so that is also wrong.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Help needed with LUX script

Post by EdwinK »

Aaarrghh.. /me feels stupid now. I was running this now as a LUA script instead of dzVents... :facepalm:
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest