Skip to content

Commit

Permalink
(simatec) Debug Log for Sunprotec #412 added
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Aug 7, 2024
1 parent 8d74d60 commit d003a9f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/sunProtect.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,12 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
_triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null;
mustValue = ('' + shutterSettings[s].triggerState);
mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted);

currentValue = _triggerState?.val ? ('' + _triggerState.val) : '';

adapter.log.warn(`mustValue for ${shutterSettings[s].shutterName}: ${mustValue}`);
adapter.log.warn(`mustValueTilted for ${shutterSettings[s].shutterName}: ${mustValueTilted}`);
adapter.log.warn(`currentValue for ${shutterSettings[s].shutterName}: ${currentValue}`);

if ((currentValue === mustValue ||
currentValue === mustValueTilted) &&
shutterSettings[s].tempSensor != '' ||
Expand All @@ -406,18 +409,19 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
shutterSettings[s].tempSensor != '') ||
(shutterSettings[s].triggerID == '' &&
shutterSettings[s].tempSensor != '')) {

let insideTemp = 0;
let outsideTemp = 0;
let sunLight = 0;
adapter.log.warn(`Trigger for ${shutterSettings[s].shutterName}: ok`);

const _insideTempState = shutterSettings[s].tempSensor != '' ? await adapter.getForeignStateAsync(shutterSettings[s].tempSensor).catch((e) => adapter.log.warn(e)) : null;

insideTemp = _insideTempState?.val ? parseFloat(_insideTempState.val) : 0;

adapter.log.warn(`insideTemp for ${shutterSettings[s].shutterName}: ${insideTemp}`);
const _outsideTempState = shutterSettings[s].outsideTempSensor != '' ? await adapter.getForeignStateAsync(shutterSettings[s].outsideTempSensor).catch((e) => adapter.log.warn(e)) : null;
outsideTemp = _outsideTempState?.val ? parseFloat(_outsideTempState.val) : 0;

adapter.log.warn(`outsideTemp for ${shutterSettings[s].shutterName}: ${outsideTemp}`);
// heatProtection
if (shutterSettings[s].heatProtection == true &&
shutterSettings[s].tempHeatProtection < outsideTemp &&
Expand All @@ -432,6 +436,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {

const _sunLight = shutterSettings[s].lightSensor != '' ? await adapter.getForeignStateAsync(shutterSettings[s].lightSensor).catch((e) => adapter.log.warn(e)) : null;
sunLight = _sunLight?.val ? parseFloat(_sunLight.val) : 0;
adapter.log.warn(`sunLight for ${shutterSettings[s].shutterName}: ${sunLight}`);

if (shutterSettings[s].sunProtectEndtimerid != '' &&
shutterSettings[s].sunProtectEndtimerid != '0' &&
Expand All @@ -450,22 +455,25 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
shutterSettings[s].autoDrive != 'onlyUp') ||
(shutterSettings[s].triggerID == '')) {

adapter.log.warn(`trigger2 for ${shutterSettings[s].shutterName}: ok`);
if (resultDirectionRangeMinus < azimuth &&
resultDirectionRangePlus > azimuth &&
insideTemp > shutterSettings[s].tempInside) {

adapter.log.warn(`trigger3 for ${shutterSettings[s].shutterName}: ok`);
if (shutterSettings[s].tempOutside < outsideTemp &&
(shutterSettings[s].lightSensor != '' &&
shutterSettings[s].valueLight < sunLight ||
shutterSettings[s].lightSensor == '') &&
shutterSettings[s].currentAction != 'sunProtect' &&
shutterSettings[s].currentAction != 'OpenInSunProtect' &&
shutterSettings[s].currentAction != 'Manu_Mode') {

adapter.log.warn(`trigger4 for ${shutterSettings[s].shutterName}: ok`);
if (pendingAlarm == false) {
adapter.log.warn(`trigger5 for ${shutterSettings[s].shutterName}: ok`);
const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val) {
adapter.log.warn(`trigger6 for ${shutterSettings[s].shutterName}: ok`);
adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp);

if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) &&
Expand All @@ -476,6 +484,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) {
(shutterSettings[s].currentHeight == shutterSettings[s].heightUp ||
(shutterSettings[s].heatProtection == true &&
shutterSettings[s].tempHeatProtection < outsideTemp))) {
adapter.log.warn(`trigger7 for ${shutterSettings[s].shutterName}: ok`);

shutterSettings[s].currentAction = 'sunProtect';
shutterSettings[s].currentHeight = heightDownSun;
Expand Down

0 comments on commit d003a9f

Please sign in to comment.