Page 1 of 1
to define a motor as a selector switch...
Posted: Friday 15 January 2021 17:24
by abdolhamednik
hello everybody
i want to define a motor as a selector switch. so when i click on different buttons, it runs until reaches multiple positions, e.g 1st button off, 2nd btn. run for 10 sec, 3rd btn. for 20 sec, 4th for 30 sec
is it possible?
if yes, by script or here in switches tab?
thanks

- Untitled.jpg (49.09 KiB) Viewed 433 times
Re: to define a motor as a selector switch...
Posted: Friday 15 January 2021 18:03
by waaren
abdolhamednik wrote: ↑Friday 15 January 2021 17:24
i want to define a motor as a selector switch. so when i click on different buttons, it runs until reaches multiple positions, e.g 1st button off, 2nd btn. run for 10 sec, 3rd btn. for 20 sec, 4th for 30 sec
Do you mean 10 seconds On then Off, 20 seconds On then Off, etc ?
Then It can certainly be done by script.
Re: to define a motor as a selector switch...
Posted: Friday 15 January 2021 18:29
by abdolhamednik
yes. exactly
but i dont know how. i wrote this below script but it doesn't work. (lua - device) :
Code: Select all
commandArray = {}
if devicechanged['motor'] == '1/3 open' then
commandArray[#commandArray + 1] = { ['motor' ] = 'On' }
commandArray[#commandArray + 1] = { ['motor' ] = 'Off AFTER ' .. 5 }
end
if devicechanged['motor'] == '2/3 open' then
commandArray[#commandArray + 1] = { ['motor' ] = 'On' }
commandArray[#commandArray + 1] = { ['motor' ] = 'Off AFTER ' .. 10 }
end
if devicechanged['motor'] == 'total open' then
commandArray[#commandArray + 1] = { ['motor' ] = 'On' }
commandArray[#commandArray + 1] = { ['motor' ] = 'Off AFTER ' .. 15 }
end
return commandArray
Re: to define a motor as a selector switch...
Posted: Friday 15 January 2021 22:27
by waaren
abdolhamednik wrote: ↑Friday 15 January 2021 18:29
but i dont know how. i wrote this below script but it doesn't work. (lua - device) :
Your control device (selector) cannot be the same as your motor. You need to rename the selector to something like motorControl and create a new switch for your motor.
Re: to define a motor as a selector switch...
Posted: Saturday 16 January 2021 5:54
by abdolhamednik
thanks waaren
i think i understood what u said:
1. manual light/switch

- Untitled.jpg (45.41 KiB) Viewed 407 times
2. type: selector / selector switch
3. id and unit code: i don't know ??
4. add device
5. then the code below:
Code: Select all
commandArray = {}
if devicechanged['motorControl'] == 'Level1' then
commandArray[#commandArray + 1] = { ['motor' ] = 'On' }
commandArray[#commandArray + 1] = { ['motor' ] = 'Off AFTER ' .. 5 }
end
if devicechanged['motorControl'] == 'Level2' then
commandArray[#commandArray + 1] = { ['motor' ] = 'On' }
commandArray[#commandArray + 1] = { ['motor' ] = 'Off AFTER ' .. 10 }
end
if devicechanged['motorControl'] == 'Level3' then
commandArray[#commandArray + 1] = { ['motor' ] = 'On' }
commandArray[#commandArray + 1] = { ['motor' ] = 'Off AFTER ' .. 15 }
end
return commandArray
is that right?
Re: to define a motor as a selector switch...
Posted: Saturday 16 January 2021 6:53
by abdolhamednik
and now, a problem:
if user clicks level2, motor will run 10sec until window connected to it reaches for example to 40degrees
but if user first clicks level1 and then level 2, window will not reach 40 but to 60degrees!
how should the script know that?
Re: to define a motor as a selector switch...
Posted: Saturday 16 January 2021 7:06
by waaren
abdolhamednik wrote: ↑Saturday 16 January 2021 6:53
if user clicks level2, motor will run 10sec until window connected to it reaches for example to 40degrees
but if user first clicks level1 and then level 2, window will not reach 40 but to 60degrees!
The click on level 2 will cancel the schedule action caused by the click on level 1. Only the last scheduled action will be executed, they will not be added together.
But do yourself a favor and create some virtual devices to play with before implementing this on production. It will help you understand how domoticz reacts and save you some frustration.
If you can't solve it yourself with Lua, have a look at the dzVents framework. It is also Lua but, once used to the specific style, it will make you coding life a lot easier.