Home Assistant Community

Working on lacrossealertsmobile.com component - Receive "object has no attribute" error on start

#1

Hello everyone,

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.

Thanks in advance for your reply!

Legomaniac

Hoping to correctly implement component for lacrossealertsmobile.com
#2

Please keep me posted! Been going nuts trying to figure out the Jeelink thing.

#3

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.

  - platform: lacrosse_alerts_mobile
    user: !secret lacrosse_username
    pass: !secret lacrosse_password
#4

How do you have this programmed?

I put the folder in custom_components and titled it lacrosse_alerts_mobile:

Then, in Configuration.YAML

  • platform: lacrosse_alerts_mobile
    user: XX
    pass: XX

I keep getting:

Component not found: lacrosse_alerts_mobile_sensor – and if I change it back to the other, still nothing.

#5

Hey @jbk1988 and @Hassiopeia. Thanks for your interest!

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:

sensor:
  - platform: lacrosse_alerts_mobile
    id: !secret lacrosse_id

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,
Legomaniac

#6

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. :wink:

#7

@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!

#8

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)

#9

Hey @Hassiopeia,

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!

#10

This page has some info about the changes needed and could probably point in the right direction. https://developers.home-assistant.io/blog/2019/04/12/new-integration-structure.html Looks like any dependencies and requirements need to be moved into a maifest.json file and maybe the addition of a init.py file.

#11

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!