Easy to use, 100% Lua-based event scripting framework.
Moderator: leecollings
Varazir
Posts: 378 Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:
Post
by Varazir » Saturday 29 June 2019 10:57
Hello,
I created this test script to dim a light bulb, but it loops to quick.
IKEA Switch Brightness Down is a selector switch device so it has 4 states, Off, Click, Hold, Release
Code: Select all
return {
on = {
devices = {
'IKEA Switch Brightness Down'
}
},
execute = function(domoticz, device)
local dimDevice = domoticz.devices(73)
local dimLevel = 100
if ( device.state == "Hold" )
then
repeat
dimLevel = dimLevel - 5
domoticz.log('Device ' .. dimLevel .. ' %', domoticz.LOG_INFO)
dimDevice.dimTo(dimLevel)
until ( device.state == "Release" or dimLevel < 5 )
end
if ( device.state == "Release" )
then
if (dimLevel == 0 )
then
dimDevice.switchOff()
end
domoticz.log('Device ' .. device.name .. ' Release', domoticz.LOG_INFO)
end
end
}
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
poudenes
Posts: 667 Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:
Post
by poudenes » Saturday 29 June 2019 11:17
You can't use this line?:
Will dim device 73 to 50%
Code: Select all
return {
on = {
devices = {
'IKEA Switch Brightness Down'
}
},
execute = function(domoticz, device)
if ( device.state == "Hold" ) then
domoticz.devices(73).dimTo(5)
elseif ( device.state == "Release" ) then
domoticz.devices(73).switchOff()
end
domoticz.log('Device ' .. device.name .. ' Release', domoticz.LOG_INFO)
end
end
}
RPi3 B+ , Debain Stretch , Domoticz , Homebridge , Dashticz , RFLink , Milight , Z-Wave, Fibaro , Nanoleaf , Nest , Harmony Hub , Now try to understand pass2php
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Saturday 29 June 2019 11:35
Varazir wrote: ↑ Saturday 29 June 2019 10:57
I created this test script to dim a light bulb, but it loops to quick.
As dzVents does not change the devices by itself but hands over that action to domoticz after the script has finished you cannot use the new state of a device inside a dzVents script that changed that state. The state simply had not changed yet. Same is true for classic domoticz Lua and Blockly
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
Varazir
Posts: 378 Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:
Post
by Varazir » Sunday 30 June 2019 11:17
waaren wrote: ↑ Saturday 29 June 2019 11:35
Varazir wrote: ↑ Saturday 29 June 2019 10:57
I created this test script to dim a light bulb, but it loops to quick.
As dzVents does not change the devices by itself but hands over that action to domoticz after the script has finished you cannot use the new state of a device inside a dzVents script that changed that state. The state simply had not changed yet. Same is true for classic domoticz Lua and Blockly
Okay, I have goten this far now and the diming works but I cant get it to stop
Code: Select all
return {
on = {
devices = { 'IKEA Switch Brightness Down' },
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "IKEADown"
},
data = {
buttonState = { initial },
},
execute = function(domoticz, device)
function sleep(s)
local ntime = os.clock() + s
repeat until os.clock() > ntime
end
local dimDevice = domoticz.devices(73)
local dimLevel = 100
if ( device.state == "Hold" )
then
repeat
dimLevel = dimLevel - 5
domoticz.log('Device ' .. dimLevel .. ' %', domoticz.LOG_INFO)
domoticz.log('Hold Button State ' .. domoticz.data.buttonState .. ' ', domoticz.LOG_INFO)
dimDevice.dimTo(dimLevel)
sleep(1)
until ( domoticz.data.buttonState == "Release" or dimLevel < 5 )
end
if ( device.state == "Release" )
then
domoticz.data.buttonState = "Release"
if (dimLevel == 0 )
then
dimDevice.switchOff()
end
domoticz.log('Release Button State ' .. domoticz.data.buttonState .. ' ', domoticz.LOG_INFO)
domoticz.log('Device ' .. device.name .. ' Release', domoticz.LOG_INFO)
end
end
}
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
waaren
Posts: 6028 Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:
Post
by waaren » Sunday 30 June 2019 13:17
Varazir wrote: ↑ Sunday 30 June 2019 11:17
Okay, I have goten this far now and the diming works but I cant get it to stop
Please have a look at this.
Code: Select all
return
{
on =
{
devices = { 'IKEA Switch Brightness Down' },
},
logging =
{
level = domoticz.LOG_INFO,
marker = "IKEADown"
},
execute = function(domoticz, device)
local dimDevice = domoticz.devices(73)
local dimLevel = 100
local delay = 0
if device.state == "Hold" then
repeat
delay = delay + 0.15
dimLevel = dimLevel - 1
domoticz.log('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%, after ' .. delay .. ' seconds', domoticz.LOG_INFO)
dimDevice.dimTo(dimLevel).afterSec(delay)
until dimLevel <= 0
elseif device.state == "Release" then
domoticz.log('Stop dimming of ' .. dimDevice.name, domoticz.LOG_INFO)
dimDevice.cancelQueuedCommands()
if dimDevice.level == 0 then
dimDevice.switchOff()
end
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>>
dzVents wiki
Varazir
Posts: 378 Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:
Post
by Varazir » Sunday 30 June 2019 20:01
waaren wrote: ↑ Sunday 30 June 2019 13:17
Varazir wrote: ↑ Sunday 30 June 2019 11:17
Okay, I have goten this far now and the diming works but I cant get it to stop
Please have a look at this.
Code: Select all
return
{
on =
{
devices = { 'IKEA Switch Brightness Down' },
},
logging =
{
level = domoticz.LOG_INFO,
marker = "IKEADown"
},
execute = function(domoticz, device)
local dimDevice = domoticz.devices(73)
local dimLevel = 100
local delay = 0
if device.state == "Hold" then
repeat
delay = delay + 0.15
dimLevel = dimLevel - 1
domoticz.log('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%, after ' .. delay .. ' seconds', domoticz.LOG_INFO)
dimDevice.dimTo(dimLevel).afterSec(delay)
until dimLevel <= 0
elseif device.state == "Release" then
domoticz.log('Stop dimming of ' .. dimDevice.name, domoticz.LOG_INFO)
dimDevice.cancelQueuedCommands()
if dimDevice.level == 0 then
dimDevice.switchOff()
end
end
end
}
Thanks, it worked.
Then to the next step to make it dynamic.
But that is another thread
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
Diplo95
Posts: 15 Joined: Friday 26 July 2019 10:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Melun France
Contact:
Post
by Diplo95 » Monday 15 February 2021 19:47
Hello,
I join the thread because I try to find a way to dim a light with my Xiaomi Round 1 button switch.
Just to be sure, this script dim the light once the button is released ?
Varazir : have you found a way to dim the light when pushing the switch ?
Domoticz v2021.1 on Raspberry Pi 3B+
Raspbian Buster
ConBee II + Xiaomi devices
Zwave
Users browsing this forum: No registered users and 1 guest