Added sensor state attribute#10617
Added sensor state attribute#10617bbbenji wants to merge 2 commits intohome-assistant:devfrom bbbenji:patch-1
Conversation
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Could you please explain why? I am new to this.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
This PR seems to have gone stale. Closing it. You can reopen it when you're ready to finish it. |
|
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. |
Description: Adds an attribute for the sensor state.
Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#3998
Checklist:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.