Affordable Smart Wearable meets Home Assistant

Hi everyone!

For people looking for an affordable wearable device that can control your Home Assistant and update Health / Fitness data to Home Assistant, this might be interesting for you.

ZeppOS Wearable App


Home Assistant Cards

yaml configuration
type: custom:config-template-card
entities:
  - sensor.amazfit_band_7_bram_sleep_minutes
variables:
  sleep_duration: states['sensor.amazfit_band_7_bram_sleep_minutes'].state+'min'
  sleep_start: >-
    states['sensor.amazfit_band_7_bram_sleep_minutes'].attributes.sleep_stage_data[0].start
    +'min'
card:
  type: custom:apexcharts-card
  apex_config:
    grid:
      show: true
    legend:
      formatter: |
        EVAL:function(seriesName, opts) {
          return seriesName
        }
    tooltip:
      x:
        format: hh:mm
    stroke:
      show: true
      curve: straight
  graph_span: ${sleep_duration}
  span:
    start: day
    offset: ${'+' + sleep_start}
  yaxis:
    - min: 0
      max: 4
      apex_config:
        tickAmount: 4
        labels:
          formatter: |
            EVAL:function(value) {
              if (value == 4) {
                return "Awake";
              }
              else if (value == 3) {
                return "REM";
              }
              else if (value == 2) {
                return "Light";
              }
              else if (value == 1) {
                return "Deep";
              }
            }
  series:
    - entity: sensor.amazfit_band_7_bram_sleep_minutes
      name: Awake
      color: red
      stroke_width: 40
      data_generator: |
        let data = []
        entity.attributes.sleep_stage_data.map((val) => {
          if (val.model == 7) {
            let start = moment().startOf('day').minutes(val.start).valueOf();
            let stop = moment().startOf('day').minutes(val.stop).valueOf();
            data.push([start, 4]);
            data.push([stop, 4]);
            data.push([stop, null]);
          }
        });
        return data;
    - entity: sensor.amazfit_band_7_bram_sleep_minutes
      name: REM Sleep
      color: '#2a7fbd'
      stroke_width: 40
      data_generator: |
        let data = []
        entity.attributes.sleep_stage_data.map((val) => {
          if (val.model == 8) {
            let start = moment().startOf('day').minutes(val.start).valueOf();
            let stop = moment().startOf('day').minutes(val.stop).valueOf();
            data.push([start, 3]);
            data.push([stop, 3]);
            data.push([stop, null]);
          }
        });
        return data;
    - entity: sensor.amazfit_band_7_bram_sleep_minutes
      name: Light Sleep
      color: '#2a3dbd'
      stroke_width: 40
      data_generator: |
        let data = []
        entity.attributes.sleep_stage_data.map((val) => {
          if (val.model == 4) {
            let start = moment().startOf('day').minutes(val.start).valueOf();
            let stop = moment().startOf('day').minutes(val.stop).valueOf();
            data.push([start, 2]);
            data.push([stop, 2]);
            data.push([stop, null]);
          }
        });
        return data;
    - entity: sensor.amazfit_band_7_bram_sleep_minutes
      name: Deep Sleep
      color: '#7a489c'
      stroke_width: 40
      data_generator: |
        let data = []
        entity.attributes.sleep_stage_data.map((val) => {
          if (val.model == 5) {
            let start = moment().startOf('day').minutes(val.start).valueOf();
            let stop = moment().startOf('day').minutes(val.stop).valueOf();
            data.push([start, 1]);
            data.push([stop, 1]);
            data.push([stop, null]);
          }
        });
        return data;
    - entity: sensor.amazfit_band_7_bram_sleep_minutes
      name: Heart Rate
      color: rgb(245, 39, 39)
      opacity: 0.7
      stroke_width: 1
      data_generator: |
        let min_in = entity.attributes.sleep_hr_data[0];
        let max_in = entity.attributes.sleep_hr_data[0];  
        const min_out = 0.65
        const max_out = 4
        entity.attributes.sleep_hr_data.forEach((val) => {
          if (val < min_in) {
            min_in = val;
          }
          if (val > max_in) {
            max_in = val;
          }
        });
        let data = []
        let t_start = entity.attributes.sleep_stage_data[0].start-1
        entity.attributes.sleep_hr_data.map((val) => {
            t_start += 1
            let t = moment().startOf('day').minutes(t_start).valueOf();
            let newVal = (val - min_in) * (max_out - min_out) / (max_in - min_in) + min_out;
            data.push([t, newVal]);
        });
        return data;
  card_mod:
    style: |
      ha-card {
        overflow: unset !important;
      }
      .apexcharts-tooltip.apexcharts-active {
        display: none;
      }

