Skip to content

zha: additional sensors#12515

Closed
dmulcahey wants to merge 7 commits intohome-assistant:devfrom
dmulcahey:dfm/zha-sensors
Closed

zha: additional sensors#12515
dmulcahey wants to merge 7 commits intohome-assistant:devfrom
dmulcahey:dfm/zha-sensors

Conversation

@dmulcahey
Copy link
Copy Markdown
Contributor

@dmulcahey dmulcahey commented Feb 19, 2018

Description:

Updates ZHA with the following changes:

  • Adds the groundwork for several new sensor types to be supported by ZHA:
  1. Metering (energy consumption for connected devices)
  2. PowerConfiguration (battery sensors - currently limited to Centralite devices)
  3. IlluminanceMeasurement
  4. ElectricalMeasurement

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line at end of file
blank line contains whitespace

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing whitespace

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line at end of file
blank line contains whitespace

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ':'

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ':'

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ':'

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ':'

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ':'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline at end of file

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline at end of file

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block comment should start with '# '

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block comment should start with '# '

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line under-indented for visual indent

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace

Copy link
Copy Markdown
Contributor

@rcloran rcloran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks good to me.

I'd prefer to handle the device quirks (Centralite-specific battery sensor) in zigpy, where we can expose a consistent interface to hass. I'd be OKish with this going in and changing to use the normal BatterySensor when zigpy quirks handling is ready, though.

Please send in PR to zigpy for the battery size enum, happy to add that in and bump the release for you.

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this kind of device is normally wired, and so polling it is OK? Have you tried configuring reporting on your device? That'd be a better option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, they're wired devices and the electrical measurement cluster attributes don't support reporting according to the ZCL docs.

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into zigpy as an enum, as it is part of the standard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll submit a PR to zigpy for this

Comment thread homeassistant/components/sensor/zha.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should live in Home Assistant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"I'd be OKish with this going in and changing to use the normal BatterySensor when zigpy quirks handling is ready, though."

Will leave here until quirks mode is ready.

@ryanwinter
Copy link
Copy Markdown

Is there still plans to push this out?

@dshokouhi
Copy link
Copy Markdown
Member

I agree this PR has some very critical functionality. Battery reporting for a contact sensor is really important. Not knowing when your device battery is going to run out poses a security risk for any alarm.

@rcloran
Copy link
Copy Markdown
Contributor

rcloran commented Apr 4, 2018

I've just force pushed to https://github.com/dmulcahey/home-assistant/tree/dfm/zha-sensors to get travis to re-run.

@Adminiuga
Copy link
Copy Markdown
Contributor

should @asyncio.coroutine/yeiled from" be updated to use "async def/await" syntax?

@dshokouhi
Copy link
Copy Markdown
Member

Any chance we can at least split out the Battery aspect of this PR and merge it in? Many users are waiting for this functionality so we can know when a zha battery device is going to die. I would love to see all of it get merged if possible.

@dshokouhi
Copy link
Copy Markdown
Member

@dmulcahey and @rcloran I wanted to provide some feedback on this PR as yesterday I had time to pull in this PR into my own environment to test things out. I can confirm the energy reporting is working as expected. I am not so certain about the battery reporting. As of this morning some of my Iris Contact Sensors had checked in but the battery level reported is 100% which can't be right. On top of that it seems I got duplicate battery entity ID's as well. Looking at the code in sensor/zha.py I can see the values being interpreted to 100% so it seems like we are getting the values but maybe we need to update the percentage reading (line 187-200)? When I switched from SmartThings most my devices were around 60-70% battery life so I don't know how accurate the 100% reading really is.

pr12515-battery

@ryanwinter
Copy link
Copy Markdown

I might give this a whirl if I have time this week. I only have smart thing devices though and @dshokouhi looks like he already confirmed this.

@balloob
Copy link
Copy Markdown
Member

balloob commented May 1, 2018

