Skip to content

Commit

Permalink
(simatec) Fix Sunprotect end by Shutter up
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Aug 5, 2024
1 parent 9b65da9 commit ab0c070
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ When the adapter crashes or an other Code error happens, this error message that
* (simatec) Code revision and improvements
* (simatec) many small fixes
* (simatec) Fix sleep up when open the Window
* (simatec) Fix Sunprotect end by Shutter up

### 1.7.3 (2024-06-20)
* (simatec) Fix Sunprotect End-Delay
Expand Down
98 changes: 84 additions & 14 deletions lib/sunProtect.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val) {
if (shutterSettings[s].triggerAction == 'sunProtect' && shutterSettings[s].KeepSunProtect === false && (parseFloat(shutterSettings[s].triggerHeight) == parseFloat(heightDownSun) || Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight))) {
if (shutterSettings[s].triggerAction == 'sunProtect' &&
shutterSettings[s].KeepSunProtect === false &&
(parseFloat(shutterSettings[s].triggerHeight) == parseFloat(heightDownSun) ||
Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight))) {

shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp);
shutterSettings[s].triggerAction = 'up';

Expand All @@ -330,8 +334,19 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
adapter.log.debug('Temperature inside: ' + insideTemp + ' < ' + hysteresisInside + ' OR ( Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight + ' )');
adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
}
else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
} else if (shutterSettings[s].triggerAction == 'sunProtect' &&
shutterSettings[s].KeepSunProtect === false &&
(parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) ||
Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightUp))) {

shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp);
shutterSettings[s].triggerAction = 'up';

adapter.log.info(`#1 Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].triggerHeight}% after is the value for up`);
adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`);
adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`);

} else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
shutterSettings[s].sunProtectEndtimerid = ''
shutterSettings[s].triggerAction = 'none';
adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active');
Expand Down Expand Up @@ -521,7 +536,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
shutterSettings[s].triggerHeight = parseFloat(heightDownSun);
shutterSettings[s].triggerAction = 'sunProtect';

adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed ');
adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed');

adapter.log.debug('save new trigger height: ' + heightDownSun + '%');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
Expand Down Expand Up @@ -659,8 +674,19 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
adapter.log.debug('Temperature inside: ' + insideTemp + ' < ' + hysteresisInside + ' OR ( Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight + ' )');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%');
}
else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
} else if (shutterSettings[s].triggerAction == 'sunProtect' &&
shutterSettings[s].KeepSunProtect === false &&
(parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) ||
Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightUp))) {

shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp);
shutterSettings[s].triggerAction = 'up';

adapter.log.info(`#2 Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].triggerHeight}% after is the value for up`);
adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`);
adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`);

} else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
shutterSettings[s].triggerAction = 'none';

adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active');
Expand Down Expand Up @@ -975,8 +1001,19 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%');
}
else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
} else if (shutterSettings[s].triggerAction == 'sunProtect' &&
shutterSettings[s].KeepSunProtect === false &&
(parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) ||
Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightUp))) {

shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp);
shutterSettings[s].triggerAction = 'up';

adapter.log.info(`#3 Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].triggerHeight}% after is the value for up`);
adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`);
adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`);

} else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
shutterSettings[s].sunProtectEndtimerid = ''
shutterSettings[s].triggerAction = 'none';

Expand Down Expand Up @@ -1202,8 +1239,19 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%');
adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
}
else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
} else if (shutterSettings[s].triggerAction == 'sunProtect' &&
shutterSettings[s].KeepSunProtect === false &&
(parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) ||
Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightUp))) {

shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp);
shutterSettings[s].triggerAction = 'up';

adapter.log.info(`#4 Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].triggerHeight}% after is the value for up`);
adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`);
adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`);

} else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
shutterSettings[s].triggerAction = 'none';

adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active');
Expand Down Expand Up @@ -1501,8 +1549,19 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%');
}
else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
} else if (shutterSettings[s].triggerAction == 'sunProtect' &&
shutterSettings[s].KeepSunProtect === false &&
(parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) ||
Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightUp))) {

shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp);
shutterSettings[s].triggerAction = 'up';

adapter.log.info(`#5 Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].triggerHeight}% after is the value for up`);
adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`);
adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`);

} else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
shutterSettings[s].sunProtectEndtimerid = ''
shutterSettings[s].triggerAction = 'none';
shutterSettings[s].sunProtectEndtimerid = '';
Expand Down Expand Up @@ -1731,8 +1790,19 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%');
adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
}
else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
} else if (shutterSettings[s].triggerAction == 'sunProtect' &&
shutterSettings[s].KeepSunProtect === false &&
(parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) ||
Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightUp))) {

shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp);
shutterSettings[s].triggerAction = 'up';

adapter.log.info(`#6 Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].triggerHeight}% after is the value for up`);
adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`);
adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`);

} else if (shutterSettings[s].currentAction == 'OpenInSunProtect') {
shutterSettings[s].triggerAction = 'none';

adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active');
Expand Down

0 comments on commit ab0c070

Please sign in to comment.