Author Topic: Alternative Nest configuration/control -- with Python  (Read 3862 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Alternative Nest configuration/control -- with Python
« on: March 23, 2016, 03:40:42 PM »
This is an alternative to our Nest command collection posted here: http://voxcommando.com/forum/index.php?topic=1965.0.

In this version, I decided to put the Python plugin to use so you will need to have the Python plugin enabled.

The previously posted collection works great and is probably fine for most users, but it has a few limitations that I wanted to try to address, including:
  • improving how we refresh data from the Nest
  • automatically determining system information such as whether a device is using Fahrenheit or Celsius, so that temps can be reported in that measurement system
  • eliminating some of the complex & fallible regular expressions that were required to read the Nest data (because Python permits us to easily parse json)

The video tutorial in the other thread is still very helpful if you don't yet use Nest commands with VC. You should watch it in order to understand the whole setup process. However, there are a few minor variations when setting up this Python-enabled variation.

1. Put the attached Nest.py in your VC root directory.*
2. Import attached command collection to your tree.
3. Edit the Nest authorization command with your user/pwd info.
--
4. Save & exit the command tree, and then open it up again.
--
5. Execute commands marked 1, then 2, then 3 -- in order.
6. Save & exit the command tree.

Test commands. (You'll probably want to "show help" to see the commands.)

---
* If you are a seasoned VC user, feel free to put this in your \PY subfolder and then edit the command that loads this file to point to the correct filepath.
« Last Edit: March 25, 2016, 09:24:15 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Alternative Nest configuration/control -- with Python
« Reply #1 on: March 23, 2016, 03:44:22 PM »
Saaaaaweeeeeeet.

Lots of snakes in the Nest!

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Alternative Nest configuration/control -- with Python
« Reply #2 on: March 23, 2016, 03:56:16 PM »
This new version includes a few new features -- mostly for getting information about your Nest units and setup.

IMPORTANT NOTE:

Each time you ask for information about your Nest, the Python script will check whether VC's data is more than 3 minutes old. If so, it will refresh the data before responding to your query. If not, it will use the "old" data.

However, as with the other version, at any time you can manually refresh the data with the command "Update Nest data".

Some of the other new stuff:

You can now get target temperature information for your thermostats; VC will automatically determine whether your thermostat is in heat, cool, or heat/cool mode and give the appropriate target temperature or temperatures for the mode you are in.

You do not need to convert temperatures yourself if your units use Fahrenheit. This is done automatically. Indeed, if you have some units set to use Fahrenheit and others using Celsius, results will be faithful to the settings of the thermostat.

If you have more than one Nest environment (known in Nest terms as "structures" -- e.g. home & weekend retreat), now you can change the home/away status for each one. You can also get the home/away status for each.

You can check battery levels for all Protect devices, or ask about a specific Protect unit by name. There are 2 separate commands, depending on what you want to do.

---
A lot of these features are not necessarily things you'd want to do by voice command, but hopefully the information provided will help you to build your own solutions, if you want to create scenarios that incorporate getting or setting Nest data.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: Alternative Nest configuration/control -- with Python
« Reply #3 on: March 23, 2016, 07:13:37 PM »
:clap :clap :clap --- I will hold the clapping a bit   :P

when I run step no. 3 I get the following error in python:

Line: 54 >>
KeyError: device
« Last Edit: March 23, 2016, 07:28:07 PM by Haddood »
When Voice command gets tough, use hand gestures

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Alternative Nest configuration/control -- with Python
« Reply #4 on: March 23, 2016, 10:30:16 PM »
Did you save and close the tree (or save and do a quick restart) to register the new commands  before trying to run them?

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: Alternative Nest configuration/control -- with Python
« Reply #5 on: March 23, 2016, 11:14:00 PM »
Did you save and close the tree (or save and do a quick restart) to register the new commands  before trying to run them?
I did all ... the error happens with myNest.getdevices()
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Alternative Nest configuration/control -- with Python
« Reply #6 on: March 24, 2016, 08:07:38 AM »
Do you not have any Nest thermostats?
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Alternative Nest configuration/control -- with Python
« Reply #7 on: March 24, 2016, 08:22:19 AM »
I've updated the Python script. It should now properly generate payload xml whether or not you have both Protect and thermostat devices. Sorry for the oversight.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: Alternative Nest configuration/control -- with Python
« Reply #8 on: March 24, 2016, 10:43:10 PM »
you are totaly right, I have only one protect  device for the moment ... at one point they should be three ...
the new PY solved the error ... however the protect list is still empty ...
after running step 3, I end up with 5 files in nest folder ...
abodeList.xml
Nest_dev_status.txt
nest_therm_max-min.xml
protectist.xml ...

all have data, except for protectList ... I can see the name of the device in Nest_dev_status ... but not in the xml


I figured the problem; the device had no label ("description") so py return the id and blank, and probably because it raises an error it did not save properly ...

now i can  :clap :clap :clap :clap :clap and  ::bow ::bow ::bow ::bow

hopefully will have the time to look into a way to retrieve the messages ... then mark them read !! ...

as well now it seems the nest account with thermo or not ... can use the phone to figure if a user home (geofencing) and /or the the sensor in protect to see if there is someone home
« Last Edit: March 24, 2016, 11:14:32 PM by Haddood »
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Alternative Nest configuration/control -- with Python
« Reply #9 on: March 25, 2016, 08:22:58 AM »
Glad you figured it out.

One of the reasons I said in the first post that people should watch the video unless they've already used the Nest commands is because it explains a bunch of fundamental things -- including the fact that one needs to label one's devices.

There is no point in generating payload xml for a device that has no name. Users with one device might as well just enter their unit's ID directly into the command itself.

I don't have any Nest products here. This was just an intellectual exercise for me, using Nest's developer tools, and the most useful information to retrieve in my view was for the thermostats.

You may want to view your Nest data (Nest_dev_status.txt) in a json viewer (e.g., http://jsonviewer.stack.hu/) to find other variables of interest for the Protect.

I didn't make any commands or functions that access the geofencing info. You can add a function yourself, but obviously it's not going to automatically generate an event when an environment is occupied or not unless you are regularly polling the Protect. Maybe there's an IFTTT solution for that.
« Last Edit: March 25, 2016, 09:23:38 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: Alternative Nest configuration/control -- with Python
« Reply #10 on: March 25, 2016, 05:53:54 PM »
Not big on watching videos :bong or reading instructions :bong :bong
I will try to modify the py to make it read the location of protect if the label is empty ...
In my case since vc can sense when door opens ... That is when I can check the geofencing info...

Btw it is impressive u did all this without any nest hardware for testing!! :clap

Did u ever look at nest streaming API?

On a completely different page, It is been a while I am trying to use opencv with iron Python, without much success ... If you have time for another challange :D ... It will give VC the ability to recognize faces, logos and anything that we train it to "see"
http://www.emgu.com/wiki/index.php/Documentation
https://github.com/shiftcontrol/UnityOpenCV/tree/master/IronPython


« Last Edit: March 25, 2016, 06:01:50 PM by Haddood »
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Alternative Nest configuration/control -- with Python
« Reply #11 on: March 25, 2016, 06:21:47 PM »
Not big on watching videos :bong or reading instructions :bong :bong

I'm usually not patient enough for videos either. Of course, if things don't work after we've wasted x amount of time randomly trying things, then maybe it's time to suck it up and follow instructions. ;-)

Quote
I will try to modify the py to make it read the location of protect if the label is empty ...

I wouldn't waste your time. The location info is buried in a whole separate part of the structure. That's why I didn't use it. I recommend that you either give your Protect a name (you can use the location name again, I don't think it cares), or download the new version of the script that I posted this morning. It will generate payload xml with dummy names, for those who don't want to name their devices. At least that way you'll have the all-important ID value handy. Just edit the payload xml with your preferred device name.


But seriously, as a note to everyone reading this: If you don't know how to label your Protect via the Nest website (https://home.nest.com/), just fast forward to 1m30s in James's Nest tutorial and he shows you how to do it. It will take you 30 seconds, tops.

Quote
Did u ever look at nest streaming API?

The whole Firebase thing is too much to deal with. If someone with actual Nest products wants to tackle that in order to try to get events happening on their systems, all the power to them.

Quote
On a completely different page, It is been a while I am trying to use opencv with iron Python, without much success ...

Haven't heard of it. I can take a look, but obviously no promises. :)
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)