yaml configuration
type: custom:config-template-card
entities:
  - sensor.amazfit_band_7_bram_heart_rate
variables:
  span: >-
    states['sensor.amazfit_band_7_bram_heart_rate'].attributes.today_values.length+'min'
card:
  type: custom:apexcharts-card
  graph_span: ${span}
  span:
    start: day
  series:
    - entity: sensor.amazfit_band_7_bram_heart_rate
      stroke_width: 1.5
      color: '#e35d54'
      data_generator: |
        var start = new Date();
        start.setHours(0,-1,0,0);
        const min = 60000;
        let t0 = start.getTime()
        return entity.attributes.today_values.map((val) => {
          t0 += min
          return [t0, val];
        });

ZeppOS app that uses the Home Assistant REST API to control entities and updates the wearable sensors to Home Assistant including:

  • Daily Heart Rate values
  • Recent Sleep data
  • Battery %
  • PAI values
  • Daily Steps
  • Daily Calories burnt
  • Daily Standing hours
  • Wear status

A few months ago, I “upgraded” my wearable device from an old, slow and expensive Fossil smart watch to a €35,- smart band (Xiaomi Mi Band 7). The main features that I require from my wearable is that it can control my Home Assistant entities, and keep track of my health / fitness (and of course display the time).

I became aware of the Smart Band concept, but most of them do not support the Home Assistant Companion App (which is on WearOS watches only), or app development at all. The brand that I found that allows app development on their smart bands/watches is Zepp Health through their wearable operating system called ZeppOS. The company owns the Amazfit brand which has a line of wearable products that use ZeppOS, but also some other wearables have ZeppOS, such as the Xiaomi Mi Band 7.

I found the ha-zepp repository which already has (limited) Home Assistant entity control using the REST API. I added some extra entity types that I required myself, and asked the owner of the repository if I could post about it here, which was fine. I am currently working on the feature that updates the wearable sensors to Home Assistant and trying to make this a stable background updater. The picture on the top of the HA lovelace is an example UI for the wearable sensors. I might follow up on this post if there is any interest.

NOTES:

  • The Mi Band 7 is not officially supported for ZeppOS app development, but its possible to pair it as the Amazfit Band 7 device using this modified Android APK of the Zepp App.

  • The ha-zepp app is created specifically for the Mi Band 7, but could also be built for any other Zepp OS 1.0 device.

11 Likes

This looks very interesting. Can you add the modified apk to this forum I cannot find it in the link you posted. Is the app just the standard Zepp app

No it has to be a modified version of the Zepp app (can’t be downloaded via the play store). It seems that the all the download links on the russian forum linked on the github page are down. Here is a temporary download link from the apk I used (bit older version though)

Thank you I am getting one of these for Christmas and so I am going to work on adding in stuff like unlocking my door and such with the band

I also found this very good documentation explaining how to write the modified apk while I was trying to find the modified APK so if we want to build it ourselves it appears possible Пишем приложение на Mi Band 7 с сервисной частью / Хабр

I am planning on getting an Amazfit Band 7 in the future, since it has official support for the ZeppOS app development and you can just use the official Zepp app with all its features (I believe the map is missing now). I like the Mi Band 7 for its size and form (especially during sport activities).

Do note that the updating of sensor data to Home Assistant is not perfect. After a while it suddenly stops updating (did not find the reason yet) and you have to reset it. The PAI sensor also seems to round the values (e.g. 85 is shown as 80). Feel free to update the code (I am not the owner of the linked repository, but the man will respond to pull requests).

I might share my HA lovelace configuration later so you are able to build the graphs for the sleep data etc. Let me know if you need anything.

1 Like

Thanks I appreciate it

Got my mi band 7 all setup. While I was at it I decided to rewrite the app to make it easier to navigate. I added 3 categories: Devices, scripts, and sensors




2 Likes

Looks nice! Do you have the source code uploaded somewhere?

Not yet I’ll try and add it to GitHub this weekend

Did you finally upload the code? That looks really interesting! Thanks :slight_smile:

Could you upload the APK? It seems that there are no working download links :frowning:

I try adding my mi band 7 but it says that i need a newer version? How can i fix that?

Did you try to pair it as an Amazfit Band 7? I did not have this issue.

How do i pair it as a amazfit band 7?

I don’t know how the pairing process went again, it’s been a while. You should either be able to select the Amazfit Band 7 in the pairing process or it should just pair automatically as that device. Can you provide some images of your issue?

Maybe ask on the russian forums. I am still using the same Zepp app version and everything is working fine. Did you try both pair options?

Also make sure you are not logged in with Google in the app, as noted on the Github page