-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MiScale V2 - multiple sensor updates from one use of scale #617
Comments
I don’t understand it exactly, how would I have to select the measurement that you want. Normally, the weight sensor would show the stabilized load, isn’t that what you need? and about the combined sensor, when would it have the state |
It seems the scale reading (with the 2 sensors values) is returned twice within a short period. I am requesting that the sensor only responds once within a shot period of time. A check could be made to see if the second reading is exactly the same as the first within a short period of time. I am currently doing this using Node-RED to prevent the second reading (which is causing me other issues). It could simply be 'unavailable' unless there is a measurement to return. Cheers |
@Ernst79 this is still an issue. As you can see, the weight and impedance sensors were updated multiple times today. I combine them when both have been received once, for my own purposes. A second reading from a second person returned a reading once a minute for 15 minutes. I'm using Node-RED HA flows to detect when the state changes. |
Hi @Ernst79, any chance you could look at this please? I am still getting lots of readings coming through. Key issue is the Multiple sensor updates and the weight and impedance out of sync. I also think adding a sensor that returns an OK and the weight and impedance as attributes would be a major enhancement. Kind regards |
Could you try the following, in sensor.py, change line 863-874 (only the from class WeightSensor(InstantUpdateSensor):
"""Representation of a Weight sensor."""
def __init__(self, config, key, devtype, firmware, description, manufacturer=None):
"""Initialize the sensor."""
super().__init__(config, key, devtype, firmware, description, manufacturer)
def collect(self, data, period_cnt, batt_attr=None):
"""Measurements collector."""
if self.enabled is False:
self.pending_update = False
return to class WeightSensor(InstantUpdateSensor):
"""Representation of a Weight sensor."""
def __init__(self, config, key, devtype, firmware, description, manufacturer=None):
"""Initialize the sensor."""
super().__init__(config, key, devtype, firmware, description, manufacturer)
def collect(self, data, period_cnt, batt_attr=None):
"""Measurements collector."""
state = self._state
if self.enabled is False or state == data[self.entity_description.key]:
self.pending_update = False
return |
Ok yes that is better. I noticed the impedance is returned in the attributes of the weight sensor. However, it is the previous impedance value, not the new one. I also notice that the impedance seems to be 6 seconds later than the weight update and also seems to wait for the 'weight_removed' to be true. |
Thinking about this again, how about the |
No sorry, that change is worse. Doesn't always report the weight now. |
I have enabled debug - this is what I get in the logs (I have removed your change).
This is what I see as state changes in Node-RED; Looking at this it seems you want the reading when
The person needs to wait for the white line to start flashing for the impedance data to be gathered (I think). So, the weight appears first, then the impedance data. The integration needs to wait until the weight is removed before reporting either. If the weight is removed too soon, report weight and impedance is |
On the basis of the above comments, I suggest the following change - ble_monitor/custom_components/ble_monitor/ble_parser/miscale.py Lines 75 to 79 in d36df5c
if is_stabilized and (weight_removed == 0) and has_impedance:
result.update({"weight": weight})
result.update({"impedance": impedance})
# if is_stabilized and not weight_removed:
# result.update({"weight": weight})
# if is_stabilized and has_impedance:
# result.update({"impedance": impedance}) This results in the impedance and weight sensors reporting once, almost simultaneously. If the scale is not allowed to complete the impedance calculation (indicated by flashing white bars), then the sensors do not report at all. This might be undesireable from your perspective. |
I have no objection, but I don't have this scale, so that's easy for me to say. I propose you test it yourself for a couple of days and if you think it works ok, we will make this change. I can't test it myself unfortunately, as I don't have the scale. The only thing I want to ask you than is to clearly describe the old behavior and the new behavior, such that we can inform the users about the change. |
Ok thanks. I have tested this a couple of times and it has worked reliably. I have also tested stepping off before the impedance has been calculated which results in the other 2 sensors updating, but not the weight or impedance. Can I suggest adding any stabilized weight received to the How about this; Old behaviorThe scale reports multiple ble packets each time it is used and sends the stabilized weight before the impedance has been calculated. The scale also reports an impedance value (if calculated) when the weight is removed. The integration reported on each ble data packet received (via different sensors). This resulted in the weight and impedance sensors being updated multiple times and at different times with the impedance attribute in the weight sensor to hold the old value initially. New behaviorThe person using the scale must wait until the white bars flash - this indicates the impedance has been calculated. If they do not wait, neither the weight sensor or impedance sensor will update. The integration will report once per activation of the scale with a stabilized weight ( |
Ah, this needs to be for the V2 only! |
Regarding your request about adding an attribute to the "weight removed" binary sensor, we might be able to use something like this. if self.entity_description.key == "weight removed":
if "stabilized" in data:
if data["stabilized"] and data["weight removed"]:
self._extra_state_attributes["weight"] = data["non-stabilized weight"]
Add the code behind this line, here
|
Please check if 8.0.4-beta works for you. Weight attribute is added as described above. |
For weight and impedance sensors if the impedance is calculated, then yes. If I step off the scale before the impedance is calculated - not quite. The stabilized weight is set in the If I step off before the weight has stabilized, the |
So, we should make something that sets the But what about the |
I think the attribute should be set to unavailable initially, then when the data appears, set to that new value. The fact the impedance data is reported is enough of a condition to add it to that sensor. |
Ah, didn't read your edit. I think the |
As long as you do not update the sensors, they can stay unchanged internally. With these changes, I just see them both update when the good data has arrived so you never get |
Yes, I understand, But we need to figure out how to define "a new scale session", especially what is triggering a new session. But it might be sufficient to just set it to unavailable when the scale is not stabilized. Could you try changing this lines ble_monitor/custom_components/ble_monitor/sensor.py Lines 903 to 908 in 59bea69
to if self.entity_description.key == "non-stabilized weight":
self._extra_state_attributes["stabilized"] = bool(data["stabilized"])
if "weight removed" in data:
self._extra_state_attributes["weight removed"] = bool(
data["weight removed"]
)
if data["stabilized"] == 0:
self._extra_state_attributes["impedance"] = "unavailable" |
On the basis of the messages captured above, the first message is Stabilized = 0 and the last is Stabilized = 1 with weight removed = 1. I think at that point you could say the current session has ended. |
That should be covered with the above change. Could you check if this works for you? |
Might a check to see if impedance is in the data or and if not then set to |
Please try with 8.0.5-beta. It should now set it to |
Hi @Ernst79 Tested and the condition needs a slight tweak; if "weight removed" in data:
self._extra_state_attributes["weight removed"] = bool(
data["weight removed"]
)
if "impedance" not in data and data["type"] == "Mi Scale V2" and data["weight removed"] == 0:
self._extra_state_attributes["impedance"] = "unavailable" tested
Works as expected. Many thanks for your help and engagement :) |
Ok, will change that in the final release tomorrow. |
8.1.0 has been released as final. Thanks for the sponsoring! |
I am seeing the 2 sensors (weight and Impedance) being updated multiple times when the scale is used.
Can a 'delay' be introduced such that only one update is generated from each occurrence of the scale being used? Perhaps a configuration item for the 'dwell' period?
It would also be useful to have a 'combined' sensor as the weight and impedance are intrinsically linked. Perhaps a new sensor of
scale_reading
with the state ofok
and the attributes oftimestamp
,weight
, andimpedance
.The text was updated successfully, but these errors were encountered: