Thanks to @redphx’s comment, I attempted to get it into HA via LocalTuya and was able to get it integrated🎉.
After much trial and error, I got all of the Tuya IDs of the device mapped out to HA entities (except for one, which I don’t think is useful anyway). Let me know if anyone is interested in getting this setup in HA and I’ll provide the mappings.
My favorite features that I now have access to are being able to turn off the annoyingly loud sound when interacting with the device and being able to automate the screen brightness! It’s the small things. Having access to the filter lifespan and filter use will also open up a really useful notification automation when it’s time to replace the filter.
All updates are instantaneous between HA and the Smartmi Air Purifier P1. I like having it in HomeKit for easily controlling the fan speed via the UI and to quickly see air quality but this opens up a lot of advanced automations for me in node red (HomeKit may send a notification when it’s time to change the filter but I’m not sure - just got the purifier yesterday).
Would love to know how you did this; I haven’t setup localtuya before and don’t know how to pull the localKey. I’m fine using the cloud device lookup but can this be added to Tuya Cloud even?
How to Integrate Smartmi P1 into Home Assistant via LocalTuya
Quick notes before embarking on this journey:
The Tuya integration is not necessary (I’m not using it). However, this process involves setting up a Tuya cloud developer account. Though according to the LocalTuya GitHub:
Cloud API calls are performed only at startup, and when a local_key update is needed.
I’ve used this integration for a week now and have setup advanced automations in node red and it’s worked extremely well. Communication between HA and the P1 are instantaneous.
It also allows access to various settings and features that you would only be able to access/change through the Tuya/Smartmi app (for example, you can’t turn off the sound or adjust the display brightness in HomeKit).
1. Add Smartmi P1 to HomeKit
This isn’t necessary if your only goal is to get the device in Home Assistant. I use the Home app as my front end (I like the UI) and HA as my backend (all automations are in node red) so I like being able to see and control all of my devices manually through the Home app.
2. Connect the Smartmi P1 to the Tuya Smart app
Download the Tuya Smart app on your phone
If I remember correctly, when you open the app for the first time, it will ask for permission to allow the app to access devices in the Home app. Make sure you allow it.
If you already added the device to HomeKit, in the Tuya app you’ll want to select Me > HomeKit Information.
You should see a device called Air Purifier which is your P1. Select “Bind”. The device is now connected in Tuya.
3. Obtain Tuya local key, client id, client secret, and device id
Watch this tutorial on getting your device’s local key and device id
After you’ve done that, you can easily get your client id and client secret. Go to Cloud > Development
Select the project you created in the tutorial. I called mine home assistant
Now we start mapping Tuya’s internal ID’s to different entities in Home Assistant. I won’t include a screenshot for every ID/entity but I’ll provide the necessary information for each one, which will include:
the Tuya ID followed by what I named it (i.e. 1: Fan means that the Tuya ID is 1 and I named it “Fan”)
entity type in HA (sensor, switch, etc)
other relevant details specific to the entity
1: Fan
Here’s how I setup ID 1, which is the switch that will turn the fan on/off. I called it Fan but you can also call it Air Purifier or whatever else you want. Select SUBMIT when complete.
Another window will pop up where you will select the next HA entity type that you’ll be mapping. In this case, the next entity we’ll setup is the PM2.5 Density, which we want to be a sensor in HA. Select “sensor” and unselect “Do not add any more entities”. You’ll want to uncheck this box each time you see this screen until we’re finished.
valid entries (tuya asks for semicolon separated list):
0_hour;1_hour;2_hour;4_hour;8_hour
user friendly options (tuya asks for semicolon separated list):
off;1 hour;2 hours;4 hours;8 hours
104: Filter Lifespan
entity type: sensor
description: current filter life remaining in percent
105: Filter Use
entity type: sensor (or number)
unit of measurement: hours
description: number of hours the current filter has been in use. In the Tuya app, this corresponds to “Filter useh” under “Setting”. This can be set as a number that can be adjusted (it’s also editable in the Tuya app). However, this number should automatically reset to 0 after following the “Resetting the Filter instructions in the manual”. For that reason, I’ve left it as a sensor.
You can now check the box “Do not add any more entities”. Note that I couldn’t figure out what Tuya ID 22 was. I set it as a sensor for awhile but it’s value never changed from 0 so I ended up removing it.
1 question though, how do you add data points later? For example, I noticed that you have Fan Speed and Screen Brightness, I didn’t see an option for the fan speed, and I missed the screen brightness. Is there a way to go back and add those data points or do I need to delete the device and reconfigure the entire setup?
Wow. Thank you sooo much @ryanmsnyder for this instruction. I was waiting for a possibility to add my Smartmi P1 to Home Assistant since I bought it 1,5 years ago. Finally it is working!
Great instruction for adding it.
I just had some small problem with the mapping because I was following your guide and didnt realize that the internal ID 22 was not written in your instruction. So the following IDs were mapped wrong in my first attempt. Maybe you can include ID 22 in your instruction (I added it as sensor with name Test). This could help other users to avoid this mistake. And after the setup I also removed this ID from my setup.
Thanks for this! What device types did you use for these additional entities? I’d love to get the manual fan speed setting working, but I haven’t been able to find the right combination yet.
Can you also please confirm that when you click on the edit button it lets you add additional data points? I’m seeing that it lets me delete existing data points, but not add anything new. Running 2022.8.5 with version 4.0.1 of the LocalTuyal integration. Just wondering if something changed or if I’m just blind.
[update]
For the fan speed. Looks like you can include the 109 setting in the initial “fan” definition as shown here and it will then expose the fan speed in the home assistant controls
@ald112 I also had this exact error when I used the API Explorer on the Tuya IoT Platform. I simply used the wrong API. The correct one is located here:
hey @vegardan thanks for responding
you tried with p1?
I don’t succeed on all the regions to get the key, same permission deny ):
you on which region you are on the tuya app on the phone?
Thanks so much for figuring out the entities. Got both my P1’s in.
I never had it in the tuya/smart life app (just three bulbs I couldn’t flash) but a quick bind from already being in HomeKit and then using the Tuya-Cli wizard on the pi which I hadn’t used in like 16months and boom works like a charm.
I thought my developer account expired many months ago but the tuya cli tool on the Pi with node.js/npm works fine still so not sure the developer account was needed but maybe it still was - I know things have changed on tuya developer side for sure but thought I’d let people know the Tuya-Cli wizard works like a charm for getting the token secret if check out GitHub repo.
Forgot to test everything out and fan speed controls weren’t working so I tweaked the max fan integer from 9 to 100 and also changed DP value type selector at the bottom of the pop-up window to “int” and now everything is working like a charm except for screen brightness but I’ll find the correct tuya values and report back when I do although not too concerned about that entity.
Thanks again homies! @ryanmsnyder - what did the screen brightness input values end up being
The smartMi manual says it has a light/lux sensor on top - too bad that doesn’t seems to be ID22, that or I was hoping it was a switch to reset filter life. Works great with the HACS purifier card too!
I still dont succeed
the p1 working via smartmi app
working via HomeKit app
I see it on Tuya via HomeKit information - binder
but when I try to get device info on Tuya platform I always get permission deny.
@ryanmsnyder detailed the vast majority of the setup above, and @ballakers
tweaked the fan config to get the speed working. I figured out the
remaining data points, and I’m posting an updated configuration guide
below:
How to Integrate Smartmi P1 into Home Assistant via LocalTuya (Updated)
1. Start the Guide at the Following Post
Notes:
Complete steps 1 - 4
Start step 5, and come back after reaching the first “Entity type
selection” prompt
2. Continue Adding P1
Notes:
When adding any data point, you will be prompted to select a platform
before selecting the data point (ID). This updated guide lists the
platform selection, and then all the necessary configuration options
follow.
Starting with the second data point, you must uncheck “Do not add any
more entities” to add each additional data point.
The friendly names for your entities are person preference. You can name
them whatever you choose.
Useful DPs:
(These data points control functions or provide important data)
Platform: fan
ID: 1
Friendly name: Smartmi Air Purifier P1
Fan Speed Control dps: 109
minimum fan speed integer: 1
maximum fan speed integer: 100
DP value type: int
Platform: sensor
ID: 19
Friendly name: Smartmi Air Purifier P1 Timer Remaining
Unit of Measurement: min
Device Class: duration
Platform: sensor
ID: 2
Friendly name: Smartmi Air Purifier P1 PM2.5
Density Unit of Measurement: µg/m³
Device Class: pm25
Platform: sensor
ID: 102
Friendly name: Smartmi Air Purifier P1 PM10 Density
Unit of Measurement: µg/m³
Device Class: pm10
Platform: sensor
ID: 104
Friendly name: Smartmi Air Purifier P1 Filter Life Remaining
Unit of Measurement: %
Platform: sensor
ID: 105
Friendly name: Smartmi Air Purifier P1 Filter Usage
Unit of Measurement: h
Device Class: duration
Platform: sensor
ID: 22
Friendly name: Smartmi Air Purifier P1 Fault Alarm
*This data point isn’t documented, but the name of the data point was pulled from the Tuya IoT API. 0 means there is no fault. Other potential values are unclear.
Completionist DPs:
(These data points are completely unnecessary)
Platform: select
ID: 108
Friendly name: Smartmi Air Purifier P1 Device Color
Valid entries: unknown;dark_grey;sliver
User Friendly options: unknown;Silver;Dark Gray
*The values for this data point are reversed in the app. Also, the misspelled “sliver” is the actual valid entry.
Platform: sensor
ID: 107
Friendly name: Smartmi Air Purifier P1 Country Code
*This data point could be configured as a select instead, but the device won’t accept any changes other than the current country and unknown.
ID: 109
*This data point is the manual fan speed setting. Don’t bother configuring this, as it is redundant. It is already linked to and controlled by the fan above.