bodymiscale
bodymiscale copied to clipboard
Data lose after restart HA
Not sure if this is expected. Everytime restart HA, all data from bodymiscale will lose and status will become problem.
Je ne sais pas si cela est attendu. À chaque redémarrage de HA, toutes les données de bodymiscale seront perdues et le statut deviendra un problème.
Yes this is normal, the component reads the sensor (s). To compensate, I put in place a node red. https://community.home-assistant.io/t/exemple-xiaomi-miscale-select-the-person-who-weighs-himself-notif-action/299321
There is a RestoreEntity
class that may be subclassed and utilized to implement such functionality.
I have recently forked this repository, and will attempt to add this.
this can be solved in a simple way (when using BLE monitor for Homeassistant):
go to integrations, choose "configure" on the Bluetooth Low Energy Monitor integration, check if "Restore state" is activated, otherwise activate it. Now, after every restart of HA, the last State is shown
Maybe dckiller51 can put that hint into the readme.md
Bluetooth Low Energy Monitor integration,
There is no Bluetooth Low Energy Monitor integration under Configure->intergrations.
are you using esphome or Passive BLE monitor integration?
if you are using esphome, I don´t have a solution, but on passive BLE monitor it is working fine
are you using esphome or Passive BLE monitor integration?
if you are using esphome, I don´t have a solution, but on passive BLE monitor it is working fine unfortunately I using esphome.
Would it be possible to select for the weight and impedance sensors a helper? i have an automation already setup to store the last recorded weight and impedance into a number helper (which gets restored at start time) so this would alleviate this regardless of ble integration or esphome.
Indeed, it could be simpler if it would be possible to specify an input_number
helper as inputs for the integration.
Otherwise it is necessary to add extra template sensors as a workaround to bypass helpers' values like this:
template:
- sensor:
- name: "Weight (last value)"
unique_id: weight_last
unit_of_measurement: "Kg"
icon: "mdi:weight-kilogram"
state: "{{ states('input_number.weight_last') }}"
- name: "Impedance (last value)"
unique_id: impedance_last
unit_of_measurement: "Omh"
icon: "mdi:omega"
state: "{{ states('input_number.impedance_last') }}"
For completeness, input number helpers:
input_number:
weight_last:
name: "Weight (last value)"
min: 0
max: 100
step: 0.01
unit_of_measurement: "Kg"
icon: "mdi:weight-kilogram"
mode: box
impedance_last:
name: "Impedance (last value)"
min: 0
max: 1000
step: 1
unit_of_measurement: "Omh"
icon: "mdi:omega"
mode: box
Automations to update input number helpers when sensor values obtained from ESPHome change:
- id: '1663000060470'
alias: Save weight
description: ''
trigger:
- platform: state
entity_id:
- sensor.weight
condition: []
action:
- service: input_number.set_value
data:
value: '{{ states(''sensor.weight'') | float }}'
target:
entity_id: input_number.weight_last
mode: single
- id: '1663000498790'
alias: Save impedance
description: ''
trigger:
- platform: state
entity_id:
- sensor.impedance
condition: []
action:
- service: input_number.set_value
data:
value: '{{ states(''sensor.impedance'') | float }}'
target:
entity_id: input_number.impedance_last
mode: single
That's almost exactly what Im doing now as well. Just a bummer that the other values from the integration won't get updated till the next weigh in. which is why I had wondered if we could just modify the selection from just those sensor values to just selecting the entity you want (in this case it would be the helpers)
Hello everyone, I follow your comments, have you looked at my proposal to go through node red and Node Red Companion. With this solution no problem after a reboot but given are stored in each sensor node red companions
https://community.home-assistant.io/t/exemple-xiaomi-miscale-select-the-person-who-weighs-himself-notif-action/299321
Sorry, I'm new to HA, and I'm not familiar with Node Red yet.
I don't use node red, nor have any plans to. So to do node red would add a full layer of something new just for this. Just curious (from a developer perspective) what is the concern with allowing the selection of a helper entity? please note, i have done 0 HA development, so I have no idea how involved any of that is :)
I forgot to specify following one of the last updates. Can you check your sensors normally each attribute has its own sensor this one must keep your data after the restart? Can you confirm it for me because my card currently uses the attributes and not the sensors? If this is ok for you then I should revise my card accordingly.
Which update? I am on 3.0.3 and I still show all the sensors as unknown until i get on the scale after a restart.
input_number: weight_last: name: "Weight (last value)" min: 0 max: 100 step: 0.01 unit_of_measurement: "Kg" icon: "mdi:weight-kilogram" mode: box
impedance_last: name: "Impedance (last value)" min: 0 max: 1000 step: 1 unit_of_measurement: "Omh" icon: "mdi:omega" mode: box
Can you please elaborate where to implement this solution as I'm a noob noobie? Thank you in adnvance!
@grego1981 input_number
section which you quoted has to be added to configuration.yaml
file. After it is added you need to restart HA: Developer tools
-> Check configuration
and if the result is green -> Restart
.
Or as a simpler approach, you could do the same via HA web interface without modifying configuration.yaml
.
Just go to Settings
-> Devices & Services
-> Helpers
tab -> Create helper
-> Number
-> Fill the fields with appropriate values -> Create
According to the https://github.com/dckiller51/bodymiscale/releases/tag/v3.0.4 with the very recent version of the plugin it is no longer necessary to create template sensors (the first code snippet in my post). And it should be possible to use input number helpers directly in the plugin.
And automations (the third code snippet) are created via Services
-> Automations & Scenes
-> Create Automation
.
I updated and switched to the helpers. On HA restart though, Im not sure if the integration is triggering before the helpers restore. But in my situation, all the sensors for bodymiscale still show as unknown. BUT, without having to get on the scale, if i wait a bit and then hit reload, it does recalculate everything. What is the trigger mechanism that does the calculations?
@cranky-coder, could you please check:
- if helpers have proper values after HA restart
- that
Weight sensor
andImpedance sensor
in BodyMiScale configuration point to input number helpers (i.e.input_number.xxx
), which preserve their state during HA restart. And not to sensors (i.e.sensor.xxx
), which switch toUnknown
state on HA restart.
Confirmed. Not pointing to the sensors, but only pointing to the input_number helpers. both have valid values.
Thank you. Then I'm out of ideas so far.
What triggers the recalculations? both sensors weight and impedance or just one or the other?
this can be solved in a simple way (when using BLE monitor for Homeassistant):
go to integrations, choose "configure" on the Bluetooth Low Energy Monitor integration, check if "Restore state" is activated, otherwise activate it. Now, after every restart of HA, the last State is shown
Maybe dckiller51 can put that hint into the readme.md
Just wanted to confirm that checking "restore state" in BLE instantly solved this for me (didn't even need a restart).
I had the same issue when using ESPHome and the HA API. I noticed that commenting out api:
and adding the mqtt:
block did the trick (requires MQTT though). No other adjustments necessary. It now seems to survive both esp32 and ha reboots without loosing the calculated values.
Full example:
esphome:
name: "xiaomi-mi-scale"
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
mqtt:
topic_prefix: bodymiscale
discovery: true
broker: 192.168.1.80
port: 1883
username: !secret mqtt_username
password: !secret mqtt_password
discovery_prefix: homeassistant
ota:
password: "REPLACE_ME"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.42
gateway: 192.168.1.1
subnet: 255.255.255.0
esp32_ble_tracker:
scan_parameters:
# default is 320ms:
interval: 160ms
# default is 30ms:
window: 60ms
xiaomi_ble:
sensor:
- platform: xiaomi_miscale
mac_address: '5C:CA:D3:78:A7:04'
weight:
name: "Xiaomi Mi Scale Weight"
id: weight_miscale
on_value:
then:
- lambda: |-
if (id(weight_miscale).state >= 80 && id(weight_miscale).state <= 100) {
return id(weight_user).publish_state(x);}
# else if (id(weight_miscale).state >= 55 && id(weight_miscale).state <= 75) {
# return id(weight_user2).publish_state(x);}
impedance:
name: "Xiaomi Mi Scale Impedance"
id: impedance_miscale
on_value:
then:
- lambda: |-
if (id(weight_miscale).state >= 80 && id(weight_miscale).state <= 100) {
return id(impedance_user).publish_state(x);}
# else if (id(weight_miscale).state >= 55 && id(weight_miscale).state <= 75) {
# return id(impedance_user2).publish_state(x);}
- platform: template
name: Weight User
id: weight_user
unit_of_measurement: 'kg'
icon: mdi:weight-kilogram
accuracy_decimals: 2
- platform: template
name: Impedance User
id: impedance_user
unit_of_measurement: 'ohm'
icon: mdi:omega
accuracy_decimals: 0
# - platform: template
# name: Weight User2
# id: weight_user2
# unit_of_measurement: 'kg'
# icon: mdi:weight-kilogram
# accuracy_decimals: 2
# - platform: template
# name: Impedance User2
# id: impedance_user2
# unit_of_measurement: 'ohm'
# icon: mdi:omega
# accuracy_decimals: 0