This isn’t my add-on so I can’t compare, but at first sight it doesn’t use mqtt.
Are your other mqtt sensors automatically added or manually added?
If you want to use add-on have you tried my add-on which is basically the same code and config, only the sensors would be automatically added via mqtt
Yes you’re right. The HACS addon does not use mqtt.
I have a 3rd party SleepAsAndroid integration that sends sleep data from phone to mqtt. But it created the sensor automatically.
Now I have this addon installed via supervisor:
Tell me, please, what needs to be changed for the sensors are automatically added?
All instructions are documented. Can you share the full sensors section of your configuration.yaml?
Can you also share your mqtt broker config? (Hide the credentials)
Stupid questions
- have you defined multiple instances of your mqtt broker? You only need one
- can you try and set one of your scale sensor to pull from one of your non scale sensors?
- you mention Sleep As Android but I can’t see it on your mqtt Explorer screenshot. Are you sure you’re using to correct broker?
Yes, but the addon triggers on startup. If you use MQTT sensors with the MQTT message retained, the sensors populate on startup. But another issue is that the addon relies on 2 sensors and does not check both have been updated within a time window, so, you can end up with it triggering on a new weight but old impedance. Double reports if the two sensors are updated at different times · Issue #51 · dckiller51/bodymiscale · GitHub
However, recently I have seen the addon trigger before the sensor has been populated - the major issue with HA is the order things get populated and dependency.
The addon needs to check for unknown
or unavailable
and not trigger in this state. Error reported when sensors not ready · Issue #60 · dckiller51/bodymiscale · GitHub
You were absolutely right!
I messed up with the MQTT settings.
After I corrected the settings in the addon to those that I use in the SleepAsAndroid integration, everything worked!
But now I have 2 weight sensors:
sensor.nika_weight
sensor.nika_weight_2
I made a config according to the recommendations above:
- platform: mqtt
name: "Nika Weight"
state_topic: "miscale/Nika/weight"
value_template: "{{ value_json.weight }}"
# value_template: "{{ value_json['weight'] }}"
unit_of_measurement: "kg"
# json_attributes_topic: "miscale/Nika/weight"
icon: mdi:scale-bathroom
# Below lines only needed if long term statistics are required
state_class: "measurement"
- platform: mqtt
name: "Nika BMI"
state_topic: "miscale/Nika/weight"
# value_template: "{{ value_json['bmi'] }}"
value_template: "{{ value_json.bmi }}"
icon: mdi:human-pregnant
unit_of_measurement: "kg/m2"
# Below lines only needed if long term statistics are required
state_class: "measurement"
Do I understand correctly that I need to delete the weight sensor section in the config.yaml and use the one automatically created by the addon?
And what about this block?
# Below lines only needed if long term statistics are required
state_class: "measurement"
If I remove the sensor from the config, there will be no statistics after the restart?
Ah OK. GitHub - lolouk44/hassio-addons: Xiaomi Mi Scale Add On for Home Assistant - I’d not realised you had done your own code.
I use the GitHub - custom-components/ble_monitor: BLE monitor for passive BLE sensors addon for retrieving the BLE data then pass it on to the miscale Card.
I don’t really want 2 different addons trying to communicate with BT.
@baz123, I’m using both (Xiaomi Mi Scale Add-on and Passive BLE monitor Integration) and didn’t find any issues with both accessing BT. @lolouk44’s solution allows having weight measurements for multiple people as long as there’s a big enough difference between them.
I’ve been bitten before so that’s why I avoid. I’d rather have one integration for getting the data and something else for processing. I also keep the number of addons to a minimum where I can.
I’m doing that via Node-RED currently.
Hey there,
thanks for all your efforts so far.
I am currently planning on integrating my Xiaomi Mi scale into Home Assistant, too.
However, my instance runs in a VM on my server, so I cannot add bluetooth to it. I do have some Raspis laying around, which I’d like to use for this.
I do not have any MQTT sensors or something like that in use so my question is:
What is the best way to realise this scenario? Scale → RPi with BT LE → Home Assistant
Thanks in advance!
Mqtt is still probably the best way to communicate with HA. It’s simple to implement and does not require any additional hardware
Can you not plug in a USB BLE dongle and pass it through to the VM?
That’s what I thought too. However, I am not really experienced with this way. I already installed the mosquitto MQTT broker on my HA yesterday but i don’t know what needs to be installed on my Pi (probably the Xiaomi scale script) and how to pass it to HA. Is there a simple tutorial on how to pass information to HA via MQTT that you (or anybody else) can recommend?
@baz123 I could, but the scale is way out of reach for the server, that is in my rack outside of the living area in a shed.
MQTT is a protocol - it consists of a Broker (server) - that accepts data (that is published to it) and makes it available for other systems to read (subscribe). Your Pi would Publish the data to the Broker and HA would then subscribe to the topic and read it into a sensor. The Broker can be on any machine that is accessible by both on your LAN.
On the Pi, you would use a Pythion (probably) script to read the BLE data, parse it, and publish it to the MQTT broker on your HA install. You then create an MQTT sensor. You need to do lots of Googling, but there are enough keywords here for you to find the answers.
What @baz123 said. You only need to take care of the server, use the same credentials with the add-on / script and use the same credentials with HA
5 years later after starting this thread :
The easiest and most solid way to integrate the Miscale is ESPHome to me. I have setup a complete Bluetooth Low Energy Hub collecting several BLE sensors on a single low cost and low energy ESP32 device. I have also written a documentation (in german) about the necessary configuration and the calculation of the BMI directly on the ESP32. In case it is helpful to you throw this URL in the translator of your choice:
I have EN local on my Home Assistant server. But how I can manually set other language in Lovelace card with [bodymiscale] intagrtion?
For those of you looking to set this up, I just created a step-by-step guide for adding my Mi Body Composition 2 to Home Assistant via ESPHome. I was able to get the MQTT route working correctly as well, but I didn’t document that part.
Anyway, here it is if anyone is still interested: https://smarthomepursuits.com/how-to-add-smart-scale-home-assistant/
Dear All,
Not really related to this thread, but can someone help me with the conditions? Must be something wrong with it and I cannot figure out.
My purpose is to specify who’s standing on the scale
- alias: 'Weight'
trigger:
- entity_id: binary_sensor.ble_weight_removed_mi_scale
platform: state
to: 'on'
condition:
condition: and
conditions:
- condition: template
value_template: "{{ state('sensor.ble_weight_mi_scale') < 61.5 }}"
- condition: template
value_template: "{{ state('sensor.ble_weight_mi_scale') > 58.5 }}"
action:
- service: media_player.volume_set
data_template:
entity_id: media_player.googlehome5624
volume_level: 0.7
- service: tts.google_translate_say
entity_id: media_player.googlehome5624
data_template:
message: >
Your weight is {{states ('sensor.ble_weight_mi_scale') }} kg
Thank you all
A few pointers for you:
- it should be
states('sensor.ble_weight_mi_scale')
notstate('sensor.ble_weight_mi_scale')
(see the missing ‘s’?) - conditions are “and” by default, so you can simplify them.
- you’re most likely comparing a string to a number, add
| int
after your state
Your condition block would look like this:
condition:
- condition: template
value_template: "{{ states('sensor.ble_weight_mi_scale') | int < 61.5 }}"
- condition: template
value_template: "{{ states('sensor.ble_weight_mi_scale') | int > 58.5 }}"
Or even simpler:
condition:
- condition: template
value_template: "{{ states('sensor.ble_weight_mi_scale') | int > 58.5 and states('sensor.ble_weight_mi_scale') | int < 61.5}}"
Dear lolouk44,
Oh my stupidness
I tried and tried but could not figured out what happened.
Thanks a lot!