Converting my block to dzVents

Easy to use, 100% Lua-based event scripting framework.
Post Reply
Melotron
Posts: 50
Joined: Tuesday 22 November 2016 22:04
Target OS: Raspberry Pi
Domoticz version:
Contact:

Converting my block to dzVents

Post by Melotron » Sunday 12 August 2018 12:47

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: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Converting my block to dzVents

Post by Andyf66 » Sunday 12 August 2018 13:01

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: 50
Joined: Tuesday 22 November 2016 22:04
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Converting my block to dzVents

Post by Melotron » Monday 13 August 2018 9:17

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: 1079
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Converting my block to dzVents

Post by waaren » 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 
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Melotron
Posts: 50
Joined: Tuesday 22 November 2016 22:04
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Converting my block to dzVents

Post by Melotron » Monday 13 August 2018 14:24

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 0 guests