CODE: Public Holiday virtual switch

Here’s another virtual device for your MiOS-meddling pleasure… It presents itself as a binary switch, which is

[ul][li] ON if today is a public holiday, and[/li]
[li]OFF it today is not.[/li][/ul]

For “public holiday” you can substitute anything which can be represented as all-day events in an iCalendar (*.ics) accessible over HTTP. Some ideas for using this device:

[ul][li]Use it as an inhibitor for the excellent WakeupRamp plugin so you can sleep in on holidays. (This is why I wrote the plugin.)[/li]
[li]Publish your vacation dates to an iCalendar file, and set scenes to start when you go away, and scenes to stop when you come back from your trip.[/li]
[li]Feed it with Jewish holidays from http://www.hebcal.com/ and use it for a sunset scene Luup Event condition.[/li][/ul]

To install:

  1. Use SSH (Unix scp or WinSCP or another tool) to copy ical.lua to /usr/lib/lua.
  2. Add D_HoildayVirtualSwitch1.xml, D_HolidayVirtualSwitch1.json and I_HolidayVirtualSwitch1.xml to MiOS Developers > Luup Files.
  3. Create a new Luup device with UpnpDevFilename D_HolidayVirtualSwitch1.xml. Set the Description to whatever you want to name the device.
  4. Save, wait, then reload, then wait. (It seems to take two Luup restarts for the variables to appear.)
  5. Click the spanner/wrench and go to the Advanced tab. Scroll to the bottom and in the calendar field, put the URL of the iCal file (e.g. [b]http://www.vic.gov.au/ical/holidays.html[/b]).
  6. Optional: change the offset field to 1 if you want the device to represent tomorrow’s holidays (-1 for yesterday, 7 for next week, etc.).
  7. Close the dialog and Save.

Some screen shots:

[ul][li]The device on a day that isn’t a holiday.[/li]
[li]The device on a day that is a holiday.[/li]
[li]The device control dialog.[/li][/ul]

Wow! What a good idea!

Thanks Futzle

Nice plugin. Thanks for sharing your code.

Feature requests: :slight_smile:

[ul][li]Use a local ics file[/li]
[li]Display a [complete] list of future holidays on the ‘Control’ tab (could be implemented via HTML injection via UPnP variable …)[/li]
[li]Display a warning message if there are no future holidays in the ics file.[/li][/ul]

Edit:
MCV should integrate the holiday switch into the ‘Timers’ tab.

Wouldn’t it be a little bit less resource consuming to use a DOW timer in the startup code instead of an interval timer in [tt]periodic[/tt]?

luup.call_timer("periodic", 1, "60", "", "")
luup.call_timer("periodic", 2, "00:00:01", "1,2,3,4,5,6,7", "")

… and please feel free to borrow some load balancing code from DAD. :slight_smile:

For my information, what is the difference between the two ways of doing it ?

@futzle a newbie question, your first install step “Add ical.lua to MiOS Developers > Extra Lua Files (or scp it to /usr/lib/lua).” do we need to enter the full directory path) e.g [font=Verdana]C:\Desktop\VERA stuff\HolidayVirtual\ical.lua[/font]? ???

Tried it both ways aka filename only and with the full directory path with no success, I get a generic device but my advance tab doesn’t have a calendar field even after a number of Lua reloads… more clues please

I thought about that at the time… but I went with the code you see for a couple of not-very-compelling reasons. Because of the known daylight saving bug that you found with timers, and because of my long history of programming with time zones, I’m leery of anything that works in local time. Also, I considered enhancing the plugin later to handle iCal events shorter than a day and having a start and end time. Perhaps the real reason is that I was lazy and wanted to code this up as quick as possible.

Thanks for the feature requests. I’ll try to find time to do them. Also, patches welcome. :slight_smile:

To be honest, I used scp to copy the file, so I can’t speak for how well the Extra Lua Files page works. The end result is that the Vera has to have a file /usr/lib/lua/ical.lua, and you can use whatever mechanism you like to get it there. If you’re a Windows person who doesn’t like command lines, something like WinSCP is probably the way to do it.

The way these “upload file” dialogs work in web pages is that you should see the full path to your local file in the File field, but when it uploads to the Vera, the path gets stripped off and the Vera stores the file in whatever directory it likes, presumably the correct one. There is a known bug with Internet Explorer which messes with the path, so it’s generally recommended to use a different browser to do these uploads.

Chances are very good that the problem is with uploading the four files, so look for some evidence that the files were uploaded properly: you should be able to see the three I_ and D_ files in the Luup Files list, for instance. Also, make sure that you didn’t misspell the D_*.xml filename wrong when you created the device. Copy and paste the filename just to make sure.

PHVS thinks today (Saturday) is a holiday (Good Friday) in Germany …

The reason is obvious:

From http://www.schulferien.org/iCal/Feiertage/icals/Feiertage_Nordrhein_Westfalen_2011.ics:

BEGIN:VEVENT
CREATED:20110114T125119Z
LAST-MODIFIED:20110114T125119Z
DTSTAMP:20110114T125119Z
SUMMARY:Karfreitag
DTSTART;VALUE=DATE:20110422
DTEND;VALUE=DATE:20110423
URL:http://www.schulferien.org/Feiertage
DESCRIPTION:Karfreitag ist gesetzlicher Feiertag in Nordrhein-Westfalen. Alle Termine auf www.schulferien.org/Feiertage
TRANSP:TRANSPARENT
UID:Karfreitag-Nordrhein_Westfalen-201104221197827424@schulferien.org
END:VEVENT

Is the ics data just plain wrong?

Ok @futzle, got working… please fix your post, in step 3 you missed spelled “3. Create a new Luup device with UpnpDevFilename D_HoildayVirtualSwitch1.xml. Set the Description to whatever you want to name the device”.

I kept copying your misspelled text into the new device with no success! :-[ One good thing is you introduced me to WinSCP which is great tool, it’s the first time I seen my actual VERA directory structures and files :-* I was looking for a tool to review my logs… thanxs

I’ll quote myself…

For my information, what is the difference between the two ways of doing it ?[/quote]

No, the data for your state is right, unlike the data for mine. The end date is supposed to be exclusive, so if the dates are the same (as for the Victoria file I was working off) you have a zero-day event. The events in the NRW is a correct one-day event.

I have modified the file I_HolidayVirtualSwitch1.xml in the first post of this topic. Please let me know if it fixes the bug.

It’s not surprising that there are tools out there that get the ics format wrong. I think that I am going to have to code a lot of workarounds into this plugin to handle them all.

Fixed. Thanks for finding that, and sorry for the wild goose chase.

One sets a timer to call the periodic() function at 1 minute past midnight on the next day. The other sets a timer to call the periodic() function 60 seconds from now. The arguments to call_timer() are explained here: http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_call_timer

I get “Lua Engine Failed to Start” after the first refresh?

m0jon

I get "Lua Engine Failed to Start" after the first refresh?

Please use [tt]scp[/tt] to transfer [tt]ical.lua[/tt] to your Vera. ‘MiOS developers’ → ‘Extra Lua files’ → ‘Add extra LUA file’ doesn’t seem to work …

@futzle

Please modify step 1 of your installation instructions.

Please let me know if it fixes the bug.

Thanks for the fix, it does work now.

Here comes a quick and dirty implementation of my feature request

Display a [complete] list of future holidays on the 'Control' tab (could be implemented via HTML injection via UPnP variable ...)

@futzle,

Thank you kindly for creating this, the Holiday Virtual Switch is cool and most certainly useful. It will def. be nice to bypass certain scenes if a holiday is near.

@Ap15e

I dig it, nice tweak. :slight_smile:

@futzle, question the link in your quote is for Auzie holiday’s is it possible to down load my countries holiday ical and reference it from my computer vs a URL?

@Ap15e thanxs for the update I like seeing future holidays, I notice that today did not turn On (Easter) might just be that I updated today?

Absolutely. You just need to be able to have an iCalendar-format file (*.ics) on a machine on your LAN that can serve web pages. I’m in a Mac household, so I’d do something like this:

  1. Set up Web Sharing on my computer, turning on the computer’s built-in web server. (This is the bit that would be most different for Windows users. You could download Apache, or enable your computer’s built-in IIS. Perhaps an expert can chime in.)
  2. Publish the calendar from iCal or Outlook, to a file inside the web server’s directory (~UserName/Sites/my-calendar.ics). Or, if I already have an externally-sourced *.ics file, just copy it to the same location.
  3. Point the HolidayVirtualSwitch calendar variable at the file on the server (http://my-computer/~UserName/my-calendar.ics).

Related: There’s a feature request from @Ap15e to make the plugin work with a local file on the Vera, which you’d copy over to it using SFTP. I just haven’t coded it up yet.

@Ap15e thanxs for the update I like seeing future holidays, I notice that today did not turn On (Easter) might just be that I updated today?

It needs two cycles of reloading the Luup engine to appear. Nice addition, @Ap15e. I will consider your hack the new official version :slight_smile:

Question to the community: does anyone have examples of published holiday *.ics files that use recurrence rules? I have a feeling I should support them, and need real-world samples. All the examples I’ve seen so far are one-off all-day events.

Yes please, in my humble opinion it makes better sense rather than trying to find web servers to link to (although suggest keeping the capability).

@Ap15e I’m not clear as to recurrence rules is this holidays that re-occur from year to year or is this a holiday that expand more than one day?