Is nest offline when I'm away? - nest-api

I've written a combination of bash and php script, which will read the Nest every 5min. I read the values like temp and desired temp and check if it is heating.
This seems to work well as long as the Nest is NOT in "Away" status. When I'm home, I can see a log entry every 5min, but about 45min after I've left my home, the logs don't show any entries anymore. As soon as I get home, I see new entries in the log.
Is it the Away status that is bothering me? Can I somehow change this behaviour?

Being in home or away mode has no effect on the API's responsiveness. You may want to check how you're logging your data

Found why my scripts failed. When the Nest is set to away (either manual or auto), the return object changes.
Away is active:
[target] => stdClass Object
(
[mode] => heat
[temperature] => 18
[time_to_target] => 0
)
Away is not active:
[target] => stdClass Object
(
[mode] => range
[temperature] => Array
(
[0] => 10.111
[1] => 24.444
)
[time_to_target] => 0
)
So my script is tripping over the array in temperature that is suddenly returned.

Related

Which Association to add to get customfield added to tax

I am trying to get a customfield in an order inside of the price->calculatedTaxes object which I added to the tax entity.
I dont know what association I have to use to add the customfield to the object. The object is looking like this:
[price:protected] => Shopware\Core\Checkout\Cart\Price\Struct\CartPrice Object
(
[netPrice:protected] => 125.47
[totalPrice:protected] => 128.9
[calculatedTaxes:protected] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection Object
(
[elements:protected] => Array
(
[0] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTax Object
(
[tax:protected] => 0
[taxRate:protected] => 0
[price:protected] => 107.41666666667
[extensions:protected] => Array
(
)
)
[19] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTax Object
(
[tax:protected] => 3.43
[taxRate:protected] => 19
[price:protected] => 21.483333333333
[extensions:protected] => Array
(
)
)
)
This is my criteria for the orderdata:
$criteria->addFilter(new EqualsFilter('id', $orderId))
->addAssociation('deliveries')
->addAssociation('addresses')
->addAssociation('addresses.country')
->addAssociation('deliveries.shippingOrderAddress.country')
->addAssociation('orderCustomer.salutation')
->addAssociation('transactions.paymentMethod')
->addAssociation('lineItems')
->addAssociation('currency');
Is this even possible or am I completely wrong and this needs to be done completely different to add the customfield to that element?
Thanks
Danny
The CalculatedTax objects your are referring to are not at all direct descendants of the TaxEntity you added your custom fields to. These objects are constructed during runtime through a series of calls where only at the very beginning of the stack an instance of TaxEntity would be present.
There are quite a few levels in the stack between these two instances in fact. Without going into too much details, maybe have a look at the SalesChannelContextFactory where a TaxRuleCollection is stored in the current sales channel context. It has to happen this early on in the stack, since depending on the current user/customer different taxes may be applied, be it net/gross or different tax rates all together.
After all it depends on what you want to do with the data stored in the custom fields. If you need the data for altering the calculation of taxes you might want to store them early on with the creation of the sales channel context as an extension.

Run shell script within oracle procedure

I have a script /home/load_data.sh that I want to run from my procedure, only if my IF statement is not satisfied:
create or replace
PROCEDURE RD_ODS_REFRESH_LOG
IS
BEGIN
FOR i IN
(
SELECT RESULT FROM USERS
WHERE trunc(COMPLETED_DATE) = trunc(SYSDATE -1)
)
LOOP
IF i.RESULT = 'FAIL'
THEN
EMAIL
(
'ANGELINA1984#aol.com',
'daily Refresh report',
'FAILED',
'Todays daily Refresh Failed.'
);
ELSE
SYS.DBMS_SCHEDULER.create_job
(
job_name => 'RD_ODS_REFRESH_LOG',
job_action => '/home/load_data.sh',
job_type => 'executable',
number_of_arguments => 0,
start_date => SYSDATE,
repeat_interval => 'FREQ=SECONDLY; INTERVAL=1',
enabled => FALSE,
auto_drop => FALSE,
comments => 'run load data shell script'
);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
(
name => 'RD_ODS_REFRESH_LOG',
attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_FULL
);
SYS.DBMS_SCHEDULER.enable
(
name => 'RD_ODS_REFRESH_LOG'
);
END IF;
END LOOP;
END RD_ODS_REFRESH_LOG;
I am wondering how to put all of this together so that when IF is not satisfied, it jumps to ELSE statement and it executes the above code?
Can I use something else other than SCHEDULER? After all all I want is to be able to run my /home/load_data.sh script in ELSE case.
I use Oracle11g...
It might be worth going in the other direction and making more use of scheduler, in particular of scheduler chains.
I say this because the sort of flow control that you show here -- do X if fail, otherwise do Y -- is tiresome to code, and with a scheduler chain you simply specify the next step to run if particular steps raise an error or not.
Once you get used to it it's pretty pain free, and very flexible and reliable -- I ran scheduler chains to load a data warehouse, executing the load and transform job every 60 seconds 24 hours a day for over a year, stopping the chains for maintenance, starting them again when maintenance is over, and all you need are a few monitoring and control scripts.

Telerik MVC Grid Filter

I was using Telerik MVC Grid in my project. I just wanted to change the dropdown value orders a bit. I googled for the requirement and found the filter dropdown options are handled by **telerik.grid.min.js file. But, I dont know how can i change the order from
Options by Default
Is Equal to
Is not equal to
Starts with
Contains
Does not contain
Ends with
Change to the below format
Contains
Does not contain
Starts with
Ends with
Is Equal to
Is not equal to
Can anybody tell me the possibilities that i can change the order of filter dropdown box ..
Thanks,
You can do it by JQuery simply by some codes like this :
$('#GRIDID').find(".t-filter").click(function () {
setTimeout(function () {
$(".t-filter-operator").html('<option value="substringof">Contains</option><option value="notsubstringof">Does not contain</option>');
});
});
NOTE : the above code is a sample, you should do a process to check what operators you have and then repopulate the items in desired order. You can find all allowed "option" tags by inspecting the rendered grid.
The easy way (if you're using MVC razor syntax)
#Html.Kendo().Grid<Model>().Columns(columns =>
{
columns.Bound(x => x.variableName);
})
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains").DoesNotContain("DoesNotContain").WhateverYouNeed)
.ForEnums( dat => dat.Clear()
.IsEqualTo("Is Equal To"))
))
Here, the Clear() empties the options in the filter and then you can add the ones you want or even create your own custom ones there, simply place them there in the order that you want.
Have fun!

