core: Smart Meter Texas SSL Certificate Verification Error
The problem
Smart Meter Texas integration has been working (including with Energy Dashboard since 40348 was resolved but as of late yesterday, is now reporting Failed to Connect with an SSL Certificate Error.
What is version of Home Assistant Core has the issue?
core-2021.10.2 and core-2021.10.4
What was the last working version of Home Assistant Core?
core-2021.10.2
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Smart Meter Texas
Link to integration documentation on our website
https://www.home-assistant.io/integrations/smart_meter_texas/
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Logger: homeassistant.config_entries
Source: components/smart_meter_texas/__init__.py:49
First occurred: 12:59:56 PM (1 occurrences)
Last logged: 12:59:56 PM
Error setting up entry NateEaton for smart_meter_texas
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1081, in create_connection
transport, protocol = await self._create_connection_transport(
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1111, in _create_connection_transport
await waiter
File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 528, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 188, in feed_ssldata
self._sslobj.do_handshake()
File "/usr/local/lib/python3.9/ssl.py", line 944, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'smartmetertexas.com'. (_ssl.c:1129)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/smart_meter_texas/__init__.py", line 49, in async_setup_entry
await smart_meter_texas_data.client.authenticate()
File "/usr/local/lib/python3.9/site-packages/smart_meter_texas/__init__.py", line 196, in authenticate
await self._init_websession()
File "/usr/local/lib/python3.9/site-packages/smart_meter_texas/__init__.py", line 147, in _init_websession
await self.websession.get(
File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 971, in _wrap_create_connection
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host smartmetertexas.com:443 ssl:True [SSLCertVerificationError: (1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'smartmetertexas.com'. (_ssl.c:1129)")]
Additional information
This integration has been working fine since July and stopped working last night (2021.10.11 about 9pm CT), still not working this afternoon even after updating Core from 2021.10.2 to 2021.10.4. I am able to log into my account on smartmetertexas.com.
July
Yesterday
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 135 (9 by maintainers)
Called their help line, they escalated the ticket to their L2 team, who deals with API and such. I was given an ETA of 48h for a fix, so we should just buckle down.
On that note, i’ve been looking through the code, and cannot locate where it looks for the domain to connect to. If someone could point that out, i’d be grateful.
This issue was caused by SmartMeterTexas.com SSL Renewal process. They didn’t include the SAN for “smartmetertexas.com”, and only included “www.smartmetertexas.com”. I have already emailed SMT support about their SSL issue(s), and hope to get a reply soon.
For this I used a platform start automation that checks to see if the changes exist and makes them if not. This is based on what I found here. Detail below.
I’m not sure that I needed to loop the hosts update the way that I did but in my first few tries it seemed as if during startup my hosts addition was being stomped by the system. Update: I’ve confirmed that the loop was not needed and that what I was observing was that the platform start automation runs later than I thought that it would, only once “Home Assistant has started!” message appears. SMT will hang up the startup for a few minutes before it will move to retrying in background, allowing startup to finish, at which point SMT will load as the hosts file has been updated. I’ve removed the loop from the hosts.sh below.
Also, in testing I found that If I removed www from the BASE_HOSTNAME variable the platform start automation would add it back but not before the component had already loaded and failed due to the SSL error. A second restart resolves the issue.
As all have pointed out, this is a temp fix, could break at anytime, use at your own risk, zombies, …
/config/hosts.sh
/config/smt_host.sh
Just tried to add the integration just for giggles and it worked! It created 1 entity and it seems to be pulling in data.
So i reached back out to SMT, and they mentioned they’re getting quite a few calls regarding the SSL certificate. So we’re not the only ones affected. I did recommend they lower the API requirements however, as that would make things like this much easier to navigate, and possibly provide us with more information.
I’m hoping that we can get scraping data to allow for surplus generation data to be available on HA, but for now, that’s a pipe-dream.
That’s surprising they’re being this helpful. We’re using the unofficial API used by the web browser. Thanks @johnavich.
The API logic is performed by the library I created. https://github.com/grahamwetzler/smart-meter-texas
Their HTTPS port is still technically open, but it appears they’ve restricted it to Akamai traffic only. I was always afraid this might happen. 😣
Yep, they’ve included the SAN for “smartmetertexas.com” in their new cert.
Sheesh, sorry for that and thank you for the help. I’m not a docker person… tried for a while but pretty much abandoned a while back.
I have it all added and restarted and then rebooted the VM too. No errors on the shell scripts but the smartmeter integration shows not-loaded and not seeing any new data (yet) in the Energy tab. Is this normal or is there something I should could check?
edit: Seems it loaded the entity after a few minutes and got the total usage. Just waiting for hourly updates now - Thank you again!
SMT seems to do their maintenance/releases on Saturdays. As of noon yesterday the HA SMT integration is working again for me.
its about time! thank you for everyone keeping on them over the last year… its been a tough road for some folks, what with all the workarounds in place, but i’m glad this is working to our advantage!
To make it work in HA 2022.7.0 and later, change the calls in /config/smt_host.sh from python3.9 to python3.10:
/config/smt_host.sh
Since making the change suggested by @johnavich, I’ve updated my HA install a few times and of course, lost the manual changes each time. so, I decided to semi-automate the process of finding the const.py file and updating it. Here is the result, one command to re-apply the changes after updating to a new version. Enjoy 😉 (I’m sure the command can be optimized, and might have some unforeseen bugs too. Please post your improvements)
Disclaimer: Use at your own risk, I’m not responsible for anything, including the Zombie Apocalypse…
sed -i 's/"smartmetertexas.com"/"www.smartmetertexas.com"/' $(docker inspect homeassistant | grep MergedDir | sed 's~"MergedDir": ~~g; s~\"~~g; s~,~~g; s~ ~~g; s~$~/usr/local/lib/python3.9/site-packages/smart_meter_texas/const.py~g')
Does anyone know how to create a “post update” script in HA to automate the above command after each update?
@johnavich Thanks for the detailed instructions, works like a charm 🙂
@meyerrj, a request/suggestion for you: The proper fix would be for the SMT folks to come to their senses and manage their SSL certs correctly. Since we don’t have control over that, I’m wondering if we can incorporate the fix suggested by @johnavich with a config option, which toggles it off or on, depending on the state of the URL/IPs? This would help many other users, who may not be comfortable with changing code themselves.
So, long story short, SMT is being billeigerent, trying to continue requiring a publicly signed cert and a static ip address.
Until they come to their senses, I did figure out a workaround that worked for me. I’ll be pasing that to the “fix” on Graham’s original site.
Well, they do have an official API but it has some ridiculous requirements that would make it much more difficult to offer an HA integration.
I also had this same issue , I also tried to remove and re-add and then after that could not re-create, would get invalid credentials.