Skip to content

Added sensor state attribute#10617

Closed
bbbenji wants to merge 2 commits intohome-assistant:devfrom
bbbenji:patch-1
Closed

Added sensor state attribute#10617
bbbenji wants to merge 2 commits intohome-assistant:devfrom
bbbenji:patch-1

Conversation

@bbbenji
Copy link
Copy Markdown

@bbbenji bbbenji commented Nov 16, 2017

Description: Adds an attribute for the sensor state.

Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#3998

Checklist:

  • Documentation added/updated in home-assistant.github.io
  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

Used the wrong variable in original commit for PR.
ATTR_SENSOR_USED: int(
self.consumable_state.sensor_used.total_seconds()
ATTR_SENSOR_DIRTY: int(
self.consumable_state.sensor_dirty.total_seconds()
Copy link
Copy Markdown
Member

@rytilahti rytilahti Nov 16, 2017

Choose a reason for hiding this comment

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

I retracted my earlier comment here, but now I'm curious whether this has ever worked? I can't recall it ever being called sensor_used.

edit: the original comment was related to whether it would make sense to use "time left" as with other consumables. This would involve 1) finding out how often the sensors should be cleaned and 2) making the change in python-miio and finally updating this platform.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This did not work, it was a mistake on my part. Regarding your previous comment:

I wanted to keep the original functionality and naming from python-miio. I have done the math in my config to provide a "left" value.

However, this attribute does work opposite to the rest of them, so I do understand it would probably make more sense.

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.

Ok, I saw that you changed it :-) What kind of math you are doing there at the moment? It would be nice if you could just adapt ConsumableStatus class in python-miio (it is pretty straightforward, see https://github.com/rytilahti/python-miio/blob/master/miio/vacuumcontainers.py#L284) to provide the also sensor_dirty_left (not a really nice name, but follows the suit) and add output for printing it out in the relevant command in vacuum_cli.py.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, that would be much better. I'll try to get that working.

How many hours until a cleaning of the sensors is recommended (left):
{{ float(30) - float(states.vacuum.mijia.attributes.sensor_dirty) | round(0) }}

How many hours passed since the sensors where last cleaned:
{{ states.vacuum.mijia.attributes.sensor_dirty }}

Remaining % until a cleaning of the sensors is recommended:
{{ "%01d" | format(((float(30) - float(states.vacuum.mijia.attributes.sensor_dirty)) / float(30)) * float(100) | int) }}

The sensors should be cleaned every 30hrs of runtime.

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.

Ok, great, thanks for your patch too! I added some comments there earlier, but just for the future reference here's the upstream PR: rytilahti/python-miio#119 .

self.consumable_state.filter_left.total_seconds()
/ 3600),
ATTR_SENSOR_DIRTY: int(
self.consumable_state.sensor_dirty.total_seconds()
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.

We should not ever contain a relative time in our attributes. All these total seconds have to go. We should only record timestamps in the state machine.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Could you please explain why? I am new to this.

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.

The state of an entity should not change based on just time. It causes a state change every time the entity gets written to the state machine even though nothing has changed.

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.

Agreed, I'll look into this next week when I get some time. The attribute should return the timestamp when a change is required, I think.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jan 11, 2018

This PR seems to have gone stale. Closing it. You can reopen it when you're ready to finish it.

@balloob balloob closed this Jan 11, 2018
@rytilahti
Copy link
Copy Markdown
Member

Looks like I've overlooked this, but this was discussed already on some other PR/issue. As these values depend on the usage, there is no way to expose a simple timestamp for these.

@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
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.

5 participants