michbeck100 / pimatic-hap

Pimatic homekit bridge
GNU General Public License v2.0
30 stars 10 forks source link

Add MQTT Sensors to HAP #31

Closed tjandt closed 7 years ago

tjandt commented 8 years ago

Hi,

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

michbeck100 commented 8 years ago

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

tjandt commented 8 years ago

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?!

michbeck100 commented 8 years ago

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.

tjandt commented 8 years ago

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

michbeck100 commented 8 years ago

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.

michbeck100 commented 8 years ago

Created feature request: https://github.com/wutu/pimatic-mqtt/issues/7

wutu commented 8 years ago

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
    }
michbeck100 commented 8 years ago

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.

michbeck100 commented 8 years ago

As for now this feature won't be created because of the answers in https://github.com/wutu/pimatic-mqtt/issues/7

ManuelW77 commented 7 years ago

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

michbeck100 commented 7 years ago

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"
    }
  ]
}
ManuelW77 commented 7 years ago

oh yes, it works. Thanks a lot :)