Beginners guide to graphing Evohome temperatures using python and plot.ly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Bill M
    Automated Home Jr Member
    • Nov 2015
    • 10

    Beginners guide to graphing Evohome temperatures using python and plot.ly

    First of all, I may have a technical background, but that is many years behind me now! However, I was really interested in accessing the API and producing temperature graphs for Evohome.
    I read all the posts on here about Python and plot.ly and it took me a long time to understand it with tutorials etc and get it working. Now that I have, I thought I would share my “idiots guide” whilst at the same time acknowledging the excellent work by others who worked it all out in the first place!

    So, the steps are:

    1 Install Python
    Download and Install Python 2.7


    Make sure you select option to add Python.exe to PATH
    (you will need to reboot to pick this up in your settings, if you don’t know how to add this manually)


    2. Install the relevant Python modules to support what we are trying to do
    Install pip, setuptools, and wheel
    • Download get-pip.py from https://bootstrap.pypa.io/get-pip.py and save to your C:\Python27 folder.
    • At the command prompt switch to the C:\Python27 folder and run:

    python get-pip.py

    This will install or upgrade pip. Additionally, it will install setuptools and wheel if they’re not installed already. This is explained here:
    [URL="http://python-packaging-user-guide.readthedocs.org/en/latest/installing/"]


    Now that the above is installed the rest of the modules are easy to install as they will be automatically retrieved, downloaded and installed when you type the following at the Command Prompt:
    Pip install requests
    Note: The requests module is explained here: http://docs.python-requests.org/en/master/

    Pip install plotly
    Note plot.ly is the online graphing and is explained here: https://plot.ly/python/getting-started/ and here https://github.com/PieterVO/EvohomeTemperature

    Pip install evohomeclient
    Note this is put together by some excellent work by members on this forum and the details are here



    More info here if you are curious:
    http://python-packaging-user-guide.r...st/installing/
    ○ The requests module is explained here: http://docs.python-requests.org/en/master/
    ○ Installing modules in general is covered here: http://programminghistorian.org/less...on-modules-pip
    http://www.wikihow.com/Install-Pytho...s-on-Windows-7


    3. Evohome Client
    Now you can play with the python scripts like I did. If you open IDLE (Python GUI) which was installed with Python you can paste the text in any of these examples here:

    Don’t forget to replace your evohome username (email address) and password to get it working.
    Say you save it as test.py, then just run python test py from the command prompt
    This will start reporting temperatures of your zones back to your screen. Initially I captured them all to a file and imported into Excel as a CSV file and made a pivot table. This was great, until I discovered plot.ly….


    4. plot.ly
    This is an on-line graphing too. If you create a free account and follow the instructions here https://github.com/PieterVO/EvohomeTemperature with the config.ini file to enter your evohome username and password along with the stream IDs from plot.ly account, you can forget excel. This works beautifully and you can even create dashboards with all graphs on the same page.


    5. Bear in mind gathering the date is a repeating cycle, running a python script from a DOS prompt for as long as you want to gather and graph date. It means your computer is on constantly. I have read about using raspberry pi to do this, but I haven’t go that far. Just happy with the graphs and knowing I am saving energy and money!!
  • Cchris
    Automated Home Sr Member
    • Nov 2015
    • 95

    #2
    Thanks for sharing - this looks really good and Im hoping to get the time to try this out.

    My holy grail is being able to control the evohome from scripts on the PC, and then link this with voice recognition software. I have the vision of walking into the house and saying "Hot water on for an hour please", or "Set the lounge heating to 21 degrees until 11pm" and the system knowing what to do.

    I am almost certain this is technically possible, but finding the right tools for the job is difficult. I do like IT and have a decent knowledge of it - but actual coding is stretching my knowledge - Id be burried in google to try and learn that part.

    Id also like the above to be able to control lighting too, which as Siri can talk to philips hue lights I know is posible, but getting the whole thing working in harmony would just be brilliant.

    Comment

    • zcapr17
      Automated Home Jr Member
      • Oct 2014
      • 20

      #3
      Originally posted by Cchris View Post
      My holy grail is being able to control the evohome from scripts on the PC, and then link this with voice recognition software. I have the vision of walking into the house and saying "Hot water on for an hour please", or "Set the lounge heating to 21 degrees until 11pm" and the system knowing what to do.
      You can do this right now with Siri, Homebridge, and a Samsung SmartThings Hub. Minimal coding required.

      See here: https://community.smartthings.com/t/...ridge/16701/27
      (to get the Evohome-SmartThings integration, you need to sign up to the beta, but it should be public any day now).

      I use two HomeKit scenes in conjunction with "Rules Engine" (a SmartThings SmartApp)...
      - When going to bed I can say "Siri, I'm going to work tomorrow" and SmartThings will set my house in 'Working Away' mode, which means it will heat my bedroom and turn on my bathroom towel rail at the right time in the morning.
      - Alternatively, I can say "Siri, I'm working from home tomorrow" and SmartThings will heat my bedroom at a later time and automatically heat my home office until 5pm.

      Note, I rarely find the need to issue specific commands like "Set Lounge Thermostat to 21 degrees until 11pm". If SmartThings detects I'm in a room outside of my normal schedule (via the motion sensors in each room), it automatically extends the Evohome heating in that room until I leave. At a macro-location level, if I go more than a few miles from home, SmartThings will put Evohome in 'Away' mode, and when I leave work it will resume normal Evohome scheduling.

      HTH

      Z
      Last edited by zcapr17; 26 February 2016, 10:58 PM. Reason: Additional info on how I use Siri to control Evohome

      Comment

      • garmcqui
        Automated Home Guru
        • Jan 2015
        • 119

        #4
        Thank you for posting instructions - they're very clear. However I've been trying to get this working for hours now and keep getting an error.

        I've filled out the config.ini file as follows:

        #rename this file to config.ini

        [Plotly]

        Username: xxxxxxxx

        APIkey: xxxxxxxxxx

        [Evohome]

        Username: XXXXXXXXX@gmail.com

        Password: XXXXXXXX

        #same roomnames on Evohome system

        [Rooms]
        Living Room: XXXXXXXXXX

        Kitchen: XXXXXXXXXX


        However, on running the "EvohomeTemperature.py" file (by opening it in IDLE and running the module - is this the right way?) I get the following error:

        Traceback (most recent call last):
        File "C:\Python27\Myscripts\EvohomeTemperature-master\EvohomeTemperature.py", line 46, in <module>
        stream_id = Config.get('Rooms', device['name'])
        File "C:\Python27\lib\ConfigParser.py", line 618, in get
        raise NoOptionError(option, section)
        NoOptionError: No option '' in section: 'Rooms'


        I'm at a loss. Any ideas? Any advice appreciated.

        Comment

        • Bill M
          Automated Home Jr Member
          • Nov 2015
          • 10

          #5
          You need to run the script from a DOS Command Prompt. Change to the folder where you have saved the script and type python evohometemperature.py

          regarding the config.ini file, some pointers from my experience:
          - plotly APIkey can be found when you log in to your new plot.ly account, click your username, then settings and then the API key is on the left of the screen.
          - For your rooms, it is important to create an API stream token for each zone that you have set up on Evohome (don't just test it with a couple as it won't work!)
          - It is also important that you spell your rooms exactly as on EvoHome (I have my son's room as Matt's room and missed off the apostrophe in the .ini file and it failed!)

          Comment

          • garmcqui
            Automated Home Guru
            • Jan 2015
            • 119

            #6
            thanks for the quick reply...

            I've updated the config.ini file so it includes all 11 zones, all spelt perfectly and each with its own API stream token.

            I've ran the script from the command prompt, but am getting the same error:

            C:\EvohomeTemperature-master>python evohometemperature.py
            Traceback (most recent call last):
            File "evohometemperature.py", line 46, in <module>
            stream_id = Config.get('Rooms', device['name'])
            File "C:\Python27\lib\ConfigParser.py", line 618, in get
            raise NoOptionError(option, section)
            ConfigParser.NoOptionError: No option '' in section: 'Rooms'


            To me as a novice, it looks like the script isn't pulling something from the config file correctly (something to do with rooms?)

            This is the exact layout of my config.ini file - is it correct? There aren't any spaces where there's not meant to be?

            #rename this file to config.ini

            [Plotly]
            Username: xxxxxxxx
            APIkey: xxxxxxxxxx

            [Evohome]
            Username: xxxxxxxxxx@gmail.com
            Password: xxxxxxxx

            #same roomnames on Evohome system
            [Rooms]
            Living Room: xxxxxxxxxx
            Kitchen: xxxxxxxxxx
            Nursery: xxxxxxxxxx
            Study: xxxxxxxxxx
            Hallway: xxxxxxxxxx
            Master Bed: xxxxxxxxxx
            Spare Bed: xxxxxxxxxx
            Landing: xxxxxxxxxx
            Bathroom: xxxxxxxxxx
            En Suite: xxxxxxxxxx
            WC: xxxxxxxxxx

            Comment

            • Bill M
              Automated Home Jr Member
              • Nov 2015
              • 10

              #7
              Just checked this against my file and looks spot on. I can only guess it is the libraries that are not all installed.

              Try saving the following into a test.py file (using IDLE) and running it from the command prompt. Change the email and password to your evohome ones. It should just list your rooms and temperatures...



              import requests
              import json

              USERNAME = 'whatever@email.com'
              PASSWORD = 'password'

              url = 'https://rs.alarmnet.com/TotalConnectComfort/WebAPI/api/Session'
              postdata = {'Username':USERNAME,'Password':PASSWORD,'Applicat ionId':'91db1612-73fd-4500-91b2-e63b069b185c'}
              headers = {'content-type':'application/json'}

              response = requests.post(url,data=json.dumps(postdata),header s=headers)

              userData = json.loads(response.content)

              userId = userData['userInfo']['userID']
              sessionId = userData['sessionId']

              url = 'https://rs.alarmnet.com/TotalConnectComfort/WebAPI/api/locations?userId=%s&allData=True' % userId

              headers['sessionId'] = sessionId

              response = requests.get(url,data=json.dumps(postdata),headers =headers)

              fullData = json.loads(response.content)[0]

              for device in fullData['devices']:
              print device['thermostatModelType'], device['deviceID'], device['name'], device['thermostat']['indoorTemperature']

              Comment

              • garmcqui
                Automated Home Guru
                • Jan 2015
                • 119

                #8
                hmmm, when I run that I get:

                Traceback (most recent call last):
                File "C:\Python27\Myscripts\test.py", line 15, in <module>
                userId = userData['userInfo']['userID']
                TypeError: list indices must be integers, not str

                Comment

                • garmcqui
                  Automated Home Guru
                  • Jan 2015
                  • 119

                  #9
                  ignore that, got it to list the temperatures, not sure what I changed. But that works... does that help?

                  Comment

                  • Bill M
                    Automated Home Jr Member
                    • Nov 2015
                    • 10

                    #10
                    That's good. It shows that you have installed everything correctly (well the same as mine anyway!).
                    I seem to recall having a similar error at one point but that was because I tried it with just 2 rooms initially. Maybe create the config.ini file again from scratch? After that I am struggling as I had to google just about everything I learned to get this far...

                    Hopefully one of the experts will step in and help?

                    Comment

                    • garmcqui
                      Automated Home Guru
                      • Jan 2015
                      • 119

                      #11
                      Good stuff.
                      Just thinking - I've put all rooms in, but haven't put the Domestic Hot Water in - is this needed too?

                      Thanks for your help so far, this is exactly why I love forums like this.

                      Comment

                      • Bill M
                        Automated Home Jr Member
                        • Nov 2015
                        • 10

                        #12
                        That is probably it mate - needs to have all zones and the water (although I dont have that) is presumably set up as a zone too?

                        Comment

                        • garmcqui
                          Automated Home Guru
                          • Jan 2015
                          • 119

                          #13
                          I think it will be classed as a zone, yes. However, not sure what it's exact name would be.

                          Hmmm, will have a tinker. Cheers

                          Comment

                          • garmcqui
                            Automated Home Guru
                            • Jan 2015
                            • 119

                            #14
                            nope, still getting the same error

                            Can anyone advise what is happening?

                            Comment

                            • garmcqui
                              Automated Home Guru
                              • Jan 2015
                              • 119

                              #15
                              ok, finally got it working The problem was that the Evohomeclient was reporting the Hot Water zone's name as '', which was throwing python to throw a wobbly when it looked for '' in the config.ini file. There's no apparent way to change the name that is reported (Hot Water isn't editable like the other zones), so I've had to amend the code to use the device ID instead.

                              Here's the updated code, if it's useful for anyone...

                              # We make a plot for every room
                              for device in client.temperatures():
                              stream_id = Config.get('Rooms', device['id'])
                              stream = Stream(token=stream_id,
                              maxpoints=288
                              )
                              trace1 = Scatter(
                              x=[],
                              y=[],
                              mode='lines+markers',
                              line=Line(
                              shape='spline'
                              ),
                              stream = stream
                              )

                              data = Data([trace1])
                              layout = Layout(title=device['name'])
                              fig = Figure(data=data, layout=layout)
                              py.plot(fig, filename=device['name'], fileopt='extend')

                              # Infinite loop every 5 minutes, send temperatures to plotly
                              while True:

                              # Get current time and then send all thermostat readings to plotly
                              try:
                              client = EvohomeClient(USERNAME, PASSWORD)
                              from datetime import datetime
                              j=0
                              for device in client.temperatures():
                              stream_id = Config.get('Rooms', device['id'])
                              j+=1
                              s = py.Stream(stream_id)
                              s.open()
                              tijd = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                              temperatuur = float(device['temp'])
                              print tijd + " : " + device['name'] + " " + str(temperatuur)
                              s.write(dict(x=tijd ,y=temperatuur))
                              s.close()
                              print "Going to sleep for 5 minutes"
                              time.sleep(300)
                              except Exception, e:
                              print "An error occured! Trying again in 15 seconds"
                              print str(e)
                              time.sleep(15)


                              My next question - as you can see, the existing trace is plotting "device['temp']". I'd like to add a second trace to the same axes which plots "device['setpoint'] so they can be compared.

                              Any ideas?

                              Comment

                              Working...
                              X