Page 1 of 1
Set dim level on power on
Posted: Friday 10 July 2020 23:00
by Draakje
Hi all,
I want to set a specific dim level at a specific time period.
Somehow the device is not acting on the setting.
this is my script
Code: Select all
return {
on = {
devices = {
'Dimmer 1'
}
},
execute = function(domoticz, device)
local dimmer = domoticz.devices('Dimmer 1')
local PreviousState = domoticz.variables('Dimmer_1').value
if ((dimmer.state == 'On') and (PreviousState) == ('Off')) then
domoticz.variables('Dimmer_1').set('On')
function timebetween(s,e)
timenow = os.date("*t")
year = timenow.year
month = timenow.month
day = timenow.day
s = s .. ":00" -- add seconds in case only hh:mm is supplied
e = e .. ":00"
shour = string.sub(s, 1, 2)
sminutes = string.sub(s, 4, 5)
sseconds = string.sub(s, 7, 8)
ehour = string.sub(e, 1, 2)
eminutes = string.sub(e, 4, 5)
eseconds = string.sub(e, 7, 8)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=shour, min=sminutes, sec=sseconds}
t3 = os.time{year=year, month=month, day=day, hour=ehour, min=eminutes, sec=eseconds}
sdifference = os.difftime (t1, t2)
edifference = os.difftime (t1, t3)
isbetween = false
if sdifference >= 0 and edifference <= 0 then
isbetween = true
end
return isbetween
end
if timebetween("21:30:01","23:59:59") or timebetween("00:00:00","05:50:00") then
dimmer.switchSelector(70)
end
elseif ((dimmer.state == 'Off') and (PreviousState) ~= ('Off')) then
domoticz.variables('Dimmer_1').set('Off')
end
end
}
When I manually set the level (in domoticz) it does work.
Any pointers?
regards,
Re: Set dim level on power on
Posted: Friday 10 July 2020 23:24
by waaren
Draakje wrote: Friday 10 July 2020 23:00
I want to set a specific dim level at a specific time period.
Any pointers?
Can you check this?
Code: Select all
return
{
on =
{
devices =
{
'Dimmer 1',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dimmer',
},
execute = function(dz, item)
if item.state ~= 'Off' and dz.time.matchesRule('at 21:30-05:50') then
item.dimTo(70).silent()
end
end
}
Re: Set dim level on power on
Posted: Saturday 11 July 2020 9:14
by Draakje
waaren wrote: Friday 10 July 2020 23:24
Draakje wrote: Friday 10 July 2020 23:00
I want to set a specific dim level at a specific time period.
Any pointers?
Can you check this?
Code: Select all
return
{
on =
{
devices =
{
'Dimmer 1',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dimmer',
},
execute = function(dz, item)
if item.state ~= 'Off' and dz.time.matchesRule('at 21:30-05:50') then
item.dimTo(70).silent()
end
end
}
Hmm, yes this simplifies my script
one problem

when I change the dim value (manually on switch) is is automatically set back to the value in this script. This is something I want to avoid.
Re: Set dim level on power on
Posted: Saturday 11 July 2020 11:22
by waaren
Draakje wrote: Saturday 11 July 2020 9:14
Hmm, yes this simplifies my script
one problem

when I change the dim value (manually on switch) is is automatically set back to the value in this script. This is something I want to avoid.
Can you check this modified script?
Code: Select all
return
{
on =
{
devices =
{
'Dimmer 1',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dimmer',
},
execute = function(dz, item)
if item.sValue == 'On' and dz.time.matchesRule('at 21:30-05:50') then
item.dimTo(70).silent()
end
end
}
Re: Set dim level on power on
Posted: Saturday 11 July 2020 11:26
by Draakje
waaren wrote: Saturday 11 July 2020 11:22
Draakje wrote: Saturday 11 July 2020 9:14
Hmm, yes this simplifies my script
one problem

when I change the dim value (manually on switch) is is automatically set back to the value in this script. This is something I want to avoid.
Can you check this modified script?
Code: Select all
return
{
on =
{
devices =
{
'Dimmer 1',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dimmer',
},
execute = function(dz, item)
if item.sValue == 'On' and dz.time.matchesRule('at 21:30-05:50') then
item.dimTo(70).silent()
end
end
}
Same results.
This was the reason I worked with a variable.

Re: Set dim level on power on
Posted: Saturday 11 July 2020 11:38
by waaren
Draakje wrote: Saturday 11 July 2020 11:26
Same results.
This was the reason I worked with a variable.
If I test this script on my system (build 12202) it works as you described in your requirement.
What is the domoiticz hardware module, type and subtype of this device? and what do you see in the log if you test the script below? (added some loglines)
Code: Select all
return
{
on =
{
devices =
{
'Dimmer 1',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dimmer',
},
execute = function(dz, item)
if item.sValue == 'On' and dz.time.matchesRule('at 21:30-05:50') then
item.dimTo(70).silent()
dz.log('dimmed to 70', dz.LOG_DEBUG)
end
dz.log('state: ' .. item.state, dz.LOG_DEBUG)
dz.log('level: ' .. item.level, dz.LOG_DEBUG)
dz.log('lastLevel: ' .. item.lastLevel, dz.LOG_DEBUG)
dz.log('sValue: ' .. item.sValue, dz.LOG_DEBUG)
end
}
Re: Set dim level on power on
Posted: Saturday 11 July 2020 11:43
by Draakje
This is what I see in the log (I have tried setting the dimmer higher with the hardware buttons)
Code: Select all
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.255 Status: dzVents: Info: Handling events for: "Dimmer 1", value: "On"
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.256 Status: dzVents: Info: dimmer: ------ Start internal script: test: Device: "Dimmer 1 (Virtual)", Index: 180
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.257 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.258 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70 NOTRIGGER
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.259 Status: dzVents: Debug: dimmer: dimmed to 70
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.260 Status: dzVents: Debug: dimmer: state: On
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.261 Status: dzVents: Debug: dimmer: level: 40
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.261 Status: dzVents: Debug: dimmer: lastLevel: 40
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.261 Status: dzVents: Debug: dimmer: sValue: On
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.261 Status: dzVents: Info: dimmer: ------ Finished test
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.263 Status: EventSystem: Script event triggered: /home/domoticz/domoticz/dzVents/runtime/dzVents.lua
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.971 Status: dzVents: Info: Handling events for: "Dimmer 1", value: "On"
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.971 Status: dzVents: Info: dimmer: ------ Start internal script: test: Device: "Dimmer 1 (Virtual)", Index: 180
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.971 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.971 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70 NOTRIGGER
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.972 Status: dzVents: Debug: dimmer: dimmed to 70
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.972 Status: dzVents: Debug: dimmer: state: On
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.972 Status: dzVents: Debug: dimmer: level: 38
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.972 Status: dzVents: Debug: dimmer: lastLevel: 70
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.972 Status: dzVents: Debug: dimmer: sValue: On
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.972 Status: dzVents: Info: dimmer: ------ Finished test
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.973 Status: EventSystem: Script event triggered: /home/domoticz/domoticz/dzVents/runtime/dzVents.lua
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.256 Status: dzVents: Info: Handling events for: "Dimmer 1", value: "On"
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.256 Status: dzVents: Info: dimmer: ------ Start internal script: test: Device: "Dimmer 1 (Virtual)", Index: 180
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.256 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70 NOTRIGGER
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Debug: dimmer: dimmed to 70
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Debug: dimmer: state: On
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Debug: dimmer: level: 38
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Debug: dimmer: lastLevel: 70
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Debug: dimmer: sValue: On
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Info: dimmer: ------ Finished test
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.259 Status: EventSystem: Script event triggered: /home/domoticz/domoticz/dzVents/runtime/dzVents.lua
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.353 Status: dzVents: Info: Handling events for: "Dimmer 1", value: "On"
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.353 Status: dzVents: Info: dimmer: ------ Start internal script: test: Device: "Dimmer 1 (Virtual)", Index: 180
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.353 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Debug: dimmer: Constructed timed-command: Set Level 70 NOTRIGGER
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Debug: dimmer: dimmed to 70
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Debug: dimmer: state: On
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Debug: dimmer: level: 38
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Debug: dimmer: lastLevel: 70
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Debug: dimmer: sValue: On
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Info: dimmer: ------ Finished test
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.356 Status: EventSystem: Script event triggered: /home/domoticz/domoticz/dzVents/runtime/dzVents.lua
I am using a WF-DS01 dimmer (Tuya) running Tasmota v8.3.1
I did manage to get it to work with a variable like this
Code: Select all
return
{
on =
{
devices =
{
'Dimmer 1',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dimmer',
},
execute = function(dz, item)
local PreviousState = dz.variables('Dimmer_1').value
if item.sValue == 'On' and dz.time.matchesRule('at 11:00-12:50') and (PreviousState) == 'Off' then
dz.variables('Dimmer_1').set('On')
item.dimTo(70).silent()
elseif item.sValue == 'Off' and (PreviousState) ~= 'Off' then
dz.variables('Dimmer_1').set('Off')
end
end
}
(Don't mind the timeframe. Just changed it for test purposes )
Re: Set dim level on power on
Posted: Saturday 11 July 2020 11:54
by waaren
Draakje wrote: Saturday 11 July 2020 11:43
This is what I see in the log (I have tried setting the dimmer higher with the hardware buttons)
Code: Select all
Jul 11 11:40:40 domoticz domoticz[17336]: 2020-07-11 11:40:40.261 Status: dzVents: Debug: dimmer: sValue: On
Jul 11 11:40:44 domoticz domoticz[17336]: 2020-07-11 11:40:44.972 Status: dzVents: Debug: dimmer: sValue: On
Jul 11 11:40:46 domoticz domoticz[17336]: 2020-07-11 11:40:46.257 Status: dzVents: Debug: dimmer: sValue: On
Jul 11 11:40:47 domoticz domoticz[17336]: 2020-07-11 11:40:47.354 Status: dzVents: Debug: dimmer: sValue: On
I am using a WF-DS01 dimmer (Tuya) running Tasmota v8.3.1
OK. Seems your version or your device is reacting different then the ones I use. When I use a virtual dimmer on build 12202 it sets sValue to 'Set Level xx%' when controlled by the dim slider. When I switch it On the sValue is set to 'On' and when I switched it Off the sValue is set to 'Off'.
Code: Select all
2020-07-11 11:20:03.406 Status: dzVents: Debug: dimmer: sValue: Off
2020-07-11 11:20:05.183 Status: dzVents: Debug: dimmer: sValue: Set Level: 18 %
2020-07-11 11:20:10.520 Status: dzVents: Debug: dimmer: sValue: Set Level: 44 %
2020-07-11 11:20:11.642 Status: dzVents: Debug: dimmer: sValue: Set Level: 57 %
2020-07-11 11:20:24.762 Status: dzVents: Debug: dimmer: sValue: Off
2020-07-11 11:20:26.256 Status: dzVents: Debug: dimmer: sValue: On
Kind of interesting to find out what is causing this different behavior.
Re: Set dim level on power on
Posted: Saturday 11 July 2020 11:56
by Draakje
Well it is controlled via MQTT and when I change the dim value on the device there is still a power on sent to domoticz (with additional value of the dim level)
I guess this is the trigger..