>>> Join Us in the Fight Against Air Pollution

AirGradient Forum

Noob looking for simple way to do something

Hi all. I would like a smart outlet to activate when PM2.5 levels rise above zero. I am overwhelmed with where to even start searching for solutions. Is there a certain feature needed in the smart outlet I buy, and what would be the easiest way to accomplish this? I do have a Raspberry Pi that I’m not using, and I’m comfortable learning new tech.

Using the Raspberry Pi, I would setup an instance of HomeAssistant, which can manage multiple smart home device integrations and provide automation. The easiest way to use HomeAssistant is to install a dedicated SD card image that runs an OS specific for running HomeAssistant. It is the quickest to get up and running, but dedicates that device to running HA.

With recent additions to the AirGradient code to provide local API access, you could do some integrations with that, but I choose to install an add-on to HomeAssistant called ESPHome that creates firmware for devices to easily integrate with HomeAssistant. I then maintain some configuration files to make it easy to setup your AirGradient hardware to run ESPHome and have access to all of the sensors.

ESPHome devices are detected by HomeAssistant and then you can start creating automations based on that data, and would let you control a smart plug that works with HomeAssistant to turn it off and on as needed. I know the Kasa brand of plugs works with HA, but many others do as well
Smart Plugs | Kasa Smart

There is a lot to learn here, but I find it really fun and even HomeAssistant itself can do a lot, so worth checking out even if you don’t get to all of these steps right away.

3 Likes

I have a lot of little one-off tasks like this I do as scheduled tasks in PowerShell, since it’s very flexible and I have a Windows machine running in my house 24/7. I know PowerShell is supported on other platforms now as well, though I’ve only used it on Windows. I also use Shelly Plugs, which have a very simple REST API. You could set this little script to run at whatever interval, once every few minutes or so.

#Query AirGradient current values, substitute airgradient.local for the hostname or IP of your device
$airGradient = Invoke-RestMethod -Uri "http://airgradient.local/measures/current"

#Query Shelly Plug status, substitute shellyplug.local for the hostname or IP of your device
$outletStatus = Invoke-RestMethod -Uri "http://shellyplug.local/relay/0?status"

#If PM2.5 values are greater than 0 and the outlet is off, turn it on
if ($airGradient.pm02 -gt 0 -and $outletStatus.isOn -eq $false) {
	Invoke-RestMethod -Uri "http://shellyplug.local/relay/0?turn=on"
}
#If PM2.5 values are 0 and the outlet is on, turn it off
elseif ($airGradient.pm02 -eq 0 -and $outletStatus.isOn -eq $true) {
	Invoke-RestMethod -Uri "http://shellyplug.local/relay/0?turn=off"
}
#Else do nothing
else {
	#Do nothing
}
1 Like