When I drive home I activate a scene; opening my gate, garagedoor, activating some lights etc. Activating this scene is done with a cellphone, but the reception is quite poor.
It happends quite a lot that I get an “empty response” from the authomation programm, I simply press the button another time and it normally works.
BUT, it happends also quite often that there is just a delay in the network and the scene triggers than 2 times… this is not good , since it closes the gate again.
Is it possible to insert something in a scene so this scene can only be activated once in a given period, let’s say 1 minute, if the button is pressed to activate the scene for another time within this minute , nothing should happen.
This will run those other 2 scenes even if the event happens in less than 60 seconds.
If that’s what you want then you can do it.
If you do not want them to run if they are within 60 seconds than you can do:
local result = true
local now = os.time()
if (LastTime) then
result = now - LastTime > 60
end
LastTime = now
if (result) then
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "6"}, 0)
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "7"}, 0)
end
return result
Looking at my scenes, I found another scene where this “not run within a timeframe comes in handy”
Also here allready a code ( home and away button via a virtual switch)
The idea is to, first check , if the virtual switch is on , if yes, than activate the scene , but not to activate more than once within 2 minutes.
local result = true
local now = os.time()
if (LastTime) then
result = now - LastTime > 60
end
LastTime = now
return result
Thinking about it , I did this:
autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",32)
if(autoscene=="1")then
local result = true
local now = os.time()
if (LastTime) then
result = now - LastTime > 120
end
LastTime = now
return result
else
return false
end
but to be honoust… I have no clue if it makes sense what i did… :-\
That will work but is not very good form for programming.
Good form will reduce the possibility of programming errors.
I would use:
local autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",32)
local result = true
local now = os.time()
if (LastTime) then
result = now - LastTime > 120
end
LastTime = now
return result and (autoscene == "1")
Again I need your help:-)
I was editing some more scenes and my alarm needs some changing, i tried to edit the code myself , but it doesn’t work, even if the virtual switch (ID32) is selected “off” the 2 scenes i want to run still activate… where is the error?
local autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",32)
local result = true
local now = os.time()
if (LastTime) then
result = now - LastTime > 70
end
LastTime = now
if (result) then
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "29"}, 0)
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "32"}, 0)
end
return result
*check if virtual switch id 32 is on
*if yes, than check if the scene has not been activated the last 70 seconds
*if that is not the case than execute scene 29 and 32
Since I do not use Virtual Switches, not do I know the sense of it’s logic … I can only guess that the change is as follows:
local autoscene = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",32)
local result = (autoscene == "1")
local now = os.time()
if (LastTime) then
result = result and (now - LastTime > 70)
end
LastTime = now
if (result) then
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "29"}, 0)
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "32"}, 0)
end
return result
if startTime <= endTime then
– Both the start time and the end time are in the same day:
– if the current time is in the given interval, run the scene.
if startTime <= currentTime and currentTime <= endTime then
return true
end
else
– The start time is before midnight, and the end time is after midnight:
– if the current time is not outside the given interval, run the scene.
if not (endTime < currentTime and currentTime < startTime) then
return true
end
end