Page 1 of 1
Update status without triggering
Posted: Friday 25 November 2016 20:43
by Melissen
Hi,
I want to update some status of devices without triggering them.
I can get it to work, but only 1 switch at a time.
this is a part of the script:
-- Woonkamer alles
if (devicechanged['Woonkamer -alles']=='On') then
commandArray['UpdateDevice']='64|1|1'
commandArray['UpdateDevice']='65|1|1'
-- commandArray['UpdateDevice']='66|1|1'
-- commandArray['UpdateDevice']='70|1|1'
-- commandArray['UpdateDevice']='72|1|1'
end
if (devicechanged['Woonkamer -alles']=='Off') then
commandArray['UpdateDevice']='64|0|0'
-- commandArray['UpdateDevice']='65|0|0'
-- commandArray['UpdateDevice']='66|0|0'
-- commandArray['UpdateDevice']='70|0|0'
-- commandArray['UpdateDevice']='72|0|0'
end
In this case when switching ON, only nr65 is switched to ON, nr 64 stays OFF (66,70,72 are turned off, --)
When I switch OFF, nr 64 is switched OFF. (because 65,66,70,72 are turned off, --)
When I remove all -- in the commandlines, in both On or OFF only nr 72 switches.
So my conclusion is: only the last commandline is working.
How to get all commandlines working???
Thanks,
Hein
Re: Update status without triggering
Posted: Friday 25 November 2016 20:56
by SweetPants
Melissen wrote:So my conclusion is: only the last commandline is working.
That is right.
Did you check the wiki?
https://www.domoticz.com/wiki/LUA_comma ... n_one_pass
Re: Update status without triggering
Posted: Friday 25 November 2016 21:14
by Melissen
I saw this wiki-page.. but when i try to use this in the IF-THEN it doesn't work..
Even when I remove the commandArray = {} and return commandArray in the THEN-section, it doesn't work
Script I used:
commandArray = {}
-- Woonkamer alles
if (devicechanged['Woonkamer -alles']=='On') then
commandArray = {}
local function update(idx, value1, value2)
local cmd = string.format("%d|0|%.2f;%.2f", idx, value1, value2)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
update (64, 1, 1)
update (65, 1, 1)
update (66, 1, 1)
update (70, 1, 1)
update (72, 1, 1)
return commandArray
end
return commandArray
LUA is great, but the tutorials on Google aren't that great... Not a simple explanation, but only explaining a specific problem. So when you want to use a command in a different way, you get stuck very fast,
Re: Update status without triggering
Posted: Friday 25 November 2016 21:21
by Westcott
Hi Melissen,
Are you saying that if you update a device in this way (e.g. commandArray['UpdateDevice']='64|1|1') it doesn't trigger a devicechanged['MyDeviceIdx64'] ?
Re: Update status without triggering
Posted: Friday 25 November 2016 21:30
by SweetPants
You can't have two "commandArray = {} and return commandArray" instructions.
This script works in my setup
Code: Select all
commandArray = {}
local function update(idx, value1, value2)
local cmd = string.format("%d|0|%.2f;%.2f", idx, value1, value2)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
if (devicechanged['Lamp 3']=='On') then
update (110, 11, 0)
update (111, 22, 0)
update (112, 33, 0)
end
return commandArray
Re: Update status without triggering
Posted: Friday 25 November 2016 21:36
by Melissen
Hi Westcott. Indeed. When you use that command the switch will turn ON in your dashboard. But the device itself (lamp example) will not turn on.
Re: Update status without triggering
Posted: Friday 25 November 2016 21:53
by Westcott
Wow, thanks Melissen.
So an nValue of 1 (value1 in SweetPants' example) means 'On' ?
Re: Update status without triggering
Posted: Friday 25 November 2016 22:28
by Melissen
Yeah... it works... After changing the string format to %d %d %d.....
Script is now:
commandArray = {}
local function update(idx, value1, value2)
local cmd = string.format("%d|%d|%d", idx, value1, value2)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
-- Woonkamer -alles
if (devicechanged['Woonkamer -alles']=='On') then
update(64,1,1)
update(65,1,1)
update(66,1,1)
update(70,1,1)
update(72,1,1)
end
if (devicechanged['Woonkamer -alles']=='Off') then
update(64,0,0)
update(65,0,0)
update(66,0,0)
update(70,0,0)
update(72,0,0)
end
return commandArray
Thanks everybody for helping me.... very happy with you !!!!
Hein.
Re: Update status without triggering
Posted: Friday 25 November 2016 22:30
by Melissen
Hi Westcott.... yes for a switch you should use (idx,1,1)
See my script...
Re: Update status without triggering
Posted: Friday 25 November 2016 23:01
by Melissen
Problem solved again...... and for all other switches is this a very easy script...