nibi79 / worxlandroid

openHAB Binding for Worx Landroid
57 stars 20 forks source link

Scheduled Days: Can only set Sunday and Monday #83

Closed BobMiles closed 1 year ago

BobMiles commented 1 year ago

Hi,

I have a problem when changing the schedule with the binding: Sunday and Monday works fine, but the other days don't. Looking at the debug output that comes back from AWS I see that the array is not populated with the new commanded values. Here an example for Saturday, the published command correctly has the new start time 6:24 (last array item): LandroidScheduleProblem But then looking at the answer from AWS, nothing has changed for Saturday: LandroidScheduleProblem2 And the items change back to whatever AWS' response is.

Is it an issue that I don't set the minutes in 15 minute intervals? I have looked at your code but it looks fine to me...

Thank you and all the best,

Bob

sihui62 commented 1 year ago

I checked this on my installation with Monday and Wednesday, changing the values works in either direction. Make sure you have the correct channels connected to your items. If it still does not work clean the cache and tmp folders.

https://community.openhab.org/t/clear-the-cache/36424

BobMiles commented 1 year ago

I checked this on my installation with Monday and Wednesday, changing the values works in either direction. Make sure you have the correct channels connected to your items. If it still does not work clean the cache and tmp folders.

https://community.openhab.org/t/clear-the-cache/36424

Thank you so much for your answer. I found the problem: I send two commands in rapid succession, one for the hour and one for the minutes. And that's the problem. Now I delayed the second command by 10 seconds and it works fine. For reference, this is my working ECMAScript now (setting the current day's schedule to an offset of the sunrise): `var roundTimes = false

var sunriseItem = items.getItem("Sonne_Rise_Start"); var sunsetItem = items.getItem("Sonne_Set_Start");

var sunriseZDT = sunriseItem.rawState.getZonedDateTime();

var sunsetZDT = sunsetItem.rawState.getZonedDateTime();

var riseHour = sunriseZDT.getHour(); var riseMinute = sunriseZDT.getMinute(); var setHour = sunsetZDT.getHour(); var setMinute = sunsetZDT.getMinute();

// Calculate the rounded minutes let roundedRiseMinutes = Math.round(riseMinute / 15) * 15;

// Calculate the rounded minutes let roundedSetMinutes = Math.round(setMinute / 15) * 15;

// If roundedMinutes equals 60, update the hour and åset minutes to 0 if (roundedRiseMinutes === 60 && roundTimes) { riseHour++; roundedRiseMinutes = 0; }

// If hour equals 24, wrap around to 0 if (riseHour === 24) { riseHour = 0; }

// If roundedMinutes equals 60, update the hour and set minutes to 0 if (roundedSetMinutes === 60 && roundTimes) { setHour++; roundedSetMinutes = 0; }

// If hour equals 24, wrap around to 0 if (setHour === 0) { setHour = 24; }

var offset = 1

var schedule1StartHour = parseInt(riseHour + offset,10) var schedule1StartMinute = roundTimes == true ? parseInt(roundedRiseMinutes,10) : parseInt(riseMinute,10) var schedule2StartHour = parseInt(setHour - offset,10) var schedule2StartMinute = roundTimes == true ? parseInt(roundedSetMinutes,10) : parseInt(setMinute,10) var days = ["Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday","Saturday"]

var date = new Date() var today = date.getDay() var dayString = days[today]

items.getItem("LandroidM500Plus_CfgSc"+dayString+"_ScheduleStartHour").sendCommand(schedule1StartHour) setTimeout(function() { items.getItem("LandroidM500Plus_CfgSc" + dayString + "_ScheduleStartMinutes").sendCommand(schedule1StartMinute); }, 10000); // Adjust the delay time (in milliseconds) as needed //items.getItem("LandroidM500Plus_CfgSc"+dayString+"_ScheduleStartMinutes").sendCommand(schedule1StartMinute) console.log("Landroid AutoSchedule set for "+dayString+" at "+ schedule1StartHour + ":"+schedule1StartMinute) `