convert Blocky to LUA

Moderator: leecollings

Post Reply
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

convert Blocky to LUA

Post by poudenes »

Hi Guys,

I have a long list where i change "user variable" to trigger blocky actions. But want to change 1 specific one to make it easier to read.
See attachment what its now and how can i change this into LUA
Screen Shot 2017-05-08 at 09.47.55.jpg
Screen Shot 2017-05-08 at 09.48.06.jpg
Thanks for helping and push me in right direction of learning LUA code :)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: convert Blocky to LUA

Post by freijn »

Instead of Blocky you select Lua
Please select 'userVarialbel' on the next drop down list !!!

Paste the below code and give it a try :-)

Code: Select all

commandArray = {}
if (uservariables["AllOff"] == "1") then
   
	uservariables["ComeHome"] == "0"
	uservariables["Evening"] == "0"
end
return commandArray
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: convert Blocky to LUA

Post by poudenes »

freijn wrote:Instead of Blocky you select Lua
Please select 'userVarialbel' on the next drop down list !!!

Paste the below code and give it a try :-)

Code: Select all

commandArray = {}
if (uservariables["AllOff"] == "1") then
   
	uservariables["ComeHome"] == "0"
	uservariables["Evening"] == "0"
end
return commandArray
Thanks !! i give it a shot !!
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: convert Blocky to LUA

Post by poudenes »

This is not working:

error: 2017-05-08 11:22:31.899 Error: EventSystem: in MAN SCENE ON 17.05.08 (TEST): [string "commandArray = {}..."]:3: syntax error near '=='

the other user variable must updated to 0

Code: Select all

