Results 1 to 6 of 6

Thread: Logging Evohome - yet another topic!

  1. #1
    Automated Home Lurker
    Join Date
    Dec 2017
    Posts
    6

    Default Logging Evohome - yet another topic!

    Hi all,

    Firstly, let me be clear that I know little about coding, i'm at the beginning of a what seems to be a very steep learning curve so go easy! My background involves hammers and not keyboards!

    I have a Raspberry Pi (3) with the hope of learning how to do some basic coding and the first project I have undertaken is to log all of my temperatures in Evohome. I found the following script from a kind poster on this very forum, entered it into a Python 3 environment and keep coming up with the following error. I understand what it is trying to say but I do not understand how to fix it. Can anyone offer any advice.

    Traceback (most recent call last):
    File "/home/pi/USBHDD/evohome.py", line 18, in <module>
    userinfo = json.loads(response.content)
    File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
    TypeError: the JSON object must be str, not 'bytes'

    Code below:
    Code:
    # Script to monitor and read temperatures from Honeywell EvoHome Web API
    
    # Load required libraries
    import requests
    import json
    import datetime
    import time
    
    # Ser your login details in the 2 fields below
    USERNAME = '########@gmail.com'
    PASSWORD = '########'
    
    # Initial JSON POST to the website to return your userdata
    url = 'https://rs.alarmnet.com/TotalConnectComfort/WebAPI/api/Session'
    postdata = {'Username':USERNAME, 'Password':PASSWORD, 'ApplicationId':'91db1612-73fd-4500-91b2-e63b069b185c'}
    headers = {'content-type':'application/json'}
    response = requests.post(url,data=json.dumps(postdata),headers=headers)
    userinfo = json.loads(response.content)
    
    # Extract the sessionId and your userid from the response
    userid = userinfo['userInfo']['userID']
    sessionId = userinfo['sessionId']
    
    # Next, using your userid, get all the data back about your site
    # Print out the headers for our temperatures, this let's us input to .csv file easier for charts
    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]
    (print) ('Evotemps', 'Evohometemps.csv')
    for device in fullData['devices']:
        print (device['name'],',',)
    print
    time.sleep (5)
    
    # Infinite loop every 5 minutes output temperatures
    while True:
    # Next, using your userid, get all the data back about your site
        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]
    
    # Get current time and then print all thermostat readings out
    from datetime import datetime
    print ,datetime.datetime.now().strftime('%H:%M:%S'),',',
    for device in fullData['devices']:
        print (device['thermostat']['indoorTemperature'],',',)
    print
    time.sleep(300)
    Can anyone help? I've tried adding .decode('utf-8') to the end of userinfo = json.loads(response.content) but no luck either.

  2. #2
    Automated Home Legend
    Join Date
    Sep 2014
    Location
    Scotland
    Posts
    2,033

    Default

    Instead of trying to reinvent the wheel making the raw http API calls directly in your script, you're better off using watchforstock's evohome client python bindings:

    https://github.com/watchforstock/evohome-client

    All of the minutia of how to send queries to the server and parse the responses is handled for you in the library allowing you to focus on what you really want - retrieving data or sending commands.

    Here is an example of just how easy it is to use, polling for and printing all zone temperature information using the V1 API, which provides high resolution temperature readings:

    Code:
    #!/usr/bin/python
    
    from evohomeclient import EvohomeClient
    
    client = EvohomeClient('email', 'password')
    
    for device in client.temperatures():
        print device
    I'd recommend you use the V2 API for everything except retrieving measured zone temperatures, which have higher resolution using the V1 API above. watchforstock's library supports both API's.
    Last edited by DBMandrake; 30th December 2017 at 09:28 PM.

  3. #3
    Automated Home Jr Member
    Join Date
    Oct 2016
    Location
    Cambridge
    Posts
    23

    Default

    As DBMandrake mentioned, you are better off using the existing Evohome Python modules.

    As you are using Python 3.x, you will need to make a small adjustment to the Python 2.x code. The print statement has now been replaced with a print() function in Python 3.0:

    Code:
    from evohomeclient import EvohomeClient
    
    client = EvohomeClient('email', 'password')
    
    for device in client.temperatures():
       print(device)
    Calling the client.temperatures() function returns a dictionary for each device, which includes the sensor ID, the name of the sensor, the type of sensor and the current temperature reading:

    Code:
    {'thermostat': 'EMEA_ZONE', 'id': 2039413, 'name': 'Bedroom 1', 'temp': 18.68, 'setpoint': 15.5}
    {'thermostat': 'EMEA_ZONE', 'id': 2039413, 'name': 'Kitchen', 'temp': 15.97, 'setpoint': 12.0}
    ...
    Last edited by Karrimor; 1st January 2018 at 12:46 AM.

  4. #4
    Automated Home Legend
    Join Date
    May 2014
    Posts
    998

    Default

    Happy New Year to all. Out-of-interest, can this script be run on a Synology NAS? If so, can anyone recommend a Python guide for dummies (or in my case, oldies)?

  5. #5
    Automated Home Legend
    Join Date
    Jul 2014
    Posts
    1,211

    Default

    I works absolutely fine on a Synology. I ran it for quite a while until I moved to a QNAP. Runs there too.

  6. #6
    Automated Home Lurker
    Join Date
    Dec 2017
    Posts
    6

    Default

    Thank you all for your help, I really do appreciate it!

    I was hoping to use this as a project to get me into coding at a basic level but I'm content looking at the code and understanding what it is doing and when as a close second!


    Cheers all!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •