Hi,
So I am not the greatest coder but have been really getting my teeth into the DzVents stuff. I thought I'd have a go at setting a mood button that cycles through moods. In essence I now have 2 buttons in my lounge. One for setting moods and the other for turning everything off. I figured that this was the easiest way to allow anyone staying in my house a hassle free way of turning on the lights. It does however require Domoticz to be running in order to turn the lights on so I may have to rethink it. However it works quite nicely. As I'm not an expert I'd be grateful of any comments on making the code better, simpler or easier. This is it below:
return {
active = true,
on = {
devices = {
'moodSw1'
}
},
execute = function(domoticz)
local mostRecent
local TimeSinceScene1 = domoticz.scenes('DZS 1').lastUpdate.secondsAgo
local TimeSinceScene2 = domoticz.scenes('DZS 2').lastUpdate.secondsAgo
local TimeSinceScene3 = domoticz.scenes('DZS 3').lastUpdate.secondsAgo
local TimeSinceScene4 = domoticz.scenes('DZS ALLOFF').lastUpdate.secondsAgo
-- This IF statement checks to see what scene was last active and and update the local variable 'mostRecent'
if ((TimeSinceScene1 < TimeSinceScene2) and (TimeSinceScene1 < TimeSinceScene3) and (TimeSinceScene1 < TimeSinceScene4)) then
domoticz.log('Most recent was DZS 1')
mostRecent = 'Scene1'
elseif
((TimeSinceScene2 < TimeSinceScene1) and (TimeSinceScene2 < TimeSinceScene3) and (TimeSinceScene2 < TimeSinceScene4)) then
domoticz.log('Most recent was DZS 2')
mostRecent = 'Scene2'
elseif
((TimeSinceScene3 < TimeSinceScene2) and (TimeSinceScene3 < TimeSinceScene1) and (TimeSinceScene3 < TimeSinceScene4)) then
domoticz.log('Most recent was DZS 3')
mostRecent = 'Scene3'
else
domoticz.log('Most recent was DZS ALLOFF')
mostRecent = 'Scene4'
end
-- Once we know what scene was last active we can then set the scene we want to activate. Notice that the scene button will only set scenes.
-- It will never turn all the lights off. Only the all off scene can do that. In essence the mood button only ever sets the mood.
if (mostRecent == 'Scene1') then
domoticz.setScene('DZS 2','On')
elseif (mostRecent == 'Scene2') then
domoticz.setScene('DZS 3','On')
elseif (mostRecent == 'Scene3') then
domoticz.setScene('DZS 1','On')
elseif (mostRecent == 'Scene4') then
domoticz.setScene('DZS 1','On')
end
end
}
Cycling through scenes with DzVents
Moderator: leecollings
-
- Posts: 33
- Joined: Wednesday 06 January 2016 10:51
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Who is online
Users browsing this forum: No registered users and 1 guest