Thanks a lot
Blocky to Lua
Moderator: leecollings
-
theo69
- Posts: 60
- Joined: Sunday 04 June 2017 12:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version: la. beta
- Location: World
- Contact:
Blocky to Lua
Hi there I am a total n00b and just starting, now i have a blocky script i would like to translate into Lua (because I need it more often and Lua is easy to copy) Tried a lot but failed, maybe somebody can push me into the right direction
Thanks a lot
Thanks a lot
Love my Xiaomi Gateway in connection with homebridge and domoticz on my PI3
Xiaomi Gateway Domoticz Wiki
Xiaomi Gateway Domoticz Wiki
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Blocky to Lua
Code: Select all
commandArray = {}
if otherdevices['Einfachschalter'] == 'On' and otherdevices['Testschalter'] == 'Off' then
commandArray['Testschalter'] = 'On AFTER 1'
elseif otherdevices['Einfachschalter'] == 'On' and otherdevices['Testschalter'] == 'On' then
commandArray['Testschalter'] = 'Off AFTER 1'
end
return commandArrayCode: Select all
commandArray = {}
if otherdevices['Einfachschalter'] == 'On' then
if otherdevices['Testschalter'] == 'Off' then
commandArray['Testschalter'] = 'On AFTER 1'
else
commandArray['Testschalter'] = 'Off AFTER 1'
end
end
return commandArrayM
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
theo69
- Posts: 60
- Joined: Sunday 04 June 2017 12:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version: la. beta
- Location: World
- Contact:
Re: Blocky to Lua
Wow thanky a lot trying to understand but still a noob, i tried to get rid of the delay and did:emme wrote:but a smarter way would be:Code: Select all
commandArray = {} if otherdevices['Einfachschalter'] == 'On' and otherdevices['Testschalter'] == 'Off' then commandArray['Testschalter'] = 'On AFTER 1' elseif otherdevices['Einfachschalter'] == 'On' and otherdevices['Testschalter'] == 'On' then commandArray['Testschalter'] = 'Off AFTER 1' end return commandArrayciaoCode: Select all
commandArray = {} if otherdevices['Einfachschalter'] == 'On' then if otherdevices['Testschalter'] == 'Off' then commandArray['Testschalter'] = 'On AFTER 1' else commandArray['Testschalter'] = 'Off AFTER 1' end end return commandArray
M
Code: Select all
commandArray = {}
if otherdevices['Einfachschalter'] == 'On' then
if otherdevices['Testschalter'] == 'Off' then
commandArray['Einfachschalter'] = 'Off' and commandArray['Testschalter'] = 'On'
elseif otherdevices['Testschalter'] == 'On' then
commandArray['Einfachschalter'] = 'Off' and commandArray['Testschalter'] = 'Off'
end
end
return commandArrayLove my Xiaomi Gateway in connection with homebridge and domoticz on my PI3
Xiaomi Gateway Domoticz Wiki
Xiaomi Gateway Domoticz Wiki
-
GJKNL
- Posts: 41
- Joined: Monday 31 October 2016 9:33
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Blocky to Lua
Try this. But I do not understand your logic. Now you switch something off and on and then you switch both devices off again??
Code: Select all
commandArray = {}
if otherdevices['Einfachschalter'] == 'On' then
if otherdevices['Testschalter'] == 'Off' then
commandArray['Einfachschalter'] = 'Off'
commandArray['Testschalter'] = 'On'
elseif otherdevices['Testschalter'] == 'On' then
commandArray['Einfachschalter'] = 'Off''
commandArray['Testschalter'] = 'Off'
end
end
return commandArray
Last edited by GJKNL on Friday 09 June 2017 14:45, edited 1 time in total.
- jvdz
- Posts: 2445
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Blocky to Lua
This code feels flawed to me and will constantly trigger Testschalter On and Off while Einfachschalter is On... or am I seeing that wrong?emme wrote: but a smarter way would be:Code: Select all
commandArray = {} if otherdevices['Einfachschalter'] == 'On' then if otherdevices['Testschalter'] == 'Off' then commandArray['Testschalter'] = 'On AFTER 1' else commandArray['Testschalter'] = 'Off AFTER 1' end end return commandArray
Jos
Last edited by jvdz on Friday 09 June 2017 15:03, edited 1 time in total.
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Blocky to Lua
my understanding of the Blockly script is to toggle Testschalter after 1 sec when Einfaschalter is on....jvdz wrote:This code feels flawed to me and will constantly trigger Testschalter on and of while Einfachschalter is On... or am I seeing that wrong?
yes... Testschalter will flash 1sec while Einfachschalter id ON....
Wasn't this the intention?
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
- jvdz
- Posts: 2445
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Blocky to Lua
The difference with the Blockly code is that it will only act of a devicechange event and your script will trigger each time it is run by an event.
So to reflect the exact code you need to use devicechanged:
Jos
So to reflect the exact code you need to use devicechanged:
Code: Select all
commandArray = {}
if devicechanged['Einfachschalter'] == 'On' then
if otherdevices['Testschalter'] == 'Off' then
commandArray['Testschalter'] = 'On AFTER 1'
else
commandArray['Testschalter'] = 'Off AFTER 1'
end
end
return commandArray-
theo69
- Posts: 60
- Joined: Sunday 04 June 2017 12:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version: la. beta
- Location: World
- Contact:
Re: Blocky to Lua
Thanks to all, my problem is I am using a wireless Xiaomi Aqara Wall Switch, I have to set the off delay to 1 sec otherwise its not switching off again. Therefore I have to use a dummy switch to use the switch in my homekit (Apple). Maybe I went wrong with my script and thinking....
I would like to get rid of the 1 sec delay.
I would like to get rid of the 1 sec delay.
Love my Xiaomi Gateway in connection with homebridge and domoticz on my PI3
Xiaomi Gateway Domoticz Wiki
Xiaomi Gateway Domoticz Wiki
-
theo69
- Posts: 60
- Joined: Sunday 04 June 2017 12:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version: la. beta
- Location: World
- Contact:
Re: Blocky to Lua
I think I start to understand all these:
Its now working perfekt, thanks this a really a great community!!!!
Code: Select all
commandArray = {}
if devicechanged['Einfachschalter'] == 'On' then
if otherdevices['Testschalter'] == 'Off' then
commandArray['Testschalter'] = 'On'
else
commandArray['Testschalter'] = 'Off'
end
end
return commandArray
Last edited by theo69 on Saturday 10 June 2017 11:30, edited 1 time in total.
Love my Xiaomi Gateway in connection with homebridge and domoticz on my PI3
Xiaomi Gateway Domoticz Wiki
Xiaomi Gateway Domoticz Wiki
Who is online
Users browsing this forum: No registered users and 1 guest