ExpressionEngine 1 to ExpressionEngine 2 Upgrade with nGen File Field

I'm about to do an ExpressionEngine v1 to ExpressionEngine v2 Upgrade with lots of data stored in nGen File Fields.
What are the steps I need to take pre and post upgrade to get this data working correctly with the EE2 SafeCracker File field?
After upgrading to EE2, find each ex-nGen File field and change its Field Type to File, and run this SQL query:
UPDATE exp_channel_data
SET field_id_X = CONCAT('{filedir_Y}', field_id_X)
WHERE field_id_X != ''
AND field_id_X NOT LIKE '{filedir_%'
Replace “X” with your File field’s ID (you can get that from exp_channel_fields), and Y with the upload preference ID that nGen File Field was set to.
If you had Matrix installed in EE1, upgrade to Matrix 2/EE2 and do the same for any ex-nGen File columns, using this SQL query instead:
UPDATE exp_matrix_data
SET col_id_X = CONCAT('{filedir_Y}', col_id_X)
WHERE col_id_X != ''
AND col_id_X NOT LIKE '{filedir_%'
Again, X == your Matrix column ID (you can get that from exp_matrix_cols), and Y == your upload preference ID.
(Credit goes to Rob Sanchez, of course.)
I wrote this for a site as well - no matrix support in here but it works quickly and correctly for regular fields.
For the array, the left column is each field ID that you changed to text pre-upgrade, and needs to be changed to file post upgrade, and the right side is the X of filedir_X for the file upload dir you want to attach to the field
// Insert file upload directories
$array = array(
'16' => '1',
'22' => '1',
'121' => '3',
'58' => '1',
'67' => '1',
'68' => '1',
'71' => '1',
'76' => '1',
'78' => '1',
'94' => '1',
'99' => '1',
'108' => '3',
'109' => '3',
'110' => '3',
'139' => '1'
);
foreach($array as $field_id => $dir_id) {
$q_entries = $this->EE->db->query("SELECT entry_id, field_id_{$field_id} as 'field' from exp_channel_data where field_id_{$field_id} != '' order by entry_id asc");
if ($q_entries->num_rows() > 0) {
echo '<h3>field_id_'.$field_id.'</h3>';
foreach($q_entries->result_array() as $entry) {
echo $entry['entry_id'];
$filename = trim('{filedir_'.$dir_id.'}'.$entry['field']);
echo ' - '.$filename.'<br/>';
$data = array(
'field_id_'.$field_id => $filename,
);
$sql = $this->EE->db->update_string('exp_channel_data', $data, "entry_id = '{$entry['entry_id']}'");
$this->EE->db->query($sql);
}
}
}
echo 'done';
I have an entire blog post about this which is based off of my experience and the thread that Brandon referenced in his answer. Blog post here.
I've posted something to GitHub that should help anyone facing this process. It's EE1 template code (it needs PHP enabled on either output or input) that shows two things:
Firstly, it displays a tabular overview of all custom fields in the system. This is for reference, to help when you're trying to find all instances of a certain fieldtype. It covers normal EE fields, Fieldframe fieldtypes, and even Matrix columns.
Secondly, each time an nGen File field is encountered, the template generates the MySQL code you'll need to use (after you upgrade to EE2) to alter the data in said fields to the format required by EE2's native File field. These queries are only displayed, not run. The idea is that you save the queries somewhere, run the EE1->EE2 upgrade, and then run the saved queries when ready.
Needless to say, backup, Backup, BACKUP. The template code does not modify your site database in any way, and has been tested and displays what its supposed to just fine. However, while the MySQL queries it generates (for you to copy and manually run later) match what Brandon recommended in his answer, I have yet to actually test those queries in action.
The best way to do this is to proceed carefully and make backups of your database at each step of the way. I have previously written a blog post on this but will elaborate further.
Step 1: Before running your upgrade change all ngen field types to text, don't worry the data won't be lost.
Step 2: Next upgrade ExpressionEngine as per the official docs and then go back into each field and change them to the first party file type.
The next step involves a little bit of database manipulation, but it's just copying and paste so don't worry.
Step 3: Do make a back up of your database before you proceed just in case.
Step 4: This next step depends whether your original nGen file field was in a standard Channel Field or a Matrix Field.
Now go into your database and Replace “X” with your File field’s ID (you can get that from exp_channel_fields), and Y with the upload preference ID that nGen File Field was set to.
(To find your upload preference ID in your control panel, go to Content > Files > File Upload Preferences. Choose the ID column on the left that matches the file upload location.)
4a: If updating standard Channel Fields, use this query
UPDATE exp_channel_data
SET field_id_X = CONCAT('{filedir_Y}', field_id_X)
WHERE field_id_X != ''
AND field_id_X NOT LIKE '{filedir_%'
4b: For matrix, fields run this query instead
UPDATE exp_matrix_data
SET col_id_X = CONCAT('{filedir_Y}', col_id_X)
WHERE col_id_X != ''
AND col_id_X NOT LIKE '{filedir_%'
X == your Matrix column ID (you can get that from exp_matrix_cols), and Y == your upload preference ID.
Credit to Brandon Kelly and Rob Sanchez.
Additionally, the same procedure can be used for other add-ons that don't exist in EE2. Convert to text before the upgrade and then convert to a new equivalent field type post upgrade if needed. For more help: Click here

