aschzero / homebridge-airmega

Homebridge plugin for the Coway Airmega air purifier.
34 stars 19 forks source link

Using air quality sensor for automation #6

Closed brianmario closed 5 years ago

brianmario commented 5 years ago

I've been trying to figure out if there are other accessories that allow this, but I assume any sensor can be used to create an automation within the Home app. That could very likely not be the case, but based on what I read over at https://appleinsider.com/articles/18/08/28/eve-room-2-review-climate-monitoring-and-homekit-siri-automation (see the "Rules and automation" section) it appears that device allows automation around air quality and/or temperature sensors:

As an example, an air purifier can come on when the air quality drops. Or the ceiling fan can turn on in the living room when the temperature gets too high on a muggy day. A dehumidifier or a humidifier can spin up when the humidity level raises or lowers.

Maybe there's some trait ("Characteristic" ?) that needs to be exposed on the air quality sensor provided via this plugin that would allow it to be used as part of an automation?

I'll continue to do some research and will send a pull request if I figure something out. Figured I'd ask first in case you have an answer already ;)

Thanks for putting this plugin together!!

aschzero commented 5 years ago

Hi @brianmario this functionality is definitely possible! The reason why automations aren't currently supported is because the purifier/air quality states are only updated when you open the Home app (or a third-party HomeKit app).

To support automations, the plugin would need to be updated to include a long-running timer which would periodically poll the API and retrieve the most up-to-date values. The only question is how often it should poll... I could see this being a configurable option so the user would be able to supply an interval in seconds. Something like:

"platforms": [
  {
    "platform": "Airmega",
    "username": "myusername",
    "password": "password123",
    "poll_interval": 3600
  }
]

If this sounds reasonable to you, I can get started working on this and have a new release in the next few days.

brianmario commented 5 years ago

I think this would be great to add regardless, but the issue I was talking about (for me) was that the air quality sensor wasn't showing up in the automations section of the Home app at all. Like even if it was updating more regularly, I can't even create an automation with it to start with. I have a HomeKit motion sensor as well and that's the only thing that shows up that I can do anything with.

I wonder if there's some special attribute we'd need to have this plugin report as supporting so the Home app recognizes the air quality sensor as something that can be used as an automation trigger?

aschzero commented 5 years ago

Ah ok, thanks for the clarification. You are correct in that HomeKit does support accessories like temperature, humidity, air quality, etc. to be used as automation triggers. The caveat is that the Home app is pretty limited and does not expose them to create automations.

A common workaround is to use a third-party HomeKit app, such as the Eve app, to create these automations instead. This article has more info and walks you through creating air quality automations: https://blog.evehome.com/automation-for-air-quality/

brianmario commented 5 years ago

Oh interesting ok. I'll take a look at doing that for now. Kind of a bummer Apple's Home app is so limiting in that way.

In the meantime, it would be awesome to get a poll interval added to keep the various values up to date in the background.

Thanks for the help!