ariela
(Andrea Riela)
December 28, 2018, 11:16pm
1
Hi folks,
I’m trying to reduce my power consumption at home, and I would like to manage my devices in accordance with the current energy timeslot.
In facts, I have 3 timeslots:
F1: Mon/Fri 8-19
F2: Mon/Fri 7-8 and 19-23, and Sat all day
F3: remaining (Mon/Fri 23-7 and Sun all day)
Any suggestion how to create a rule for this?
I was thinking … item Timeslot, when time is 8-18 MON/FRI, set Timeslot to F1, .and so on … but what should be the trigger?
thanks for your suggestion
Regards
Andrea
vzorglub
(Vincent Regaud)
December 29, 2018, 12:06am
2
See:
Please see Design Pattern: What is a Design Pattern and How Do I Use Them for an explanation of what a DP is and how to use them.
Problem Statement
Often in home automation one has certain rules they want to run at certain times or have the home automation exhibit different behaviors for different times of day. The naieve approach would be to do the time comparisons inline in each Rule that cares about the time of day. This DP provides an alternative approach.
This DP is particularly suitable …
ariela
(Andrea Riela)
December 31, 2018, 9:55am
3
I’m trying with this rule
rule "Energy Timeslot"
when
Time cron "0 0 0/1 1/1 * ? *" or
System started
then
if ((now.getDayOfWeek == 1) && (LocalTime_Holiday == OFF)) {
if (now.getHourOfDay < 7) {
Auto_Energy_Timeslot.postUpdate(3)
}
else if (now.getHourOfDay < 8) {
Auto_Energy_Timeslot.postUpdate(2)
}
else if (now.getHourOfDay < 19) {
Auto_Energy_Timeslot.postUpdate(1)
}
else if (now.getHourOfDay < 23) {
Auto_Energy_Timeslot.postUpdate(2)
}
else if (now.getHourOfDay >= 23) {
Auto_Energy_Timeslot.postUpdate(3)
}
}
and so on for Tue, Wed, etc …
But Auto_Energy_Timeslot is always 3 … mmm
Do you see any visible error?
Thanks
Andrea
vzorglub
(Vincent Regaud)
December 31, 2018, 10:04am
4
Try that:
rule "Energy Timeslot"
when
Time cron "0 0 0/1 1/1 * ? *" or
System started
then
if ((now.getDayOfWeek == 1) && (LocalTime_Holiday == OFF)) {
val int thisHour = now.getHourOfDay
switch thisHour {
case thisHour < 7: Auto_Energy_Timeslot.postUpdate(3)
case thisHour = 7: Auto_Energy_Timeslot.postUpdate(2)
case (thisHour > 7 && thisHour < 19): Auto_Energy_Timeslot.postUpdate(1)
case (thisHour >= 19 && this Hour < 23): Auto_Energy_Timeslot.postUpdate(2)
case thisHour >= 23: Auto_Energy_Timeslot.postUpdate(3)
}
}
end
ariela
(Andrea Riela)
December 31, 2018, 10:13am
5
Same … always 3. I’ve just restarted the system.
in my logs:
2018-12-31 11:11:27.052 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'power-consumption.rules', using it anyway:
Assignment to final variable
vzorglub
(Vincent Regaud)
December 31, 2018, 10:14am
6
My fault:
case thisHour == 7: Auto_Energy_Timeslot.postUpdate(2)
Double ==
vzorglub
(Vincent Regaud)
December 31, 2018, 10:22am
8
Found it, I think
LocalTime_Holiday.state == OFF
ariela
(Andrea Riela)
December 31, 2018, 10:45am
9
ooh …f… yes, it did the trick
thanks
Andrea