This PR is a great example why one should limit PRs to a single feature. We could have merged the working parts already.

@balloob
Copy link
Copy Markdown
Member

balloob commented May 1, 2018

What needs to be done to get this finished and who is going to do this? Would someone want to open smaller PRs containing a single feature from this PR ?

@dmulcahey
Copy link
Copy Markdown
Contributor Author

@balloob from my perspective it all works. It is my understanding that others are expecting the battery reporting to work for the rebranded smart things centralite sensors. That's where the concerns seem to be on battery reporting not working. I am assuming that they modified the manufacturer check to reference smartthings instead of centralite. I could be completely wrong but that is my guess. This is tested and it is currently working for stock centralite sensors and I have been running it locally since I opened the PR. I will gladly break this up into multiple PR's if it makes things easier. Sorry for causing a stir with my first PR!

@dshokouhi
Copy link
Copy Markdown
Member

@dmulcahey the device I used this PR on is a Iris Contact Sensor second generation. I believe that is the same one you used correct? For Energy Reporting I am using a Iris Smart Plug second generation. I do agree that I have seen others mention the SmartThings rebranded ones but personally I did not modify your PR at all in that regard so to me it is working.

The only real issue I saw was that duplicate battery sensors got added as you can see in my screenshot above.

@ryanwinter
Copy link
Copy Markdown

ryanwinter commented May 1, 2018

Whats the path for supported other sensor (such as Smartthings) once this is merged.

Is it just keep extending the zha.py and add additional derived GenericBatterySensor classes?

Or do we want to wait to add this functionality into zigpy once the quirks handling is complete?

@dmulcahey
Copy link
Copy Markdown
Contributor Author

@ryanwinter Quirks handling should help this... but I think we’ll still have a bunch of custom sensor classes just in a different format. @rcloran, any thoughts on this?

def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return None to represent unknown state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are multiple input values mapped to the same output percentage?
28, 27 and 26 are 100%
Why not 28=100, 27=97, 26=93? (or something like that)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanwinter please move your comment to a general PR comment. I don't see that it's related to my comment or this code line.

elif self._state > self.maxVolts:
self._state = self.maxVolts

return self.values.get(self._state, 'unknown')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

def state(self):
"""Return the state of the entity."""
if self._state == 'unknown':
return 'unknown'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return None.

@dmulcahey
Copy link
Copy Markdown
Contributor Author

@ryanwinter I pulled that map directly from a smartthings device handler. The code can be found here: https://github.com/varzac/SmartThingsPublic/blob/97bfe61baa464cdac8894a566f19bcd6cc3c68c7/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy

@dshokouhi
Copy link
Copy Markdown
Member

Hey all I think this PR needs to be rebased or updated now as it has conflicts and parts of it is no longer working for me. After updating to 0.69 energy reporting is no longer working. I made sure to place back the files that got overwritten. Battery reporting is still working so parts of it seems to be ok.

@dmulcahey
Copy link
Copy Markdown
Contributor Author

@dshokouhi I’m going to close this. I’ll open smaller independent ones.

@dmulcahey dmulcahey closed this May 13, 2018
@dshokouhi
Copy link
Copy Markdown
Member

Happy to help test anything if you need it!

@dmulcahey
Copy link
Copy Markdown
Contributor Author

@dshokouhi #14563 #14562 #14561 have been opened. @MartinHjelmare I addressed the relevant comments in those PR's. @balloob sorry again for all of the churn that this caused!

@dshokouhi
Copy link
Copy Markdown
Member

thanks @dmulcahey !! Will check out the PR's soon :) The battery reporting has actually been working pretty well so far too, my centralite devices are definitely reporting. Thanks for much for submitting the PR's :)

@Adminiuga Adminiuga mentioned this pull request Sep 3, 2018
8 tasks
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
@dmulcahey dmulcahey deleted the dfm/zha-sensors branch December 26, 2018 12:12
@ghost ghost removed the platform: sensor.zha label Mar 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants