arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
460 stars 104 forks source link

IQA with BME680 over MQTT #139

Open Millhouse273 opened 4 years ago

Millhouse273 commented 4 years ago

Hi, I'm running a Bosch BME680 at an NodeMCU. The values for temperature, humidity and the IQA are published to an mqtt Brocker on my Rock64. The homebridge runs their too. Now I'm trying to get the data published to HomeKit. For the temperature and humidity its no problem thanks to your great work. But the IQA isn't working after hours of try and error. The type "airqualitysensor" isn't working, because of the output of my BME. The value is in the format XX.XX with no additional information. The range is from 0 to 500, so it is X.XX over XX.XX to XXX.XX The IQA can be translated into 6 categorys of airquality. 0-50 good, 51-100 average, 101-150 little bad, 151-200 bad, 201-300 worse and 301-500 very bad. I tryed other type of accessory, but the range doesn't fit to my output. Is it possible to add a new accessory, so I can use my BME with your plugin? Perhaps I can post the Arduino sketch for other to use...

Thanks an regards

arachnetech commented 4 years ago

I think Homekit's Air Quality Sensor, exposed by homebridge-mqttthing through https://github.com/arachnetech/homebridge-mqttthing#air-quality-sensor, would be the most appropriate device type to use. You'll need to map your numeric value to Homekit's states (represented by homebridge-mqttthing as EXCELLENT, GOOD, FAIR, INFERIOR, POOR) using https://github.com/arachnetech/homebridge-mqttthing#applying-functions-to-mqtt-messages-custom-payload-encodingdecoding, maybe using something like the getAirQuality topic of this sample configuration: https://github.com/arachnetech/homebridge-mqttthing/wiki/Tested-Configurations#air-quality-sensor

Millhouse273 commented 4 years ago

Hi and thanks for the fast response. I tried the function, but in every way I can figure out with my bad programming skills, I get an error on starting homebridge. I tried to copy the code like posted in the Tested-Configurations, but didn't get any result. I don't get what to add for yours "CCS811.eCO2".

My code

"getAirQuality": { "topic": "homebridge/IQA", "apply": "IQA = JSON.parse(message); return (IQA > 300 ? 'sehr-schlecht' : IQA > 200 ? 'schlechter' : IQA > 150 ? 'schlecht' : IQA > 100 ? 'okay' : IQA > 50 ? 'gut' : IQA <=50 ? 'sehr-gut');" },

I think here is the first mistake with wrong states. I'll give it a new try with the real states yout posted. Thanks for that. Can I define them in german or translates my homekit automatically?

arachnetech commented 4 years ago

Are you able to give an example of the messages published by your ESP?