Code to check for daylight savings change date

Hi,

would anyone have any code with could check for the current day being the days that daylight savings are being on and off? We have some solar panels on our house, and cheaper electricity during the night, and depending on whether we’re in DST or not, I would like the vera events to trigger either at night (when solar panels don’t generate much) or during the day (when sun is likely to be out). The handling of whether the events happen during the day or night is already handled, and currently picks up a virtual switch, however I currently need to manually change the virtual switch from on to off and back again, and to save me having to remember, if this could be automated, then that would be amazing.

As I’m based in the UK, the dates that the changes happen are, last Sunday in March, and last Sunday in Oct.

Thanks
Tony

Yes indeed, it’s built into the native date function of Lua.

local t = os.date "*t"

will return a table like this:

{
	 day = 5,
	 hour = 11,
	 isdst = false,
	 min = 45,
	 month = 2,
	 sec = 30,
	 wday = 2,
	 yday = 36,
	 year = 2018
}

So you can test for DST with

if t.isdst then
  -- it is DST
else
  -- it isn't DST
end

Hi,

sorry, something still not right.

So this is the setup, a scene, triggered every sunday at 2am, with the actions to change the GMT flag to off.

Lua code is:

local v_time = os.date (“*t”)
local v_dst = (v_time.isdst)

kwikLog("v_dst = " … v_dst)

if v_dst then
kwikLog(“return true”)
return true
else
kwikLog(“return false”)
return false
end

Sorry, something odd happened with edge and it posted the update before I finished!

So, I’ve added an extra trigger for testing, and this appears to be making the change to the gmt flag (virtual device).

Is the setup correct? Have I done something wrong - this is only the second time I’ve used the code attached to a scene.

I’ve tried using the kwikLog, but even that errors with 404 - Not Found.

Thanks for your help!
Tony

Why not use an Absolute Schedule in PLEG?

Unfortunately the actual date changes. It?s always the last Sunday of March, when we move to BST, and last Sunday of October, when we head into GMT.

Thx

I would simply have written:

return (os.date "*t").isdst

…less to go wrong.

Of course, it does then depend on what the scene actions actually do as to whether this has the desired effect, or not!

Hi,

so, here’s the solution that worked this morning, as we changed back into GMT.

sGMT_Day =

on type: day of month,
Days: 25,26,27,28,29,30,31

off type: day of month,
Days: 25,26,27,28,29,30,31

sSunday =

on type: day of week
Selected days = Sunday
Time: 01:00:00

sOct =

on type: absolute
Date: 10/25/*

off type: absolute
Date: 10/31/*

Condition = sGMT_Day and sSunday and sOct

Not sure why but sOct and sSunday wouldn’t work on their own, had to add in the sGMT_Day too for the condition to work.

This also works for when we move into BST, with:

sMar =

on type: absolute
Date: 03/25/*

off type: absolute
Date: 03/31/*

Hope it helps someone…