I am working on a custom component for the lacrossealertsmobile.com service. These $30-50 wireless temp/humitdy sensors are perfect for hot tubs, aquariums, backyards, etc. They can be found on Amazon here.
I found a module on PyPi to interface with the API, and worked with the module’s creator to get it updated for Python 3. Hooray! I was able to get the direct API calls out of my custom component and was one step closer to the requirements for a PR.
My project is on Github here:
I have been using the custom component for a while now, and it works fine except for an issue when home assistant starts. Due to the way my three sensor objects inherit from the Entity object that calls the API, and the way Home Assistant works I suppose, their state() methods are called before the update() method, and I receive 3 errors in the following format:
AttributeError: 'LaCrosseAmbientSensor' object has no attribute '_ambient'
I guess I’m just looking for a nudge in the correct direction on how I should be handling this, because this clearly isn’t quite the right way.
I’m also wondering if the inheritance here is the correct approach, or if there is some other way about this I’m so far unaware of. The way it is now, I am guessing the update method gets called three times when really it only needs to get called once.
Hi @Legomaniac I installed the custom component and added the platform to my sensors.yaml file and I’m receiving an error I’m hoping you can help me with.
Invalid config for [sensor.lacrosse_alerts_mobile]: required key not provided @ data[‘id’]. Got None. (See /config/sensors.yaml, line 126).
Below is what I’ve added to my sensors.yaml. Does this need to be in configuration.yaml rather than my sensors.yaml? I was trying to keep all of my sensors separate from the rest of my config since I have pretty many.
In the time since my previous post working on this component (where I showed the snippet from the config) I changed the way the component interacted with lacrossealertsmobile.com.
Previously, it used the username and password to load the full website (as a browser would) and scrape the data. Since that time, someone in the hass discord channel pointed me to a module on PyPi that interacted directly with the API. I worked with the developer of that module to get it updated for Python 3 and available on PyPi.
Due to the way their unsecure API works, now instead of providing my component with a user/pass combo, you simply give it the ID from the label on the back of your sensor. For example, my updated config looks like so:
Apparently, you can get data from any sensor reporting to them, as long as you have the full ID, because the API providing the data to the lacrossealertsmobile.com site doesn’t actually use any authentication. Once you log in and the site pulls your ID from your account, it just hits the API with the ID and nothing else to get the data.
Let me know if you guys have any other issues getting it working! I would love to help.
That being said, I’m still hoping to get some direction from an experienced component developer about how best to avoid the “object has no attribute” error when Home Assistant starts. I am not sure of the etiquette on these forums, but if allowed I would be willing to put a bounty on some assistance. Perhaps fifty bucks could persuade someone to take a look?
Once again, thanks for your interest! Hoping to hear from some opinions on a more correct approach to this!
Thanks for the detailed reply. I have it working with my sensor now!!! I’m able to monitor my greenhouse and setup a Generic Thermostat to turn the heater on as needed. I also setup iOS notifications using Home Assistant since the Lacrosse Mobile platform requires a paid subscription for alerts. (hopefully Lacrosse doesn’t wise up and remove the unsecure API used for this component!)
I wish I could help you with the dev side of things, but I’m not nearly skilled enough with that, sorry. If I could make a suggestion though; please add the sensor config to your Github readme in case others may stumble upon your custom component.
@Hassiopeia thanks for the feedback. To be honest I wasn’t expecting someone to want to use this before I got all the kinks ironed out. I’m glad it’s working for you as well!
Hello again! With HA update to 0.92, this custom component no longer loads. With .92 HA finally completed the migration of custom components requiring some additional build. Do you have any intentions to update this component to work with .92? If not I may fork this on Github and attempt to update it for .92 (though I don’t have much time nor experience doing this)
Thanks for letting me know! I haven’t SSH’d to my home automation server in a while, so I think I’m still on 0.90 - I will look at this tonight after I’m done with work.
As long as this post is getting bumped, I am still looking for anyone that can help with the error outlined in my first comment. Thanks again!
I just pushed an update to Github, all that I did was add an empty __init__.py and a new manfiest.json. Then I moved my REQUIREMENTS from the sensor.py file to the newly created manifest. Seems to be working in HA 0.92.1
Still getting the same errors as first described on startup. Still willing to put up a $50 bounty on help with doing this more properly, and getting rid of those errors!
Since updating recently, possibly it was the .98 version, the lacrosse sensors won’t load. I’m getting any error for line 20 of the sensor.py file. The error states that the pylocrossapi module is not found. I tried to manually install pylacrossapi via terminal, but I still get the error. Are you having this issue since recent upgrades?
Error while setting up platform lacrosse_alerts_mobile
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 150, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File “/usr/local/lib/python3.7/asyncio/tasks.py”, line 442, in wait_for
return fut.result()
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/lacrosse_alerts_mobile/sensor.py”, line 20, in setup_platform
import pylacrossapi
ModuleNotFoundError: No module named ‘pylacrossapi’
I’m running 0.98.5 and I don’t seem to be having this issue. Unfortunately I won’t be able to dig into it until Wednesday, but I’ll let you know what I find out.
I’m running 99.2 however I think the issue arose prior to 99 as I’ve been seeing it for a while but didn’t have a need for the sensors again until now. I think it maybe started for me in 97 or 98 versions. Thanks for your help!!
I just upgraded to 0.99.3 and I am not experiencing the issue. With my last commit mentioned in my comment from April 27th, I moved the requirements out of the .py file and into the manifest.json, this seems to be in line with the documentation here:
When I activate the environment my homeassistant installation is in, I am able to import the module without issue:
[root@diginuc lacrosse_alerts_mobile]# source /opt/homeassistant/bin/activate
(homeassistant) [root@diginuc lacrosse_alerts_mobile]# python
Python 3.7.4 (default, Jul 9 2019, 16:32:37)
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylacrossapi
>>> exit()
Are you starting fresh with a completely new installation of HA every time you upgrade? There’s a chance that the logic to pull in requirements no longer functions with custom components, but I would have never run into that issue because I just upgrade in place by activating the environment and updating with pip:
Of course, this may vary depending on your install process and where the HA root directory is. My implementation is on an Intel NUC (running several other applications) in Fedora Server 30.
I have a feeling this may just be due to the logic that HA uses to pull in requirements with pip, and it’s probably not doing it for custom components anymore. If you are able to activate the environment HA is running in, and then use pip within that environment, I am guessing that will fix the issue. @Hassiopeia when you attempted to manually install pylacrossapi did you first activate an environment?
I’m not entirely sure how things are structured/configured if you are running the Raspberry Pi HA where everything is wrapped up with the OS.
Also, for those of this seeing this thread for the first time because it got bumped, I am still looking for some direction on what it would take to get this polished into an official integration, and still willing to put out a bounty for help!
Please refer to the first post in this thread and let me know if you are interested.
Unfortunately I’m not familiar with your question regarding activating an environment first. I’m running Hass.io which is certainly different than your setup. I used below to atempt installing it myself
I have a thought though, could it be related to the Python version? I’m running 3.7.4 which is bundled with Hass.io. Perhaps you’re running an older version and the new version doesn’t include pylacrosseapi in their library (forgive me if that’s not the correct terminology).
Also tried deleting everything in the lacrosse custom component folder, reboot, add the component fresh from Github, reboot, same issue.
I managed to fix the issue I was having!!! It may not be the most correct way to resolve it per hassio coding standards, but it worked for me. Here’s what I did:
Then I changed lines 20 and 24 of the setup_platform section in the sensor.py file of the custom component:
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the lacrosse alerts mobile platform."""
from deps.pylacrossapi import lacrosse as lacrosse
device_id = config.get(CONF_ID)
unit_measure = 0
time_zone = 10
lacrosse_device = lacrosse(device_id, unit_measure, time_zone)
add_devices([LaCrosseAmbientSensor(lacrosse_device), LaCrosseProbeSensor(lacrosse_device), LaCrosseHumidSensor(lacrosse_device)])
Restarted, and had the sensors back!
My best guess is that in our instances, the requirement isn’t installing on it’s own. So what I did was manually install it and then put an explicit path to the module in the sensor.py file. Good Luck!