[RELEASE] Emporia Vue driver for Hubitat

I am seeing the same behavior, only after the update. I'll look into it this weekend.

I believe the timestamp from Emporia is in UTC. I use the native Hubitat function to convert it to your hub's timezone. If that's the case, it may be a bug on the Hubitat side.

This is not a problem at all for me, just information - glad it's not just me. If anything I can do to help troubleshoot, I'm happy to help.

I have had some past confusion with how HE handles GMT vs local time in Webcore. I hope whatever happened in latest ver. didn't goof up my automations in webcore too...

I updated the driver to get the current timestamp in local time. It does not rely on the native Hubitat functions to convert the timezone anymore. I was not able to figure out why the conversion suddenly stopped working.

I asked ChatGPT to create a groovy app for this. I reckon it's missing some stuff it needs to make it work, but figure it's worth taking a stab in the dark and trying it!

translate pyemvue from python to groovy app code for hubitat.

Here is an example of translating a Python Pyemvue code to equivalent Groovy code for a Hubitat app:

Python:

pythonCopy code

import requests

def update_emporia_api_token(new_api_token):
    headers = {
        'Authorization': f"Token {new_api_token}"
    }
    response = requests.post("https://api.emporia-energy.com/v2/accounts/me", headers=headers)
    if response.status_code == 200:
        print("Emporia API token updated successfully")
    else:
        print("Failed to update Emporia API token")

Groovy:

pythonCopy code

import groovyx.net.http.RESTClient

def updateEmporiaApiToken(newApiToken) {
    def client = new RESTClient("https://api.emporia-energy.com/v2")
    def headers = [
        Authorization: "Token ${newApiToken}"
    ]
    def response = client.post(path: "/accounts/me", headers: headers)
    if (response.status == 200) {
        log.debug "Emporia API token updated successfully"
    } else {
        log.debug "Failed to update Emporia API token"
    }
}

This code defines a function updateEmporiaApiToken that takes in a parameter newApiToken and uses the RESTClient class from the Groovy HTTP Builder library to make a POST request to the Emporia API with the updated token value in the Authorization header. The function logs a message indicating whether the API token was updated successfully or not based on the HTTP response status code.

Create groovy app for Hubitat using login.py and pyemvue python code described here: [RELEASE] Emporia Vue driver for Hubitat - #9 by calinatl

Here is an example of a Groovy app for Hubitat using the login.py and pyemvue.py code described in the link:

javaCopy code

import groovyx.net.http.RESTClient

def updateEmporiaApiToken(newApiToken) {
    def client = new RESTClient("https://api.emporia-energy.com/v2")
    def headers = [
        Authorization: "Token ${newApiToken}"
    ]
    def response = client.post(path: "/accounts/me", headers: headers)
    if (response.status == 200) {
        log.debug "Emporia API token updated successfully"
    } else {
        log.debug "Failed to update Emporia API token"
    }
}

def login(username, password) {
    def client = new RESTClient("https://api.emporia-energy.com/v2/accounts/login")
    def response = client.post(
        contentType: "application/json",
        body: [
            username: username,
            password: password
        ]
    )
    if (response.status == 200) {
        def json = response.json
        return json.token
    } else {
        log.debug "Login failed with status ${response.status}"
        return null
    }
}

This code defines two functions, updateEmporiaApiToken and login. The updateEmporiaApiToken function is the same as the one in the previous answer and updates the Emporia API token with a new value passed as a parameter. The login function takes in a username and a password and uses the RESTClient class from the Groovy HTTP Builder library to make a POST request to the Emporia login API with the provided credentials. The function returns the API token obtained from the response if the login is successful, or null if the login fails. The function also logs a message indicating the status of the login attempt.

3 Likes

Brilliant! If that turns out to work….. well, lets just say that would be a huge step for the community.

1 Like

Not holding my breath, and I lack the skills in this to troubleshoot much if it doesn't work.

Just a lark.

2 Likes

So @nrus2222, any update? Did it work?

1 Like

Sorry, had other priorities bump this hobby, and haven't tested yet. Been long enough I'd probably ask ChatGPT again and see if different answer before testing. 99% sure it won't work without some tweaks by someone who actually knows what they're doing, but still willing to give it a go.

Pyremvue on AWS Lamda function has been bullet-proof and still zero cost, so has not a high priority for me.

2 Likes

LOL - I have NO CLUE what this even means - but I know AWS is Amazon Web Services. So I have two questions:

  1. Can you connect the Emporia Vue to the Hubitat with "Pyremvue on AWS Lamda function" without additional hardware?
  2. Is the goal of the groovy app created by ChatGPT to be able to connect the Emporia Vue to the Hubitat without additional hardware?
    Thanks.

"Yes" to both questions.

@ke7lvb 's driver takes care of everything but periodic generation of "authtoken" needed to stay connected to emporia's API. This part is handled by periodically calling pyemvue function in Python. I think most people do this on a Raspberry Pi or a PC/Mac connected to the network. I was looking at this route myself until I saw what the chip shortage did to RPi prices! It should be possible to convert this part to groovy so that the hub can just do this, but no one has contributed something that works for this yet.

AWS, Google and Microsoft Azure all offer a free tier of service. I am just a hack at this, but with @ke7lvb 's help and some online references I linked earlier in this thread, I managed to set up an "instance" of a Ubuntu linux server on AWS EC2, and set up the cron job to run pyemvue on it every hour. This is just like what the setup would be on a local linux box except need to use the cloud version of maker API commands to pass the token instead of local LAN version. After running this a while, AWS showed $4/mo projected cost of running this after 1 year free tier was finished. I realized it was pretty wasteful to basically be running this full x86 compute node (server) 24/7 just to run this function every hour, and figured there had to be a better way.

AWS lamba is a "serverless" solution, and google/msft offer something similar as well. Basically you create a container with the code you want to run, and AWS executes it when it is triggered somehow (it offers eventbridge as a mechanism to trigger periodically). Details to make this work are above ([RELEASE] Emporia Vue driver for Hubitat - #19 by nrus2222) . Now I'm only consuming about 0.5s of x86 compute resources an hour that AWS manages, rather than consuming a full-time x86 EC2 instance.

Seems like this usage falls well-under their "always free" level of service:

Thank you!
Good to know there is a workaround to keep this running and it is free. Like you I hope someone who understands this stuff can get it working on the Hubitat.

I decided to create a docker image so I could do a local update on my API token, added a repo on my github with instructions for use. parker-hemphill/hubitat-emporia-token-generator

@user5096 Welcome to the HE Community!
For those of us not familiar with this stuff, can you please translate what it means to "create a docker image"? I presume this is some sort of software. If so, where does it get installed?

Docker is just a tool to run scripts in a virtual environment. It is an easy way to install prebuilt packages without giving them direct access to your machine. You can lookup online how to install docker for your machine. Once you have it installed you should be able to issue a command like the one in this example.
GitHub - parker-hemphill/hubitat-emporia-token-generator

When you refer to "your machine" do you mean my Hubitat?

Some other computer, like a raspberry pi.

where would i be able to find the emporia device id?

Once you've created the virtual device using the Emporia Driver, and added your Auth Token, click the "Get Device Gid" button. If you refresh the page, you should be able to see the deviceGID stored in the State Variables.

The driver retrieves the device id from this endpoint: https://api.emporiaenergy.com/customers/devices

1 Like

Awesome thank you!

Ok so I first need to install the driver into hubitat? Ok didnt realize that, that helps out alot.