How to report battery level and signal in Devices UI for new Integration

I鈥檓 working on a new (my first) integration (it鈥檚 a re-vamp of the acmeda integration for the new hub with a completely different protocol). Its a cover.

I have it mostly working, but I鈥檓 unable to get it to report the level of the battery. Specifically in the UI it just has a -:

I have messed with a lot of things, and the closest to something that I think should work is this:

    @property
    def state_attributes(self):
        """Return the state attributes of the device."""
        state_attrs = super().state_attributes
        if self.roller.battery_percent is not None:
            state_attrs[ATTR_BATTERY_LEVEL] = self.roller.battery_percent
            state_attrs[ATTR_VOLTAGE] = self.roller.battery
        return state_attrs

I have also tried using device_state_attributes as per the documentation. I have looked at a bunch of other integrations that report battery level, and this is roughly how they appear to do it - so I think I鈥檓 just missing something obvious.

Sorry for the noob question, I鈥檝e been hitting my head against a wall for a while on this now and can鈥檛 figure this final part out.

If you want to view the code, I have put up my progress so far here, it also requires this lib (which is all work in progress).

Thanks!

The device needs a sensor with the battery device_class

Thanks for the quick reply, that has got me a bit closer, I鈥檓 able to get a single additional value on the device - but unable to get another (Signal Strength).

After several hours and lots of messing around, the best I have got is either a single sensor on the cover, or every sensor and cover as their own devices.

Looking in the forums, someone asked something similar here, using device_state_attributes, but that just adds additional fields to the battery, not the actual cover. What I鈥檓 after is this pane, also showing WiFi strength etc (like for the phone devices in HA):
Screen Shot

What I have figured out is this (much of which I think is by side effect):

Returning the same unique_id for the sensors as the cover will allow a single sensor to be part of the cover device, any others just become their own devices.

Using via_device in the device_state_attributes (as per here) does not do anything best I can tell in the UI - but I maybe giving it the wrong ID? There is basically no documentation as to what it should be, this is the only page when searching for via_device. Looking at other code, best I can tell the value for via_device should be a tuple of (<DOMAIN>, <identifying id>), where identifying id is the value returned by unique_id.

The issue with the above maybe the unique_id - at the moment I鈥檓 using the following for the cover:

    @property
    def unique_id(self):
        """Return the unique ID of this roller."""
        return self.roller.id

Where the self.roller.id is the ID assigned by the hub (it鈥檚 unique, and always remains the same).

For the battery, this then becomes:

    @property
    def unique_id(self):
        """Return a unique identifier for this device."""
        return f"{self.roller.id}-battery"

Which from this page is my best guess as to what it should be.

Now the issue could be something really dumb such as the id is not getting set correctly, as in the UI, I see the id of often sensor.none_battery_6, rather than what I would expect it to be, something like sensor.automate_d55_battery - I have no idea how this is calculated. The cover is doing the right thing, and giving a value of cover.automate_d55. I can鈥檛 find any documentation on this.

So in short, I鈥檓 feeling like an idiot, and unable to figure out how to combine multiple sensors to a single entity. I have tried every combination I can think of looking at the documentation and other code (so much other code, but it鈥檚 all done a little differently from each other), and just not getting it. I feel like it should be easy, but I鈥檓 apparently missing something.

Thanks again.

I figured it out - WOOOO HOOOOO!!!

For anyone else stuck down this rabbit hole, the way to tie multiple devices together is to have identifiers have the same value (probably a single matching entry in the set - don鈥檛 know, it鈥檚 not documented). For example, the identifiers outlined below should be identical on the cover and every single sensor. What I was working from initially was using unique_id for the value in the identifiers, so it sort of appeared to work with a single sensor while the unique_id was not doing the right (I assume).

    def device_info(self):
        """Return the device info."""
        return {
            "identifiers": {(DOMAIN, self.roller.id)},
            "name": self.roller.name,
            "manufacturer": "Automate",
            "via_device": (DOMAIN, self.roller.hub.id),
        }

So after creating my Cover entity, I then created a Sensors entity for each unique value I wanted reported in the UI (for me that was Battery Level and Signal Strength).

Hopefully someone else will be able to find this useful.

Hi there, have you made any progress on this integration? I have just installed some roller blinds, and HA found hub and added via HomeKit controller.

The Rollease Acmeda Automate integration doesn鈥檛 find my hub (Pulse V2).

Interested to see how you have been going with your integration.

Yes! :grinning:

See this thread, with steps to install the dev version (I have been using this for some time now): Rollease Acmeda Automate Pulse hub integration - #219 by sillyfrog

I have actually just started getting this ready for HACS as getting it into core is not really happening (see the PR at Add Automate Pulse Hub v2 support by sillyfrog 路 Pull Request #39501 路 home-assistant/core 路 GitHub ). If you use HACS already, you should be able to add the GitHub - sillyfrog/Automate-Pulse-v2: Rollease Acmeda Automate Pulse Hub v2 integration for Home Assistant repo directly (someone already added a hacs.json), but I personally have not yet used. I鈥檓 hoping to get it into HACS default eventually.