Control house lighting with power outage correction


#1

I’ve got a bit of an odd one here…I’m using this as a learning experience, so yes, I know it’s fairly over complicated, but I’m okay with that. However, if you have a better way to accomplish this, I’m open to it. Let me know if what I want to do is feasible?

Here’s what I want to do…

This piston is just to control the lights in my house…but a little more than that…basically it will have the ability to be run at any time during the day and it will always set the lights to what they should be at that time.

I have a variable for each device I plan to control throughout the day, so I want it to work a little like this (this is half pseudo code and half webCore syntax, so bear with me):

string DrivewayLightsSwitch = off;
string FishTankSwitch = off;
integer PorchLightLevel = 0;
integer BalconyLightsLevel = 0;
string LivingRoomFanSwitch = off;

Happens at: 5:00AM, Sunrise, Sunset+30, 8:30PM, 10:00PM, 11:30PM
OR
Routine "fix lights" runs
{
	IF currentTime >= 5:00AM
		DrivewayLightsSwitch = on
		FishTankSwitch = on

	IF currentTime >= Sunrise
		DrivewayLightsSwitch = off
		PorchLightLevel = 0

	IF currentTime >= Sunset+30
		DrivewayLightsSwitch = on
		PorchLightLevel = 40
		BalconyLightsLevel = 40

	IF currentTime >= 8:30PM
		FishTankSwitch = off

	IF currentTime >= 10:00PM
		DrivewayLightsSwitch = off
		PorchLightLevel = 20
		BalconyLightsLevel = 0

	IF currentTime >= 11:30PM
		LivingRoomFanSwitch = off
}

Driveway Lights
	Set switch to = {DrivewayLightsSwitch};

Fish Tank
	Set switch to = {FishTankSwitch};

Porch Light
	Set level to = {PorchLightLevel};

Balcony Lights
	Set level to = {BalconyLightsLevel};

Living Room Fan
	Set switch to = {LivingRoomFanSwitch};

#2

Absolutely its feasible, its a fairly simple piston. No need for variables either. You would need to make sure that your conditions are in the right order, looks like they already are, and change all but the first IF statements to ELSE IF so that it exits the IF block once one of them is true. If you ran the piston at 11:30 all of those IF statements would execute, I don’t think you want that.

Happens at: 5:00AM, Sunrise, Sunset+30, 8:30PM, 10:00PM, 11:30PM
OR
Routine “fix lights” runs
{
IF currentTime >= 5:00AM
with DrivewayLishts turn on
with FishTankSwitch turn on

else IF currentTime >= Sunrise
	with DrivewayLightsSwitch turn off
	with PorchLightLevel set level 0

else IF currentTime >= Sunset+30
	with DrivewayLightsSwitch turn on
	with PorchLight setLevel 40
	with BalconyLights setLevel 40

else IF currentTime >= 8:30PM
	with FishTankSwitch turn off

    else IF currentTime >= 10:00PM
	with DrivewayLightsSwitch turn off
	with PorchLight set Level 20
	with BalconyLights set level 0

else IF currentTime >= 11:30PM
	with LivingRoomFanSwitch turn off

EDIT: Now that I’m looking at it, that won’t do what you want…I’m dumb. I think you’d be best to do IF is between.

If is between sunrise and sunset +30
If is between sunset +30 and 8:30
If is between 8:30 and 10:00
if is between 11:30 and sunrise.


#4

Yeah, haha, that’s the problem. I need the variables so I can do the power loss correction. My smart bulbs default to 100% brightness if they lose power for any reason. So that’s why I want this “correction” ability.

I did consider using between…but that makes it very difficult to manage if I decide to add a new trigger time, like if I wanted to add one for 2PM or something…then I would have to go and modify two other conditions plus add the 2pm condition.