Converting my block to dzVents

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

Moderator: leecollings

Post Reply
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Converting my block to dzVents

Post by Melotron »

Hiya.

I am trying to convert a blocky to dzVents.
How do I set the in between value of the Lux ??

Code: Select all

return {
    on = {
        devices = {
            'Lux'
        }
    },
        if (domoticz.devices.Lux ( >= 3701 ) then
	       print("Lux is > 3701")
        end

        if (domoticz.devices.Lux ( >= 401 and <= 3700 ) then
		    print("Lux is > 401 and < 3700")
        end

        if (domoticz.devices.Lux ( = 0 and <= 400 ) then
		   print("Lux is > 0 and < 400")
		end

end

}
I want it to set a few virtual switches after how light/dark it is.
I am only having the print command to see if it changes.

Code: Select all

2018-08-12 12:46:00.818 Status: dzVents: Error (2.4.6): error loading module 'MI Day' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/MI Day.lua':
2018-08-12 12:46:00.818 ...pi/domoticz/scripts/dzVents/generated_scripts/MI Day.lua:7: unexpected symbol near 'if'
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Converting my block to dzVents

Post by Andyf66 »

Your syntax is a bit off. Try something like this

Code: Select all

return {
	on = {
		devices = {
			'Lux'
		}
	},
	execute = function(domoticz, device)

        if (device.Lux >= 3701 ) then
	       print("Lux is > 3701")
        end

        if ((device.Lux >= 401) and (device.Lux <= 3700 )) then
		    print("Lux is > 401 and < 3700")
        end

        if ((device.Lux >= 0) and (device.Lux <= 400)) then
		   print("Lux is > 0 and < 400")
	end

	end
}
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Converting my block to dzVents

Post by Melotron »

Andyf66 wrote: Sunday 12 August 2018 13:01 Your syntax is a bit off. Try something like this
Thanks alot.
But now I need to learn how to handle values in dzvents.
Sat a few hours googling yesterday on the error and trying to figure out how it works.
I'm still lost

Code: Select all

Status: dzVents: Info: ------ Finished MI Day
Status: dzVents: Info: Handling events for: "Lux", value: "20266.6666667"
Status: dzVents: Info: ------ Start internal script: MI Day: Device: "Lux (Virtual_Switches)", Index: 130
Status: dzVents: Error (2.4.6): An error occured when calling event handler MI Day
Status: dzVents: Error (2.4.6): ...pi/domoticz/scripts/dzVents/generated_scripts/MI Day.lua:9: attempt to compare number with table
Status: dzVents: Info: ------ Finished MI Day

Code: Select all

return {
	on = {
		devices = {
			'Lux'
		}
	},
	execute = function(domoticz, device)
        if (domoticz.devices('Lux') >= 3701 ) then
        print("Lux is > 3701")
        end
end
}
I've even made the script as simple as possible.
The Lux are 20k+ so it should work.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Converting my block to dzVents

Post by waaren »

Melotron wrote: Monday 13 August 2018 9:17 Status: dzVents: Error (2.4.6): ...pi/domoticz/scripts/dzVents/generated_scripts/MI Day.lua:9: attempt to compare number with table
Status: dzVents: Info: ------ Finished MI Day[/code]
You are trying to evaluate the table containing all attributes of your lux device. You should only evaluate the lux value.

Change

Code: Select all

if (domoticz.devices('Lux') >= 3701 ) then
to

Code: Select all

if (domoticz.devices('Lux').lux >= 3701 ) then 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Melotron
Posts: 62
Joined: Tuesday 22 November 2016 21:04
Target OS: Linux
Domoticz version: 2020.2
Location: Gothenburg
Contact:

Re: Converting my block to dzVents

Post by Melotron »

waaren wrote: Monday 13 August 2018 9:28
Melotron wrote: Monday 13 August 2018 9:17 Status: dzVents: Error (2.4.6): ...pi/domoticz/scripts/dzVents/generated_scripts/MI Day.lua:9: attempt to compare number with table
Status: dzVents: Info: ------ Finished MI Day[/code]
You are trying to evaluate the table containing all attributes of your lux device. You should only evaluate the lux value.

Change

Code: Select all

if (domoticz.devices('Lux') >= 3701 ) then
to

Code: Select all

if (domoticz.devices('Lux').lux >= 3701 ) then 
Thank you so much its working perfectly now =))
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest