Converting Spelled-Out Number to Integer

Hello,

what syntax can I use to convert/transform a string containing a spelled-out number value into an integer?

I’m trying to create a timer via rule, but the data received via Alexa/my Echo Dot is a phonetically spelled-out number, and I need it to be an integer.

I was researching and think maybe this might be possible with some java function? Is this what I’m looking for?

val itemvalue = new java.math.BigDecimal(Integer::parseInt(myHexValue, 16))

Thank you for your help!

Phonetically? Like “won too”?

1 Like

No, that is not what you are looking for. This is hard problem and there is no easy solution for it I know of. You will have to just check for each and every one.

var num = 0;

switch(word){
    case "one": num = 1
    case "two": two = 2
    ...
}
1 Like

A little clunky, but it’s working for now… thanks!!

rule "ac timer"
when 	
   Item LastVoiceCommand_Everywhere received update
then	
   if (LastVoiceCommand_Everywhere.state.toString.startsWith ("turn on the upstairs den ac for")) {	
       val actimer1 = LastVoiceCommand_Everywhere.state.toString().replace("turn on the upstairs den ac for ", "").replace("minute","").replace("s","").replace("one", "1").replace("two", "2").replace("three", "3").replace("four", "4").replace("five", "5").replace("six", "6").replace("seven", "7").replace("eight", "8").replace("nine", "9").replace("ten", "10").replace("eleven", "11").replace("twelve", "12").replace("thirteen", "13").replace("fourteen", "14").replace("fifteen", "15").replace("sixteen", "16").replace("seventeen", "17").replace("eightteen", "18").replace("nineteen", "19").replace("twenty", "20").replace("twenty one", "21").replace("twenty two", "22").replace("twenty three", "23").replace("twenty four", "24").replace("twenty five", "25").replace("twenty six", "26").replace("twenty seven", "27").replace("twenty eight", "28").replace("twenty nine", "29").replace("thirty", "30").replace("thirty one", "31").replace("thirty two", "32").replace("thirty three", "33").replace("thirty four", "34").replace("thirty five", "35").replace("thirty six", "36").replace("thirty seven", "37").replace("thirty eight", "38").replace("thirty nine", "39").replace("fourty", "40").replace("fourty one", "41").replace("fourty two", "42").replace("fourty three", "43").replace("fourty four", "44").replace("fourty five", "45").replace("fourty six", "46").replace("fourty seven", "47").replace("fourty eight", "48").replace("fourty nine", "49").replace("fifty", "50").replace("fifty one", "51").replace("fifty two", "52").replace("fifty three", "53").replace("fifty four", "54").replace("fifty five", "55").replace("fifty six", "56").replace("fifty seven", "57").replace("fifty eight", "58").replace("fifty nine", "59").replace("sixty", "60").replace(" ","")
       sendCommand(actimer,actimer1)
       sendCommand(Speak_Everywhere_Final,"Ok, upstairs den AC will turn off in " + actimer1 + " minutes")
         if (actimer1 == "1"){createTimer(now.plusMinutes(1),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "2"){createTimer(now.plusMinutes(2),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "3"){createTimer(now.plusMinutes(3),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "4"){createTimer(now.plusMinutes(4),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "5"){createTimer(now.plusMinutes(5),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "6"){createTimer(now.plusMinutes(6),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "7"){createTimer(now.plusMinutes(7),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "8"){createTimer(now.plusMinutes(8),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "9"){createTimer(now.plusMinutes(9),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "10"){createTimer(now.plusMinutes(10),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "11"){createTimer(now.plusMinutes(11),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "12"){createTimer(now.plusMinutes(12),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "13"){createTimer(now.plusMinutes(13),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "14"){createTimer(now.plusMinutes(14),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "15"){createTimer(now.plusMinutes(15),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "16"){createTimer(now.plusMinutes(16),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "17"){createTimer(now.plusMinutes(17),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "18"){createTimer(now.plusMinutes(18),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "19"){createTimer(now.plusMinutes(19),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "20"){createTimer(now.plusMinutes(20),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "21"){createTimer(now.plusMinutes(21),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "22"){createTimer(now.plusMinutes(22),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "23"){createTimer(now.plusMinutes(23),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "24"){createTimer(now.plusMinutes(24),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "25"){createTimer(now.plusMinutes(25),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "26"){createTimer(now.plusMinutes(26),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "27"){createTimer(now.plusMinutes(27),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "28"){createTimer(now.plusMinutes(28),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "29"){createTimer(now.plusMinutes(29),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "30"){createTimer(now.plusMinutes(30),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "31"){createTimer(now.plusMinutes(31),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "32"){createTimer(now.plusMinutes(32),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "33"){createTimer(now.plusMinutes(33),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "34"){createTimer(now.plusMinutes(34),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "35"){createTimer(now.plusMinutes(35),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "36"){createTimer(now.plusMinutes(36),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "37"){createTimer(now.plusMinutes(37),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "38"){createTimer(now.plusMinutes(38),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "39"){createTimer(now.plusMinutes(39),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "40"){createTimer(now.plusMinutes(40),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "41"){createTimer(now.plusMinutes(41),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "42"){createTimer(now.plusMinutes(42),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "43"){createTimer(now.plusMinutes(43),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "44"){createTimer(now.plusMinutes(44),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "45"){createTimer(now.plusMinutes(45),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "46"){createTimer(now.plusMinutes(46),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "47"){createTimer(now.plusMinutes(47),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "48"){createTimer(now.plusMinutes(48),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "49"){createTimer(now.plusMinutes(49),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "50"){createTimer(now.plusMinutes(50),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "51"){createTimer(now.plusMinutes(51),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "52"){createTimer(now.plusMinutes(52),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "53"){createTimer(now.plusMinutes(53),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "54"){createTimer(now.plusMinutes(54),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "55"){createTimer(now.plusMinutes(55),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "56"){createTimer(now.plusMinutes(56),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "57"){createTimer(now.plusMinutes(57),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "58"){createTimer(now.plusMinutes(58),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "59"){createTimer(now.plusMinutes(59),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
         if (actimer1 == "60"){createTimer(now.plusMinutes(60),  [ | sendCommand(Upstairs_Den_AC,"OFF")])}
   }
end

Once you do have the text formatted using digits, you can parse it. So you don’t need the if statements.

val actimer1Num = Integer::parseInt(actimer1)
createTimer(now.plusMinutes(actimer1Num), [ | Upstairs_Den_AC.sendCommand(OFF) ])

NOTE: Don’t use the sendCommand Action unless necessary (i.e. you have to generate the name of the Item in the Rule).

In cases where you do need all the if statements, a switch statement is better.

switch(actimer1){
    case "1": createTimer(now.plusMinutes(1), ...
    case "2": ...
}
1 Like

Thank you thank you! I’m learning so much and very much appreciate it!!

My final rule:

rule "ac timer"
when  
   Item LastVoiceCommand_Everywhere received update
then  
   if (LastVoiceCommand_Everywhere.state.toString.startsWith ("turn on the upstairs den ac for")) {   
       val actimer1 = LastVoiceCommand_Everywhere.state.toString().replace("turn on the upstairs den ac for ", "").replace("minute","").replace("s","").replace("one", "1").replace("two", "2").replace("three", "3").replace("four", "4").replace("five", "5").replace("six", "6").replace("seven", "7").replace("eight", "8").replace("nine", "9").replace("ten", "10").replace("eleven", "11").replace("twelve", "12").replace("thirteen", "13").replace("fourteen", "14").replace("fifteen", "15").replace("sixteen", "16").replace("seventeen", "17").replace("eightteen", "18").replace("nineteen", "19").replace("twenty", "20").replace("twenty one", "21").replace("twenty two", "22").replace("twenty three", "23").replace("twenty four", "24").replace("twenty five", "25").replace("twenty six", "26").replace("twenty seven", "27").replace("twenty eight", "28").replace("twenty nine", "29").replace("thirty", "30").replace("thirty one", "31").replace("thirty two", "32").replace("thirty three", "33").replace("thirty four", "34").replace("thirty five", "35").replace("thirty six", "36").replace("thirty seven", "37").replace("thirty eight", "38").replace("thirty nine", "39").replace("fourty", "40").replace("fourty one", "41").replace("fourty two", "42").replace("fourty three", "43").replace("fourty four", "44").replace("fourty five", "45").replace("fourty six", "46").replace("fourty seven", "47").replace("fourty eight", "48").replace("fourty nine", "49").replace("fifty", "50").replace("fifty one", "51").replace("fifty two", "52").replace("fifty three", "53").replace("fifty four", "54").replace("fifty five", "55").replace("fifty six", "56").replace("fifty seven", "57").replace("fifty eight", "58").replace("fifty nine", "59").replace("sixty", "60").replace(" ","")
       if (actimer1 == "1"){sendCommand(Speak_Everywhere_Final,"Ok, upstairs den AC will turn off in " + actimer1 + " minute")}
       if (actimer1 != "1"){sendCommand(Speak_Everywhere_Final,"Ok, upstairs den AC will turn off in " + actimer1 + " minutes")}
       val actimer1Num = Integer::parseInt(actimer1)
       createTimer(now.plusMinutes(actimer1Num), [ | Upstairs_Den_AC.sendCommand(OFF) ])
}
end

Question: is there any way to programattically access a timer created via a rule? Like, perhaps to query how much time is remaining on the timer, or to cancel the timer? Thanks!

Save it to a global variable. There is no way to see how much time is on it but you can reschedule it. There are literally hundreds if not thousands of Timer examples on the forum that do just that. Search for “reschedule”.

1 Like

Indirectly.
You could store the “target” time when you schedule/reschedule a timer, and compare it with “now” whenever you like.

Also the idea of a countdown timer is not what you asked about, but may be what you want

1 Like

Sorry to come back to this: is there any way to go the reverse of this, from “12:27 PM” to “twelve twenty-seven PM”?

Yes, essentially you use a sort of glorified lookup table.

What’s the context though? In a rule, a transformation an external script?
Are you writing your own text-to-speech, most TTS services do this for themselves.

I wanted to be able to make Alexa (or one of her friends/other voices) be able to tell me the time when requested via TTS. I can also use this for various alerts or other custom projects, whenever I need custom TTS-announced time information. Below is the code I have ended up using - I was just wondering if there was some built-in Java function or transformation script that would generate this information without me having to construct it and break it down manually as I have ended up doing? Is there a better way you might recommend with regards to the rule structure/format that would be more efficient? Now when I ask “Alexa, time please” she responds by telling me the time in about eight different voices/accents. This is why I had to spell-out the time and couldn’t just go with the time in numeral format - because it would be translated into the language of the voice I am using and I want it to be in English, but with a different voice/accent. It’s working well!

rule "Time"
when
    Item LastVoiceCommand_Everywhere received update "time please"
then
    val timehour1 = new DateTimeType().format("%1$tH")
    val timehour = timehour1.replace("13","one").replace("14","two").replace("15","three").replace("16","four").replace("17","five").replace("18","six").replace("19","seven").replace("20","eight").replace("21","nine").replace("22","ten").replace("23","eleven").replace("14","two").replace("12","twelve").replace("11","eleven").replace("10","ten").replace("09","nine").replace("08","eight").replace("07","seven").replace("06","six").replace("05","five").replace("04","four").replace("03","three").replace("02","two").replace("01","one").replace("00","twelve")
    val timeminute1 = new DateTimeType().format("%1$tM")
    val timeminute = timeminute1.replace("59","fifty-nine").replace("58","fifty-eight").replace("57","fifty-seven").replace("56","fifty-six").replace("55","fifty-five").replace("54","fifty-four").replace("53","fifty-three").replace("52","fifty-two").replace("51","fifty-one").replace("50","fifty").replace("49","fourty-nine").replace("48","fourty-eight").replace("47","fourty-seven").replace("46","fourty-six").replace("45","fourty-five").replace("44","fourty-four").replace("43","fourty-three").replace("42","fourty-two").replace("41","fourty-one").replace("40","fourty").replace("39","thirty-nine").replace("38","thirty-eight").replace("37","thirty-seven").replace("36","thirty-six").replace("35","thirty-five").replace("34","thirty-four").replace("33","thirty-three").replace("32","thirty-two").replace("31","thirty-one").replace("30","thirty").replace("29","twenty-nine").replace("28","twenty-eight").replace("27","twenty-seven").replace("26","twenty-six").replace("25","twenty-five").replace("24","twenty-four").replace("23","twenty-three").replace("22","twenty-two").replace("21","twenty-one").replace("20","twenty").replace("19","nineteen").replace("18","eighteen").replace("17","seventeen").replace("16","sixteen").replace("15","fifteen").replace("14","fourteen").replace("13","thirteen").replace("12","twelve").replace("11","eleven").replace("10","ten").replace("09","oh-nine").replace("08","oh-eight").replace("07","oh-seven").replace("06","oh-six").replace("05","oh-five").replace("04","oh-four").replace("03","oh-three").replace("02","oh-two").replace("01","oh-one")
    val timeperiod = timehour1.replace("13","P-M").replace("14","P-M").replace("15","P-M").replace("16","P-M").replace("17","P-M").replace("18","P-M").replace("19","P-M").replace("20","P-M").replace("21","P-M").replace("22","P-M").replace("23","P-M").replace("14","P-M").replace("12","P-M").replace("11","A-M").replace("10","A-M").replace("09","A-M").replace("08","A-M").replace("07","A-M").replace("06","A-M").replace("05","A-M").replace("04","A-M").replace("03","A-M").replace("02","A-M").replace("01","A-M").replace("00","A-M")
    val thetime = "it's " + timehour + " " + timeminute +  " " + timeperiod
    TextToMultiSpeak.sendCommand(thetime)
end

Efficiency is really no big deal. I’m sure you already see that it runs plenty fast enough.

But from a maintainability perspective, I would not put everything all on one line like that. It’s very hard to read and edit with lines that stretch out that long.

Question: Would it work if the text were like “8 37 am”? Or does it have to be the spelled out word? If that does work with the numbers, just without the time formatting, than this rule can be made way simpler.

rule "Time"
when
    Item LastVoiceCommand_Everywhere received update "time please"
then
    var hour = now.getHourOfDay()
    var meridiem = if(hour >= 12) "P-M" else "A-M"
    hour = if(hour > 12) hour - 12 else hour // convert 24 hour to 12 hour with AM/PM

    val minute = now.getMinuteOfHour()

    val timeStr = "it's " + hour + " " + minute + " " + meridiem

    TexttoMultiSpeak.sendCommand(timeStr)
    
end

Even if you do need to use the words instead of the separated numbers, the code could be made a little more complex and generic, but I’m not sure the added complexity would be worth it. But for completeness:

rule "Time"
when
    Item LastVoiceCommand_Everywhere received update "time please"
then
    // lambda to convert numbers below 20 to a String
    val teensToString = [ Number num |
        var rval = "ERROR"
        switch(num) {
            case 1: ravl = "one"
            case 2: rval = "two"
            case 3: rval = "three"
            case 4: rval = "four"
            case 5: rval = "five"
            case 6: rval = "six"
            case 7: rval = "seven"
            case 8: rval = "eight"
            case 9: rval = "nine"
            case 10: rval = "ten"
            case 11: rval = "eleven"
            case 12: rval = "twelve"
            case 13: rval = "thirteen"
            case 14: rval = "fourteen"
            case 15: rval = "fifteen"
            case 16: rval = "sixteen"
            case 17: rval = "seventeen"
            case 18: rval = "eightteen"
            case 19: rval = "nineteen"
        }
        rval
    ]

    // Get the hour and meridiem
    var hour = now.getHourOfDay()
    var meridiem = if(hour >= 12) "P-M" else "A-M"
    hour = if(hour > 12) hour - 12 else hour // convert 24 hour to 12 hour with AM/PM
    hourStr = teensToString.apply(hour)

    var minute = now.getMinuteOfHour()
    var minuteStr = ""

    switch(minute) {
        case minute < 20: minuteStr = teensToString.apply(minute)
        case minute < 30: minuteStr = "twenty-"+teensToString.apply(minute-20)
        case minute < 40: minuteStr = "thirty-"+teensToString.apply(minute-30)
        case minute < 50: minuteStr = "fourty-"+teensToString.apply(minute-40)
        case minute < 60: minuteStr = "fifty-"+teensToString.apply(minute-50)
    }

    val timeStr = "it's " + hourStr + " " + minuteStr + " " + meridiem

    TexttoMultiSpeak.sendCommand(timeStr)

end

The above code is a little more complicated but it will run way more efficiently because it only does as much work as is necessary which is mostly some comparisons which are more efficient than String.replace. And once it finds the right one it stops.

Does that make it better? Probably not. If your original code is easier for you to understand than leave it as is (though I would put each of the calls to replace on it’s own line for readability). Efficiency of this type rarely matters that much in home automation.

1 Like

can i ask where i’m doing wrong… i explain how i fix my issue… but maebe there is a better way to do .

i have a rule with water heat system where :

i try to explain :slight_smile:my water heating system run @ 2 periods , morning and evening for one hour ,but in winter i want to modify the time during the heat is up by a factor , this factor is base on the outside degres .
for this a create a math where : “15” is the base , beside is to cold for water so i make this : 15 - (outside degres ) ( for exemple 15 - 7 degres = 8) where 8*(5minutes) make minute to remove from the start time of eating for having warm water @ same time of day .
i hope a explain correctly the idea .
But at the beginning i have trouble when i want to use the variable and minus to minutes, i’m sure this is a type problem , so i fix that in that way…but there is a more “real” way to do it or is ok ?
the rule work fine , i remove the commas with ".intValue " and also need to use "as Number "

here the rule :

var Number Tempdecalage = 00//decalage de temperature exterieur
rule "Boeler on Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi, Dimanche Boeler On 3 x 1 h jour "
when
System started
or
Time cron “0 0/5 * 1/1 * ? *”//Test toutes les 5 minutes
then
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (( MeteoTemperature.state !== null && MeteoTemperature.state < 15 )) //si sous 15 degres
{
var value = MeteoTemperature.state as Number;// valeur actuelle temprature dehors
Tempdecalage = (15 - value); //Si sous 15 degres , on calcule la difference et on retire a l’heure de demarrage en minutes

}
logInfo( “value Boeler”, ((Tempdecalage.intValue as Number) * 5).toString ) //on dois convertir Tempdecalage en retirant les virgules et en disant que c’est un nombre
if ((DayOfWeek.state == “1” || DayOfWeek.state == “2” || DayOfWeek.state == “3” ||DayOfWeek.state == “4” || DayOfWeek.state == “5” || DayOfWeek.state == “6” || DayOfWeek.state == “7” ))//si DayOfWeek = Lundi ou Mardi ou Jeudi ou Vendredi , Samedi ou dimanche
{
if ((now.getMinuteOfDay >= ((860)-(Tempdecalage.intValue as Number)) && now.getMinuteOfDay <= (960+30) || now.getMinuteOfDay >= ((1760)-(Tempdecalage.intValue as Number)) && now.getMinuteOfDay <= 1860+00 ))//si il est entre 8h00 et 9h30 ou entre 17h00 et 18h00 Boeler ON 1h

{
//logInfo(“EtatBoeler”, “Boeler recieve ON”)
Boeler.sendCommand(ON)
}
else
{
// logInfo(“EtatBoeler”, “Boeler recieve OFF”)
Boeler.sendCommand(OFF)
}
}
else
{
//logInfo(“EtatBoeler”, “Boeler recieve OFF”)
Boeler.sendCommand(OFF)
}
end

The code is really hard to read without coffee fences. But as best as I can tell there is nothing wrong with the calculations. I don’t know why you have the rest for dayOfWeek since it evaluates true for all seven days a week.

Thank for your reply, the test DayOfWeek is from older version and sorry if the code is not clear, next time I remove comments, thanks again