Theming a node/add form in Drupal 6

I have a statement in my template.php file that directs to a custom node-myccktype.tpl.php. I've added some DIV's so that I can have a two column node/add form, but now I'm trying to find print my fields, but can't seem to get it.
I'm basically using something like this:
<?php print form_render($form['field_sr_minutes']); ?>
which I came across on a Drupal Blog, but I get call to undefined function "form_render"
I am using the var_dump to get the the array below, how can I print my node title(subject) field without printing everything else? This way I can put each form field in the column I want Instead of the standard vertical drupal form.
Array
(
[0] => Array
(
[#type] => textfield
[#title] => Subject
[#required] => 1
[#default_value] =>
[#maxlength] => 255
[#weight] => -5
[#post] => Array
(
)
[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => title
)
[#array_parents] => Array
(
[0] => title
)
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)
[#input] => 1
[#size] => 60
[#autocomplete_path] =>
[#process] => Array
(
[0] => form_expand_ahah
)
[#name] => title
[#id] => edit-title
[#value] =>
[#defaults_loaded] => 1
[#sorted] => 1
)
Sorry. Because of your .tpl file name I thought that you were trying to theme a node view. For forms, the right function is not form_render but drupal_render. You can basically write things like echo drupal_render($form['field_sr_minutes']) . In the very end, remember to do a drupal_render($form) to render all the remaining things which you have not rendered by hand. This will be required to have the form working correctly.
Old Answer
The node.tpl.php and other content
type specific .tpl.php get passed the
full node object in $node. Try doing
a
drupal_set_message(print_r($node,TRUE))
on top of your tpl file. From that you
can figure out the exact path of the
values you need to print.
For example, title of the node will be
available in $node->title. However you
should be careful to always use
check_plain if you are going to
print user submitted values. For CCK
fields, you can find the already
filtered values in $node-><field
name>[0][view].

Resources