Temperature and Humidity from Nest Protect - nest-api

The Nest Protect (smoke and CO alarm) can measure temperature and humidity but neither the official or unofficial API's appear to allow access to this data. Is anyone working on a work around? Any line of sight to accessing this data? Suggestions? Thanks!

$infos = (object) array(
'current_state' => (object) array(
'mode' => $mode,
'temperature' => $this->temperatureInUserScale((float) $this->last_status->shared->{$serial_number}->current_temperature),
'humidity' => $this->last_status->device->{$serial_number}->current_humidity,
'ac' => $this->last_status->shared->{$serial_number}->hvac_ac_state,
'heat' => $this->last_status->shared->{$serial_number}->hvac_heater_state,
'alt_heat' => $this->last_status->shared->{$serial_number}->hvac_alt_heat_state,
'fan' => $this->last_status->shared->{$serial_number}->hvac_fan_state,
'auto_away' => $this->last_status->shared->{$serial_number}->auto_away, // -1 when disabled, 0 when enabled (thermostat can set auto-away), >0 when enabled and active (thermostat is currently in auto-away mode)
'manual_away' => $manual_away,
'leaf' => $this->last_status->device->{$serial_number}->leaf,
'battery_level' => $this->last_status->device->{$serial_number}->battery_level
),
'target' => (object) array(
'mode' => $target_mode,
'temperature' => $target_temperatures,
'time_to_target' => $this->last_status->device->{$serial_number}->time_to_target,
Add this:
'humidity' => $this->last_status->device->{$serial_number}->target_humidity, //added by Rick Ammazzini
'humidity_enabled' => $this->last_status->device->{$serial_number}->target_humidity_enabled //added by Rick Ammazzini
),
'serial_number' => $this->last_status->device->{$serial_number}->serial_number,
'scale' => $this->last_status->device->{$serial_number}->temperature_scale,
'location' => $structure,
'line_power_present' => $this->last_status->device->{$serial_number}->line_power_present,
'network' => $this->getDeviceNetworkInfo($serial_number),
'name' => !empty($this->last_status->shared->{$serial_number}->name) ? $this->last_status->shared->{$serial_number}->name : DEVICE_WITH_NO_NAME,
'where' => isset($this->last_status->device->{$serial_number}->where_id) ? isset($this->where_map[$this->last_status->device->{$serial_number}->where_id]) ? $this->where_map[$this->last_status->device->{$serial_number}->where_id] : $this->last_status->device->{$serial_number}->where_id : ""
);
if($this->last_status->device->{$serial_number}->has_humidifier) {
$infos->current_state->humidifier= $this->last_status->device->{$serial_number}->humidifier_state;
$infos->target->humidity = $this->last_status->device->{$serial_number}->target_humidity;
$infos->target->humidity_enabled = $this->last_status->device->{$serial_number}->target_humidity_enabled;
}
return $infos;
}

Related

Bitrix24 webhook/REST API

I'd like to create TASK in bitrix24 with webhook URL. Almost everything is fine (task name, description, responsible, deadline etc...) the only problem is with field with several users (Observers and Participants). I don't know how to add these parameters to the URL :( The documentation is incomplete.
The solution is easy, I didn't see your code but per the API doc, you need to encode the JSON array of fields as parameters into the GET request: this will help you: How should I put json in GET request?
A better approach would be using POST to submit data instead of GET, this way you don't need to do the above, you can send the array as it.
This is the API doc you need to follow:
https://training.bitrix24.com/rest_help/tasks/task/tasks/tasks_task_add.php
Here is the array of fields you can set as the "fields" parameter when creating a task:
https://training.bitrix24.com/rest_help/tasks/fields.php
Example of an array of fields:
Array
(
[TITLE] => Process lead: +19196299012 - Outgoing call (set from business process)
[STAGE_ID] => 0
[DESCRIPTION] => Process lead: +19196299012 - Outgoing call
[DEADLINE] =>
[START_DATE_PLAN] =>
[END_DATE_PLAN] =>
[PRIORITY] => 0
[ACCOMPLICES] => Array
(
)
[AUDITORS] => Array
(
)
[TAGS] => Array
(
)
[ALLOW_CHANGE_DEADLINE] => Y
[ALLOW_CHANGE_DEADLINE_COUNT] =>
[ALLOW_CHANGE_DEADLINE_COUNT_VALUE] =>
[ALLOW_CHANGE_DEADLINE_MAXTIME] =>
[ALLOW_CHANGE_DEADLINE_MAXTIME_VALUE] =>
[TASK_CONTROL] => Y
[PARENT_ID] =>
[DEPENDS_ON] => Array
(
)
[GROUP_ID] => 0
[RESPONSIBLE_ID] => 1
[TIME_ESTIMATE] => 0
[ID] => 130
[CREATED_BY] => 1
[DESCRIPTION_IN_BBCODE] => Y
[DECLINE_REASON] =>
[REAL_STATUS] => 2
[STATUS] => 2
[RESPONSIBLE_NAME] => Mohamed Ali
[RESPONSIBLE_LAST_NAME] => Ouled Ameur
[RESPONSIBLE_SECOND_NAME] =>
[DATE_START] =>
[DURATION_FACT] =>
[DURATION_PLAN] =>
[DURATION_TYPE] => days
[CREATED_BY_NAME] => Mohamed Ali
[CREATED_BY_LAST_NAME] => Ouled Ameur
[CREATED_BY_SECOND_NAME] =>
[CREATED_DATE] => 2021-06-26T08:12:39+03:00
[CHANGED_BY] => 1
[CHANGED_DATE] => 2021-06-26T08:12:39+03:00
[STATUS_CHANGED_BY] => 1
[STATUS_CHANGED_DATE] => 2021-06-26T08:12:39+03:00
[CLOSED_BY] =>
[CLOSED_DATE] =>
[ACTIVITY_DATE] => 2021-06-26T08:12:39+03:00
[GUID] => {bcd84631-6c08-4124-8db2-7cfe90628dc1}
[MARK] =>
[VIEWED_DATE] => 2021-06-28T09:09:17+03:00
[TIME_SPENT_IN_LOGS] =>
[FAVORITE] => N
[ALLOW_TIME_TRACKING] => N
[MATCH_WORK_TIME] => N
[ADD_IN_REPORT] => Y
[FORUM_ID] =>
[FORUM_TOPIC_ID] =>
[COMMENTS_COUNT] =>
[SITE_ID] => s1
[SUBORDINATE] => Y
[FORKED_BY_TEMPLATE_ID] =>
[MULTITASK] => N
[UF_CRM_TASK] => Array
(
[0] => L_38
[1] => L_38
)
[UF_MAIL_MESSAGE] =>
[UF_TASK_WEBDAV_FILES] =>
)
to set more then one, you can use this. In the array every usernumber
$accomplice = ['1','2'];
$createTask = CRest::call('tasks.task.add',
...
'ACCOMPLICES' => $accomplice,
...

add customerGroup to article with PUT call

Im trying to update my articles and add a excluded CustomerGroup.
Since the documentation is pretty bad for that part I try to find some more help here.
I put this [] Object to shopware for example
[data] => Array
(
[id] => 1460
[mainDetailId] => 1460
[supplierId] => 1
[taxId] => 1
[filterGroupId] => 1
[name] => XXX
[added] => 2018-01-26T00:00:00+0100
[active] => 1
[pseudoSales] => 0
[changed] => 2018-02-09T15:22:35+0100
[lastStock] => 1
[mode] => 0
[mainDetail] => Array
(
[id] => 1460
[articleId] => 1460
[...] => ...
)
[customerGroups] => Array
(
[0] => Array
(
[customerGroupKey] => EK
)
)
)
The important part is the [customerGroups] array which i add and which doesnt work for me.
You should create a customer group before you use the "groupKey", use "CustomerGroup" api resource for this (see /engine/Shopware/Components/Api/Resource/CustomerGroup.php).

How to apply extension hook in expressionengine

I'm working on expressionengine v2 and i have followed the docs at their site to make extension hooks, i've created a file in third party folder and install that from cp(control panel). Now i don't know how to call that function using hook just to show some text.
$hooks = array(
'after_channel_entry_insert' => 'after_channel_entry_insert',
'before_channel_entry_update' => 'before_channel_entry_update'
);
foreach ($hooks as $hook_name => $method_name) {
$data[] = array(
'class' => __CLASS__,
'method' => $method_name,
'hook' => $hook_name,
'settings' => serialize($this->settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
}
//insert data in extension table
ee()->db->insert_batch('extensions', $data);
//now i want to call this function on hook
function after_channel_entry_insert($data = '') {
die('after_channel_entry_insert');
}

How to create multilingual menu link programmatically in Drupal 7

I'm trying to create the menu link programmatically. But its not working where source language is other than english. Here is my code.
$language_list = language_list();
foreach ($language_list as $language_code => $language_object) {
$menu_item = array(
'link_title' => t('Fruit'),
'menu_name' => 'menu-main-footer',
'customized' => 1,
'link_path' => $custom_path,
'language' => $language_code,
'weight' => 30,
);
menu_link_save($menu_item);
}
Any one have some idea on this?
I changed my code. And it work for me.
// Create menu translation set.
$menu_translation_set = i18n_translation_set_create('menu_link');
// Create translated menu link for all site enable language.
$language_list = language_list();
foreach ($language_list as $language_code => $language_object) {
// Add Fruit link in menu-main-footer.
// 'change-fruit' is node title.
$fruit_path = drupal_get_normal_path('change-fruit', $language_code);
if (!menu_link_get_preferred($fruit_path, 'menu-main-footer')) {
$menu_item = array(
'link_title' => t('fruit'),
'menu_name' => 'menu-main-footer',
'customized' => 1,
'link_path' => $fruit_path,
'language' => $language_code,
'weight' => 30,
'i18n_tsid' => $menu_translation_set->tsid,
);
menu_link_save($menu_item);
$menu_translation_set->add_item($menu_item, $language_code);
$menu_translation_set->save();
}
}
May be helpful to other.
I had to migrate an old menu to a new one with its localized translations so here is what I did :
$old_name = 'menu-old';
$new_name = 'menu-new';
$old_menu = menu_load($old_name);
if(isset($old_menu)){
$old_mlids = db_query("SELECT mlid from {menu_links} WHERE menu_name=:menu_name", array(':menu_name' => $old_name))->fetchAll();
if(!empty($old_mlids)){
// Clean existing items in new menu.
$new_mlids = db_query("SELECT mlid from {menu_links} WHERE menu_name=:menu_name", array(':menu_name' => $new_name))->fetchAll();
if(!empty($new_mlids)){
foreach($new_mlids as $record){
menu_link_delete($record->mlid);
}
}
// Copy old to new menu.
foreach($old_mlids as $record){
$old_menu_item = menu_link_load($record->mlid);
$new_menu_item_config = array(
'link_title' => $old_menu_item['link_title'],
'link_path' => $old_menu_item['link_path'],
'menu_name' => $new_name,
'customized' => 1,
'weight' => $old_menu_item['weight'],
'expanded' => $old_menu_item['expanded'],
'options' => $old_menu_item['options'],
);
$new_menu_item = $new_menu_item_config;
menu_link_save($new_menu_item);
// Migrate translations.
$languages = language_list('enabled')[1];
foreach($languages as $lang_code => $language_object){
if ($lang_code == language_default('language')) {
continue;
}
$translation_value = i18n_string_translate('menu:item:'.$old_menu_item['mlid'].':title', $old_menu_item['link_title'], array('langcode' => $lang_code));
if($translation_value != $old_menu_item['link_title']){
i18n_string_translation_update('menu:item:'.$new_menu_item['mlid'].':title', $translation_value, $lang_code, $old_menu_item['link_title']);
}
}
}
}
// Delete old menu.
menu_delete(array('menu_name' => $old_name));
}

Yii2 Pagination Issue on Union

I am trying to use Pagination after union of two queries the pagination does not seems to work. However if I try to make one queries without union it works.
The below are the queries.Please help.
//First Query
$first_second = $this->find()->select($strcolumn.', p.featured_name')->from(MYDIRECTORY::tableName().' j')->join('INNER JOIN' ,MYDIRECTORYFEATUREDCLASS::tableName().' p', 'p.featurer_id = j.listdetails_featured_frid')->where(['listdetails_list_frid' => $id['list_id']])->andWhere(['<=', 'listdetails_featured_frid', 2])->andWhere(['listdetails_list_flag' => MYDIRECTORYCLASS::STATUS_ACTIVE])->orderBy(['listdetails_featured_frid'=>SORT_ASC,'listdetails_list_pos'=>new Expression('rand()')]);
//Second Query
$second_list = $this->find()->select($strcolumn.', p.featured_name')->from(MYDIRECTORYCLASS::tableName().' j')->join('INNER JOIN' ,MYDIRECTORYFEATUREDCLASS::tableName().' p', 'p.featurer_id = j.listdetails_featured_frid')->where(['listdetails_list_frid' => $id['list_id']])->andWhere(['>', 'listdetails_featured_frid', 2])->andWhere(['listdetails_list_flag' => MYDIRECTORYCLASS::STATUS_ACTIVE])->orderBy(['listdetails_featured_frid'=>SORT_ASC,'listdetails_list_medname'=>SORT_ASC]);
//Joined Union Query
$joinedquerys=$first_second->union($second_list);
$countQuery = clone $joinedquerys;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => \Yii::$app->params['pagination_limit'],'defaultPageSize' => \Yii::$app->params['pagination_limit'],'forcePageParam' => false,'params' => ['page' => \Yii::$app->request->get('page', 1)] ]);
$resultArray = $joinedquerys->offset($pages->offset)->limit($pages->limit)->asArray()->all();
return $this->render('listing', [
"mylisting" => $resultArray,
"pagination" => $pages
]);
While using the pagination as below , the pagination seems to not work?Any help will be greatly appreciated
echo LinkPager::widget([
'pagination' => $pagination,
'options' => ['class' => 'paginate pag2 clearfix'],
'registerLinkTags' => true,
'prevPageLabel' => \YII::$app->params['linker_page_btn_prev'],
'nextPageLabel' => \YII::$app->params['linker_page_btn_next'],
'maxButtonCount' => \YII::$app->params['linker_page_btn_count'],
'activePageCssClass' => 'current',
'nextPageCssClass' => 'next'
]);
you could use dataProvider
<?php
$joinedquerys=$first_second->union($second_list);
$dataProvider = new SqlDataProvider([
'sql' => $joinedquerys,
]);
?>
I had the same problem, but in addition I had to use the ActiveDataProvider. To achieve this I had to do the following:
$joinedQuery = $first_second->union($second_list);
$dirQuery = MYDIRECTORY::find()->from(['directories' => $joinedQuery]);
$provider = new ActiveDataProvider([
'query' => $dirQuery,
]);
Hope this helps someone :)

Resources