to define a motor as a selector switch...

Moderator: leecollings

Post Reply
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

to define a motor as a selector switch...

Post 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
Untitled.jpg (49.09 KiB) Viewed 430 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: to define a motor as a selector switch...

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: to define a motor as a selector switch...

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: to define a motor as a selector switch...

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: to define a motor as a selector switch...

Post by abdolhamednik »

thanks waaren

i think i understood what u said:

1. manual light/switch
Untitled.jpg
Untitled.jpg (45.41 KiB) Viewed 404 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?
User avatar
abdolhamednik
Posts: 39
Joined: Sunday 27 September 2020 7:33
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Contact:

Re: to define a motor as a selector switch...

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: to define a motor as a selector switch...

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest