All, I’ve created a Python file that gathers Sense data every 65 seconds as well as Weather data, and logs both minute by minute details and hourly summaries. See attached.
It works quite smoothly and it pretty reliable. I found that unless I waited slightly more than a minute between each requested sample of Sense data, I would just get the exact same data back again.
Please feel free to make use of what I’m put in the example file and tweak it for your own usage.
Am trying to use your script on linux:
Filled out my email/password & generated API number
$ python3 /usr/local/bin/sense_python_example.py
Initialize Weather API
Initializing Sense library…
Authenticating with Sense servers…
Waiting for next minute to start…
Unable to call the weather API, retrying…
One of the weather calls failed, using zeros as values.
Traceback (most recent call last):
File “/usr/local/bin/sense_python_example.py”, line 242, in
if (get_temp_fahrenheit_float(observation1.weather) > max_temp1):
NameError: name ‘observation1’ is not defined
Any suggestion?
UPDATE
Tried again later on the day and this time it gave me some useful info:
Date/Time: 2022/01/08 19:12:05 Power Being Used: 1446 watts, Power Being Generated: 0 watts, net production -1446 watts
Date/Time: 2022/01/08 19:12:05 Auburn temp: 40.12 Enumclaw temp: 37.22 Auburn Cloud %: 40 Enumclaw Cloud %: 96
It seems I need to figure out how to set my openweather API key to the right location.
Will figure that out eventually
Hi there. Hmm, not sure what’s up. It could be that you can’t connect to the Weather API due to a firewall or other rule.
Try adding these lines to get_weather_data(), instead of “except:” to get more details on the exception that’s being returned.
except Exception as e:
print('Failed to call the weather API: '+ str(e))
print("Unable to call the weather API, retrying...")
sleep(10)
observation = mgr.weather_at_id(city_id)
I don’t know if you have seen my updated info on the original posting.
Later on the same day “it started working” [TM]
I now have collected this output so far:
13016 Jan 8 23:59 detailed_data_2022_01_08.csv
70082 Jan 9 23:58 detailed_data_2022_01_09.csv
2594 Jan 10 09:00 summary_data_2022_01.csv
27133 Jan 10 09:06 detailed_data_2022_01_10.csv
I have seen 12kW AC at good times.
Part of it is down atm,
Waiting for a new 12kW DC hybrid inverter with 20kWh usable li-ion storage that will help beat the ludicrous Summer On-Peak: 69 cents/kWh from 2 p.m. to 8 p.m. from my utility.
Hi there. Getting a proper python environment setup can be tricky (depending on if you are on Windows, Mac, or Linux), at least from my experience. I installed Visual Studio Code, and Python 3.10 first. Then, to install the sense_energy, use this command from https://github.com/scottbonline/sense:
pip install sense_energy
There are other tips/tricks at that web site too.
Hopefully that will help you get to the next step.
Mark
Thanks all, that worked great, the Python3 trick was very useful, didn’t even realize I had both versions on the computer already.
I REALLY hope I am not just going to go line by line thru there complaining about errors, but I did the above installs and now I get:
ModuleNotFoundError: No module named ‘pyowm’
Assuming that there is also a pip3 install for that I tried and succeeded, that moved me forward, but not far enough. Then I got a:
Exception when initializing Sense library: Connection failure: HTTPSConnectionPool(host=‘api.sense.com’, port=443): Read timed out. (read timeout=5)
Which I thought was gonna be the end, but just for grins I tied it again and it WORKED. Thanks for getting me over the hump. I will now try to figure out talking to the Tesla API and see if I can actually make use of this to save me tweaking the charging as the clouds roll by or the sun begins to set.
My next steps are figuring out how get a notification to my phone or elsewhere if I have excess solar, so I can run specific power loads, kind of like your Tesla charging.
It would be great if you could share your Python code when you get the integration with your Tesla working, I’m sure there are others who would love to build off that as well!
OK, maybe it didn’t take as long as I thought, still a few bugs in the system, but it seems to be doing the tracking of the free solar and adjusting the charging of the Tesla in response. When my hot tub or space heater or dish washer comes on the Tesla backs down or turns off, than usually later it turns back on, check it out, updates will appear here:
Of course, now that I have finished most of the debugging of the code I realize I wanna add the feature where the charging setting for the Tesla is relayed to the Sense Monitor so it doesn’t show as Other. But I don’t know how to spoof the Kasa plugs in Python…
Should also figure out how to turn Kasa smart plugs off and on in the script like the WEMO Control python script does.