michbeck100/pimatic-hap

Add MQTT Sensors to HAP

tjandt opened this issue · 12 comments

Hi,

is it possible to add mqtt sensors to homekit?
https://www.npmjs.com/package/pimatic-mqtt

Everything apart from Buttons and the General Sensor should work already oob.
Are you asking especially for the general sensor?

my pimatic-mqtt configuration looks like:
{
"class": "MqttSensor",
"id": "esp01",
"name": "ESP-01",
"mqtturl": "mqtt://localhost",
"attributes": [
{
"name": "dht-11-temperature",
"topic": "/esp01/dht11/temperature",
"type": "number",
"unit": "°C",
"acronym": "DHT-11-Temperature"
},
{
"name": "dht-11-humidity",
"topic": "/esp01/dht11/humidity",
"type": "number",
"unit": "%",
"acronym": "DHT-11-Humidity"
},

So I think these devices are not seen as temperature sensors?!

No they are not, because the device type of MqttSensor is just Sensor. The hap plugin needs some more information, what type the sensor is, e.g. TemperatureSensor. HomeKit just doesn't support "any" generic Sensor. It must be more specific.

So it's not possible do use the config to be more specific? It has to be done in the pimatic-mqtt plugin?

Just as an idea would it be possible to adopt the hap plugin to manually define sensors via the config.json

Everything is possible ;-). I might be able to implement this, but still, this is restricted to just the devices that HomeKit actually supports. I think it would make more sense to implement an MqttTemperatureSensor. But that would have to be implemented in the MQTT plugin.

Created feature request: wutu/pimatic-mqtt#7

wutu commented

Hi,
May I ask why this is not working?

"class": "MqttSensor",
"id": "esp01",
"name": "ESP-01",
"attributes": [
  {
    "name": "dht-11-temperature",
    "topic": "/esp01/dht11/temperature",
    "type": "number",
    "unit": "°C",
    "acronym": "temperature"
  },
  {
    "name": "dht-11-humidity",
    "topic": "/esp01/dht11/humidity",
    "type": "number",
    "unit": "%",
    "acronym": "humidity"
  }
],
"hap": {
      "service": "TemperatureSensor",
      "exclude": false
    }

Because pimatic-hap expects a certain interface for each device. A TemperateSensor has the function getTemperature() which gets called by pimatic-hap.
The service element in the config is just for overriding a default value and changes the way how HomeKit shows the device.

As for now this feature won't be created because of the answers in wutu/pimatic-mqtt#7

Hey there, did you found a way to get mqtt temperature in HomeKit?

A few releases ago I've added a generic sensor that checks if the device has the attributes 'temperature' or 'humidity' and adds them as HomeKit sensors then. I had a look at the mqtt plugin and as far as i can tell it should work.
Could you please test if it works if you name the attributes accordingly.

{
  "name": "ESP01 with battery",
  "id": "esp01",
  "class": "MqttSensor",
  "attributes": [
    {
      "name": "temperature",
      "topic": "myhome/firstfloor/office/esp01/dht11/temperature",
      "type": "number",
      "unit": "°C",
      "acronym": "DHT-11-Temperature"
    },
    {
      "name": "humidity",
      "topic": "myhome/firstfloor/office/esp01/dht11/humidity",
      "type": "number",
      "unit": "%",
      "acronym": "DHT-11-Humidity"
    }
  ]
}

oh yes, it works. Thanks a lot :)