diff --git a/api/ecobee_sensor.php b/api/ecobee_sensor.php index de6ec57..cb87c0f 100644 --- a/api/ecobee_sensor.php +++ b/api/ecobee_sensor.php @@ -35,6 +35,17 @@ class ecobee_sensor extends cora\crud { ) === true ) { $return[$ecobee_sensor['ecobee_sensor_id']] = $ecobee_sensor; + } else if ( + in_array( + $ecobee_sensor['type'], + ['monitor_sensor', 'control_sensor'] + ) === true + ) { + foreach($ecobee_sensor['capability'] as $capability) { + if($capability['type'] === 'temperature') { + $return[$ecobee_sensor['ecobee_sensor_id']] = $ecobee_sensor; + } + } } } diff --git a/api/runtime.php b/api/runtime.php index ff882a1..75cf46d 100644 --- a/api/runtime.php +++ b/api/runtime.php @@ -755,6 +755,9 @@ class runtime extends cora\api { * has to be accounted for. * * For now I am simply ignoring this situation. + * + * Update 12/14/2021: At the very least this affects monitor_sensor + * and control_sensor. Both are somewhat uncommon. */ if (isset($sensors_by_identifier[$sensor_identifier]) === true) { $sensor = $sensors_by_identifier[$sensor_identifier]; @@ -779,6 +782,38 @@ class runtime extends cora\api { $datas[$sensor['sensor_id']][$capability['type']] = ($capability['type'] === 'temperature') ? ($value * 10) : $value; } } + } else { + // If the first attempt to identify the sensor failed, try again. + // This is for monitor_sensor and control_sensor. + $sensor_identifier = $key; + $capability_identifier = ''; + + if (isset($sensors_by_identifier[$sensor_identifier]) === true) { + $sensor = $sensors_by_identifier[$sensor_identifier]; + $sensor_id = $sensors_by_identifier[$sensor_identifier]['sensor_id']; + + if (isset($datas[$sensor['sensor_id']]) === false) { + $datas[$sensor['sensor_id']] = [ + 'sensor_id' => $sensor['sensor_id'], + 'timestamp' => get_utc_datetime( + $columns['date'] . ' ' . $columns['time'], + $thermostat['time_zone'] + ) + ]; + } + + foreach($sensor['capability'] as $capability) { + if( + $capability['id'] == $capability_identifier && + in_array($capability['type'], ['temperature', 'occupancy']) === true && + $value !== null + ) { + $datas[$sensor['sensor_id']][$capability['type']] = ($capability['type'] === 'temperature') ? ($value * 10) : $value; + } + } + } + + } } diff --git a/api/sensor.php b/api/sensor.php index 05f75c6..989cf4f 100644 --- a/api/sensor.php +++ b/api/sensor.php @@ -39,6 +39,28 @@ class sensor extends cora\crud { ) === true ) { $return[$sensor['sensor_id']] = $sensor; + } else if ( + in_array( + $sensor['type'], + ['monitor_sensor', 'control_sensor'] + ) === true + ) { + /** + * Support for these sensor types is rudimentary. It's enough to get + * temperature but some of these legacy sensors split a single sensor + * up into multiple sensors. For example, thermostat temperature, + * humidity, and motion are three different sensors. Newer sensors + * show up as a single sensor with more than one capability. To make + * sense of this I would have to do a good deal of merging etc in the + * GUI. + * + * I don't really think it's worth the clutter or the time investment. + */ + foreach($sensor['capability'] as $capability) { + if($capability['type'] === 'temperature') { + $return[$sensor['sensor_id']] = $sensor; + } + } } } diff --git a/js/component/card/sensors.js b/js/component/card/sensors.js index c4dca84..558e86a 100644 --- a/js/component/card/sensors.js +++ b/js/component/card/sensors.js @@ -132,12 +132,18 @@ beestat.component.card.sensors.prototype.decorate_sensor_ = function(parent, sen .render(td_above_below); } - if (sensor.occupancy === true) { - (new beestat.component.icon('eye', 'Occupied')).render(td_icons); - } else { - (new beestat.component.icon('eye_off', 'Unoccupied')) - .set_color(beestat.style.color.bluegray.light) - .render(td_icons); + if ( + sensor.type !== 'monitor_sensor' && + sensor.type !== 'control_sensor' + ) { + // Occupancy is not supported for these legacy sensor types. + if (sensor.occupancy === true) { + (new beestat.component.icon('eye', 'Occupied')).render(td_icons); + } else { + (new beestat.component.icon('eye_off', 'Unoccupied')) + .set_color(beestat.style.color.bluegray.light) + .render(td_icons); + } } td_icons.appendChild($.createElement('span').style({