/
SSensors_valueUpdated.php
62 lines (56 loc) · 1.95 KB
/
SSensors_valueUpdated.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
$ot = $this->object_title;
$description = $this->description;
if (!$description) {
$description = $ot;
}
$directionTimeout = (int)$this->getProperty('directionTimeout');
if (!$directionTimeout) {
$directionTimeout = 1*60*60;
}
$value = (float)$params['NEW_VALUE'];
$minValue = (float)$this->getProperty('minValue');
$maxValue = (float)$this->getProperty('maxValue');
$is_normal = (int)$this->getProperty('normalValue');
if ($maxValue == 0 && $minValue == 0 && !$is_normal) {
$this->setProperty('normalValue', 1);
} elseif (($value > $maxValue || $value < $minValue) && $is_normal) {
$this->setProperty('normalValue', 0);
if ($this->getProperty('notify')) {
//out of range notify
say(LANG_DEVICES_NOTIFY_OUTOFRANGE . ' (' . $description . ' ' . $value . ')', 2);
}
} elseif (($value <= $maxValue && $value >= $minValue) && !$is_normal) {
$this->setProperty('normalValue', 1);
if ($this->getProperty('notify')) {
//back to normal notify
say(LANG_DEVICES_NOTIFY_BACKTONORMAL . ' (' . $description . ' ' . $value . ')', 2);
}
}
$data1 = getHistoryValue($this->object_title . '.value', time() - $directionTimeout);
$direction = 0;
if ($data1 > $value) {
$direction = -1;
} elseif ($data1 < $value) {
$direction = 1;
}
$currentDirection = $this->getProperty('direction');
if ($currentDirection != $direction) {
$this->setProperty('direction', $direction);
}
$linked_room = $this->getProperty('linkedRoom');
if ($linked_room && $this->getProperty('mainSensor')) {
if ($this->class_title == 'STempSensors') {
setGlobal($linked_room . '.temperature', $value);
} elseif ($this->class_title == 'SHumSensors') {
setGlobal($linked_room . '.humidity', $value);
} elseif ($this->class_title == 'SLightSensors') {
setGlobal($linked_room . '.light', $value);
}
}
$this->callMethod('statusUpdated');
/*
include_once(DIR_MODULES.'devices/devices.class.php');
$dv=new devices();
$dv->checkLinkedDevicesAction($this->object_title, $value);
*/