Add Tradfri Battery sensors and air quality sensor to Starkvind air purifier

as a follow up of Refactor air purifier by ggravlingen · Pull Request #400 · home-assistant-libs/pytradfri · GitHub please let me suggest to add the air quality sensor which is readily available in the Tradfri library for the Starkvind, to the Home Assistant entities.

as @ggravlingen mentions, Fetching Data | Home Assistant Developer Docs would be required.

It would allow to synchronize further action/logic in HA based on a device we have, without requiring additional hardware for measuring air quality.

This is quite a significant change and it would change how data is fetched from the gateway. The integration would probably have to be rewritten completely. Without having studied this in great detail, I believe a downside would be a reduction in the responsiveness on updates of the state of the devices. On the upside, this might make the integration more stable.

Going down this route would allow exposing batteries for all entities and I know this has been a requested feature in the past.

1 Like

yes, that would be awesome too :wink: (batteries)
btw, Ever since I added 2 Starkvind devices, I felt the connection issues to the Tradfri gateway have increased. Though the last Tradfri firmware update has improved things a lot, your words above make me believe it to be a good thing reviewing that aspect too. If responsiveness is at play, constant polling updating of the devices might interfere with robustness of the system.

Introducing the DataUpdateCoordinator would be wise for that matter alone?

To clarify, we don’t poll today, but subscribe to changes. Using the co-ordinator could possibly improve stability, but I don’t know for sure. I rarely experience stability issues myself so it’s not for that reason we should make this change.

No, for sure.
thats not what I suggested. Having the additional functionality would be the driver. Batteries and air quality would be very useful to the toolset.

(if that could streamline some (severe) stability issues we’ve been experiencing that would be a nice side catch…)
I corrected my wording I the previous post

Can only highly support the request and it would add real value and the long awaited battery status display

I’ve been interested in learning about the data co-ordinator for a while so I took a stab at it this weekend. I just invited @Mariusthvdb to the private repo where this sits to test it.

A few words of caution: the process around handling the integration is not super stable. When I added the custom integration to my system, all devices ended up having duplicates. I had to remove
the integration and add it back again, and then restart, for it to work. Consider adding this custom integration as a breaking change.

Also, I don’t have a blind device so I haven’t been able to test if it works. Please let me know if you do and if it works (including the battery status).

Let me know you want to beta test as well. I’d need your Github account handle to grant you access.

Edit: made the repo public to be able to discuss it with others. It’s here: GitHub - ggravlingen/tradfri_custom_component: This is an attempt to refactor the Home Assistant Tradfri integration to use the DataUpdateCoordinator class.

got I up and running (had to smart guess the startup data… being ip and secret code). Not seeing any battery sensors yet, I do see a air purifier sensor :wink:

maybe I need te restart once more. just to be sure: is there a minimum HA version for this? My instance is running 2021.12.6, I take it that would suffice?

o, and: WOW, thanks! great start of the new year thats for sure.


nvm the battery remark, they’re all in!


and the air quality sensor is live:

this is magic! (even though the measurement displays a huge difference for which I checked the app, and ‘Ella’ was switched-off, so I guess it then doesnt measure the quality either). Yep, turning it on immediately shows a better result. Might be a thing to note in the integration: if turned off, the air sensor is not useful?

there is 1 anomaly (also in core btw) for the open close button of my cover:

Ive even tried to edit the .storage files on that, but the KE keeps coming back…

Thanks for testing!

Regarding the sensor, it’s how the pytradfri device reports back the value. That one is easily handled by returning None if the value is 65535.

No idea about that “KE” though, Looks like the data is picked directly from the gateway.

sure, and yes, that would be a good idea (or simply ignore the sensor if the purifier is off.

I dont see my signal repeaters. Did you forget those ? :wink:

Probably did, yes. :upside_down_face: Were those exposed as sensors previously?

No the device is ike this:

I’ve pushed three different fixes to the repo that hopefully addresses the issues raised here. I don’t have any of the missing devices so it’s difficult for me to debug this :frowning:

i installed it, but still dont see the repeaters… will need to have a closer look.

could it be that the core integration on my other instance suffers from this extra traffic to the Gateway? seeing

WARNING (MainThread) [homeassistant.components.tradfri.base_class] Observation failed for Bureau right

on all my devices/entities, and had to reload the integration manually . and again after toggling a light in the CC, my core integration loses connection so it seems
believe we need a speedy migration of the core integration to use your CC setup!

Yes, the gateway seems to be sensitive to extra traffic. I just had to restart mine as it stopped responding completely when doing some testing here.

Still not sure what’s going on here with the repeaters. Will continue to investigate.


btw, I just gave it another restart, with all new files for the fix. The same (even couple of extra) ‘already existing’ errors were issued, and I now have 30 more entities :wink: all with a suffix _2… so this needs a bit more investigating

The _2 suffixes will be fixed if you delete the integration, restart and add it back again:

I had the same issue and using the description above was how I resolved it.

o well, I did it manually for now. Will do like that on a next update :wink:
we might need that sooner than later, because the 2 systems wont co-exist and I’ll have to install this CC on my production system (not possible to live without the Tradfri integration there…)

1 Like

That’s most likely a limitation to the gateway so not anything we can resolve. :frowning: