From Events to Scene Part One

I like to convert two of my Homeseer Events to Vera scene

Close
First one is simple one that will close the curtains 15 minutes after sunset.
To be sure that the Harrison curtains has closed I’m sending the close command again after 250 ms (This is for the WAF)
I need to be sure that it will close since it’s working one a crowded 433 Mhz

Is there any option in the advanced tab for wait command and then resend the close command again?
Or is Luup the best option for this

UI5:
[tt]http://forum.micasaverde.com/index.php/topic,9577.msg63900.html#msg63900[/tt]

Thanks for pointing.

This will solve the problem
Daley is only a bit longer…but that’s okay for this scene

Open part is a bit more challenging

Open:
Time is 15 minutes before sunrise
AND
Time is after 7:00
Or
Time is 7:00
AND
It’s Daytime

[quote=“TANE, post:4, topic:171383”]Open part is a bit more challenging

Open:
Time is 15 minutes before sunrise
AND
Time is after 7:00
Or
Time is 7:00
AND
It’s Daytime[/quote]

Via luup you can do. Algorithmically you are saying:

IF after 7am AND 15 before sunrise
Else if
7am and after sunrise

open

right?

If that is the case then luup code can handle. The only difficulty is sunrise in luup. MCV is exposing that in an easy luup function but I don’t think it is a simple call now.

Thanks.
Thats what I’m looking for…

Do you have any samples?

Other option can be a simple scene that checks the sunrise.
If true trigger another scene that will check the time…if correct then it will open.
Not sure if you can run a scene form a scene…

[quote=“TANE, post:6, topic:171383”]Thanks.
Thats what I’m looking for…

Do you have any samples?

Other option can be a simple scene that checks the sunrise.
If true trigger another scene that will check the time…if correct then it will open.
Not sure if you can run a scene form a scene…[/quote]

Actually the way I would do it is create a virtual switch (forums can direct you there (simple install a plug-in)).
Then via a scene turn this Virtual switch on at sunrise and off at sunset (then you can use it for sunset things as well)

Then create a scene that runs at 7am to open your blinds but checks the virtual switch (via luup) if it is set (put this code in the luup section of this scene)

DeviceID = 15 -- Virtual Switch Device ID
virtualSwitch = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",DeviceID)

if(virtualSwitch == "1")then
  return true -- Sunrise
else
  return false -- Not Sunrise
end

This solve part 2 (if it is 7 AND sunrise) open

Then we create another scene that runs at 15 min prior to sunrise
and in the luup section

local openTime = "07:00"
 
local hour = tonumber( openTime:sub( openTime:find("%d+") ) )
local minute = tonumber(openTime:sub(-2))
 
if hour and minute then
    startTime = hour * 100 + minute
else
    luup.log("ERROR: invalid start time")
    return false
end
 

local currentTime = os.date("*t")
currentTime = currentTime.hour * 100 + currentTime.min

 
if currentTime >= openTime then
        return true
else
        return false
    end
else

This solves Part 1 (15 min prior to Sunrise AND 7 or later)

This isn’t elegant because your first scene will also fire if your send scene is true as well. Just means you open your blinds again. You could solve this by not using the virtual switch as a sunrise sunset variable but as an OK to open variable then set it on at 7 and sunrise and turn it off in your luup code if you trigger your scene.

Another solution:

  1. Setup a scene with two schedules: ‘15 min before sunrise’ and ‘7:00’
  2. Add Luup code to the scene:
return ( ( ( os.time() + 3600 * luup.timezone - 10 ) % 86400 ) / 3600 > 7 ) or ( not luup.is_night() )

See wiki documentation for firmware requirements for [tt]luup.timezone[/tt].

[quote=“Ap15e, post:8, topic:171383”]Another solution:

  1. Setup a scene with two schedules: ‘15 min before sunrise’ and ‘7:00’
  2. Add Luup code to the scene:
return ( ( ( os.time() + 3600 * luup.timezone - 10 ) % 86400 ) / 3600 > 7 ) or ( not luup.is_night() )

See wiki documentation for firmware requirements for [tt]luup.timezone[/tt].[/quote]

Much better!

Thanks for the scripts.
The last one is running now…I’m going to analyse both script for better understanding.

[quote=“TANE, post:4, topic:171383”]Open part is a bit more challenging

Open:
Time is 15 minutes before sunrise
AND
Time is after 7:00
Or
Time is 7:00
AND
It’s Daytime[/quote]

If I understand this and the proposed implementation correctly (and time of sunrise is the change over time between night and day) your curtains will not open when the time of sunrise lies between 7.00 and 7.15!

Thats correct…One of the options is a second event in Homeseer.