hcpy2-0 / hcpy

Python tool to talk to Home Connect appliances over the local network (no cloud required)
114 stars 19 forks source link

add mqtt autodiscovery for homeassistant #52

Closed pmagyar closed 3 months ago

pmagyar commented 7 months ago

https://www.home-assistant.io/integrations/mqtt/#discovery-messages we can create sensors directly in mqtt which the mqtt integration will automatically add to homeassistant.

Eg.

{
  "name": "Dishwasher",
  "unique_id": "dishwasher_SERIAL",
  "state_topic": "homeassistant/dishwasher/state",
  "value_template": "{{ value_json.PowerState }}",
  "payload_on": "On",
  "payload_off": "Off",
  "json_attributes_topic": "homeassistant/dishwasher/state",
  "device": {
    "identifiers": "dishwasher_SERIAL",
    "name": "Dishwasher",
    "manufacturer": "SIEMENS",
    "model": "SN55TS00CE",
    "serial_number": "SERIAL"
  },
  "availability": [
    {
      "topic": "homeassistant/LWT"
    },
    {
      "topic": "homeassistant/dishwasher/LWT"
    }
  ],
  "availability_mode": "latest"
}
image
Meatballs1 commented 7 months ago

What approach do you want to take? Do we want a library of known models with preformed configuration, or do you want to inspect the capabilities from devices.json and build a configuration from that?

pmagyar commented 7 months ago

I think generally we should use the devices.json as base. To maintain a library with known models and expand that, doesn't sound sustainable. Maybe we need special configurations for some devices. This can be done through a library. But as start the devices.json is enough.

zibous commented 4 months ago

I use the mqtt sensor setting (simple):

Example:

mqtt:
    - sensor:
        - name: "Dishwasher"
          unique_id: "dishwasher_SERIAL"
          icon: mdi:dishwasher
          state_topic: "homeconnect/dishwasher/state"
          device:
            identifiers: "dishwasher_SERIAL"
            name: "Dishwasher"
            manufacturer: "SIEMENS"
            model: "SN55TS00CE"
            serial_number: "SERIAL"
            suggested_area: Kitchen
          availability:
            - topic: "homeconnect/dishwasher/LWT"
          availability_mode: all
        - name: "Internal Errot"
          unique_id: "dishwasher_InternalError"
          icon: mdi:dishwasher-alert
          state_topic: "homeconnect/dishwasher/state"
          value_template: "{{value_json.InternalError|default('Off')}}"
          payload_on: "On"
          payload_off: "Off"
          entity_category: diagnostic
          device:
            name: "Dishwasher"
            identifiers: "dishwasher_SERIAL"
          availability:
            - topic: "homeconnect/dishwasher/LWT"
          availability_mode: all

see: https://github.com/zibous/homeconnect-hcpy/blob/main/homeassistant/dishwasher.yaml

jamesremuscat commented 3 months ago

I started to play around with this before I discovered this issue: https://github.com/jamesremuscat/hcpy/tree/feature/ha-discovery

Currently generates discovery messages based on devices.json. My next step will be to try and work out how to specify appropriate Home Assistant "component types" - right now everything's a generic sensor, but for some things e.g. binary_sensor might be better; likewise some things could use a specified device_class.