commandArray = {}
if (uservariables["All Off"] == "1") then
    uservariables["ComeHome"] == "0"
    uservariables["Evening"] == "0"
    uservariables["Goodnight"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Morning"] == "0"
    uservariables["Movie"] == "0"
    uservariables["Sexy"] == "0"
    uservariables["TV"] == "0"
   
elseif (uservariables["ComeHome"] == "1") then
    uservariables["All Off"] == "0"
    uservariables["Evening"] == "0"
    uservariables["Goodnight"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Morning"] == "0"
    uservariables["Movie"] == "0"
    uservariables["Sexy"] == "0"
    uservariables["TV"] == "0"
   
elseif (uservariables["Evening"] == "1") then
    uservariables["All Off"] == "0"
    uservariables["ComeHome"] == "0"
    uservariables["Goodnight"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Morning"] == "0"
    uservariables["Movie"] == "0"
    uservariables["Sexy"] == "0"
    uservariables["TV"] == "0"
   
elseif (uservariables["Goodnight"] == "1") then
    uservariables["All Off"] == "0"
    uservariables["ComeHome"] == "0"
    uservariables["Evening"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Morning"] == "0"
    uservariables["Movie"] == "0"
    uservariables["Sexy"] == "0"
    uservariables["TV"] == "0"
   
elseif (uservariables["Leaving"] == "1") then
   uservariables["ComeHome"] == "0"
   uservariables["All Off"] == "0"
   uservariables["Evening"] == "0"
   uservariables["Goodnight"] == "0"
   uservariables["Morning"] == "0"
   uservariables["Movie"] == "0"
   uservariables["Sexy"] == "0"
   uservariables["TV"] == "0"
   
elseif (uservariables["Morning"] == "1") then
    uservariables["All Off"] == "0"
    uservariables["ComeHome"] == "0"
    uservariables["Evening"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Movie"] == "0"
    uservariables["Sexy"] == "0"
    uservariables["TV"] == "0"
    
elseif (uservariables["Movie"] == "1") then
    uservariables["All Off"] == "0"
    uservariables["ComeHome"] == "0"
    uservariables["Evening"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Morning"] == "0"
    uservariables["Sexy"] == "0"
    uservariables["TV"] == "0"
    
elseif (uservariables["Sexy"] == "1") then
    uservariables["All Off"] == "0"
    uservariables["ComeHome"] == "0"
    uservariables["Evening"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Morning"] == "0"
    uservariables["Movie"] == "0"
    uservariables["TV"] == "0"
    
elseif (uservariables["TV"] == "1") then
    uservariables["All Off"] == "0"
    uservariables["ComeHome"] == "0"
    uservariables["Evening"] == "0"
    uservariables["Leaving"] == "0"
    uservariables["Morning"] == "0"
    uservariables["Movie"] == "0"
    uservariables["Sexy"] == "0"

end
return commandArray
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
manjh
Posts: 749
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: convert Blocky to LUA

Post by manjh »

The error is in the "==".

You use "==" to compare, and "="to assign.
for example:

Code: Select all

if (a==b) then
	c = 1
	d = 2
	e = 3
end
Having said this, the way to assign a value to a user variable is not by simply assigning.
I use this to assign a value to variable named "TestVariable":

Code: Select all

commandArray['Variable:TestVariable"] = 3
Hans
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: convert Blocky to LUA

Post by poudenes »

manjh wrote:The error is in the "==".

You use "==" to compare, and "="to assign.
for example:

Code: Select all

if (a==b) then
	c = 1
	d = 2
	e = 3
end
Having said this, the way to assign a value to a user variable is not by simply assigning.
I use this to assign a value to variable named "TestVariable":

Code: Select all

commandArray['Variable:TestVariable"] = 3

Code: Select all

commandArray = {}
if (uservariables["All Off"] == "1") then
	commandArray['Variable:ComeHome"] = "0"
	commandArray['Variable:Evening"] = "0"
	commandArray['Variable:Goodnight"] = "0"
	commandArray['Variable:Leaving"] = "0"
	commandArray['Variable:Morning"] = "0"
	commandArray['Variable:Movie"] = "0"
	commandArray['Variable:Sexy"] = "0"
	commandArray['Variable:TV"] = "0"
   
elseif (uservariables["ComeHome"] == "1") then
    uservariables["All Off"] = "0"
    uservariables["Evening"] = "0"
    uservariables["Goodnight"] = "0"
    uservariables["Leaving"] = "0"
    uservariables["Morning"] = "0"
    uservariables["Movie"] = "0"
    uservariables["Sexy"] = "0"
    uservariables["TV"] = "0"
    end
return commandArray
Sp the first IF is the correct one to use?

And how can i given that the variable type must stay as "Integer" (type 0) something like "and uservariables type = "0" ?

commandArray['Variable:ComeHome"] = "0" and uservariables type = "0"

sorry for the dumb question... hehe
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
manjh
Posts: 749
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: convert Blocky to LUA

Post by manjh »

Depending on the definition of the variable, you can use "tonumber" or "tostring" functions.
This is the nice thing about Domoticz: simply try it and see what works.
In my server, I have defined a dummy switch called "Testbutton". When I want to test some code, I put it into a LUA script (type "device") like this:

Code: Select all

-- Test script
commandArray = {}
--if devicechanged['Testbutton']  then
    print ("@@@@@@@@ invoking tester")

    -- put the code to be tested here

    print ("@@@@@@@@ ending  tester")    
--end
return commandArray
This way I can change the code, press the test button, and see what happens.....trial-and-error, but it's fun!
Hans
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: convert Blocky to LUA

Post by freijn »

apologies yes == was 1 = to much.

quick copy and past error :-(


Thanks Manjh to assist here!
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: convert Blocky to LUA

Post by poudenes »

Grrr :( it worked. But does someone can tell me if i can use Scene/Group into a device changed? Tried it but don't work.
Have some scenes and when the scene is on, i also want update a user variable.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: convert Blocky to LUA

Post by freijn »

Please post your code , so we can understand what you are looking for?

I have found this :

commandArray['Scene:Livingroom']='On' -- remember, Scene cannot be turned Off!

The comment at the end is a little 'disturbing' :-(
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: convert Blocky to LUA

Post by poudenes »

freijn wrote:Please post your code , so we can understand what you are looking for?

I have found this :

commandArray['Scene:Livingroom']='On' -- remember, Scene cannot be turned Off!

The comment at the end is a little 'disturbing' :-(
Turn on groep All-Off then user variable must goto 1. When turn off then user variable must goto 0

Code: Select all

commandArray = {}
if (Devicechanged["Group:All-Off"] == "On") then
   commandArray['Variable:All-Off"] = "1"
   
elseif (Devicechanged["Group:All-Off"] == "Off") then
    uservariables["All Off"] = "0"

    end
return commandArray
With a switch it is working. But want remove the switch and do some actions directly on the ON/OFF from a group
Last edited by poudenes on Thursday 11 May 2017 15:51, edited 1 time in total.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: convert Blocky to LUA

Post by freijn »

Then let us know which action please? So we can try to suggest you.

The code you pasted , is from your memory or from your system? As I believe you have some errors in..
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: convert Blocky to LUA

Post by poudenes »

freijn wrote:Then let us know which action please? So we can try to suggest you.

The code you pasted , is from your memory or from your system? As I believe you have some errors in..
That is a LUA script inside Domoticz. And yes its not working. Thats why i ask if i can use a scene or group as trigger ... the IF action
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: convert Blocky to LUA

Post by freijn »

poudenes

I do not recognize the "Devicechaed" in your script.

According to my knowledge that is not a valid statement... or I am mistaken ?
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: convert Blocky to LUA

Post by poudenes »

freijn wrote:poudenes

I do not recognize the "Devicechaed" in your script.

According to my knowledge that is not a valid statement... or I am mistaken ?
sorry was a typo must be devicechanged but then its not working
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest