mduran80 / pymadoka

A python library to control Daikin BRC1H (Madoka) thermostat
MIT License
26 stars 8 forks source link

the `available` field in MQTT #13

Open mario-tux opened 1 year ago

mario-tux commented 1 year ago

I'm trying to use pymadoka-mqtt to manage my Dakin controllers from HA without the (pending) specific integration. I'm using the MQTT HVAC component with the following configuration:

mqtt:
  climate:
    - name: Daikin Studio Thermostat
      unique_id: daikin-studio
      availability:
        - topic: "madoka/daikin-studio/available"
          payload_available: "1"
          payload_not_available: "0"
      current_temperature_topic: "madoka/daikin-studio/state/get"
      current_temperature_template: "{{ value_json.temperatures['indoor'] }}"
      fan_modes:
        - "high"
        - "medium"
        - "low"
        - "auto"
      fan_mode_command_topic: "madoka/daikin-studio/fan_speed/set"
      fan_mode_command_template: "{% set values = { 'auto':'AUTO', 'low':'LOW', 'medium':'MID', 'high':'HIGH' } %}{{ values[value] }}"
      fan_mode_state_topic: "madoka/daikin-studio/state/get"
      fan_mode_state_template: "{% set values = { 'AUTO':'auto', 'LOW':'low', 'MEDIUM':'medium', 'HIGH':'high' } %} {{ values[value_json.fan_speed['heating_fan_speed']] if value_json.operation_mode['operation_mode']=='HEAT' else values[value_json.fan_speed['cooling_fan_speed']]}}"
      modes:
        - "auto"
        - "off"
        - "cool"
        - "heat"
        - "dry"
        - "fan_only"
      mode_command_topic: "madoka/daikin-studio/operation_mode/set"
      mode_command_template: "{% set values = { 'auto':'AUTO', 'heat':'HEAT', 'cool':'COOL', 'fan_only':'FAN', 'dry':'DRY', 'off':'OFF' } %}{{ values[value] if value in values.keys() else 'AUTO' }}"
      mode_state_topic: "madoka/daikin-studio/state/get"
      mode_state_template: "{% set values = { 'off':'off', 'HEAT':'heat', 'COOL':'cool', 'FAN':'fan_only', 'AUTO':'auto', 'DRY':'dry' } %} {{values[value_json.operation_mode['operation_mode']] if value_json.power_state['turn_on'] else 'off' }}"
      min_temp: 17
      max_temp: 31
      precision: 1
      temperature_state_topic: "madoka/daikin-studio/state/get"
      temperature_state_template: "{{ value_json.set_point['heating_set_point'] if value_json.operation_mode['operation_mode']=='HEAT' else value_json.set_point['cooling_set_point']}}"
      temperature_command_topic: "madoka/daikin-studio/set_point/set"
      temperature_command_template: "{{ int(value) }}"
      temperature_unit: "C"
      temp_step: 1
      device:
        manufacturer: "Daikin"
        via_device: "Madoka"
        name: "Daikin Madoka Remote Controller"
        model: "Madoka (BRC1H)"
        identifiers: "BRC1H"

I'm still tweaking this configuration but it works for 80% of the cases: there are issues with the double setpoints as reported in the README of the project. My configuration is a minor adjustment of the one published by @angeloniclaudio in https://github.com/mduran80/pymadoka/issues/12 : thanks to Claudio!

I'm opening this report because there is another issue with the MQTT available field: it looks that it is not "refreshed" by pymadoka-mqtt agent and HA considers it valid only if it is "fresh". Few experiments can clarify the behavior:

As long as I understand, it looks that the available field should be "refreshed" as long as the pymadoka-mqtt agent keeps the connection with the physical thermostat.

mduran80 commented 1 year ago

Implemented in latest version https://github.com/mduran80/pymadoka/tree/0.2.8

The available message is sent whenever the device is updated.

rekkebus commented 1 year ago

Great, will give this a go somewhere next week. I noticed the availbe topic is never set to 0 on disconnect. I hacked in a last_will statement in a previous version of the mqtt broker to have it set to 0 on disconnect.

mario-tux commented 1 year ago

@mduran80 I can confirm that now, upon HA restart, the thermostat returns available after few seconds. If, keeping the mymadoka-mqtt agent active, if I stop the system bluetooth service I can spot bluetooth connections errors in the debug output but the thermostat remains available in HA. It should post available=0 in such cases, right?

mduran80 commented 1 year ago

@mduran80 I can confirm that now, upon HA restart, the thermostat returns available after few seconds. If, keeping the mymadoka-mqtt agent active, if I stop the system bluetooth service I can spot bluetooth connections errors in the debug output but the thermostat remains available in HA. It should post available=0 in such cases, right?

Yes, I forgot to add that case, will do soon.

mduran80 commented 1 year ago

available=0 fixed in 0.2.11

eduardoboucas commented 7 months ago

@mario-tux could you please share the config file you're using with pymadoka-mqtt? I'm trying to get this working but it's hard to come by full examples that show both the pymadoka-mqtt and the Home Assistant configs.

Thanks!

mario-tux commented 7 months ago

@mario-tux could you please share the config file you're using with pymadoka-mqtt? I'm trying to get this working but it's hard to come by full examples that show both the pymadoka-mqtt and the Home Assistant configs.

Sorry, I switched on another solution based on esphome by @Petapton. It allows to use my units with HA. There is a thread: https://community.home-assistant.io/t/daikin-madoka-brc1h-bluetooth-custom-component/ You can pull the custom component from the repository (see instructions in thread): https://github.com/Petapton/esphome/tree/madoka And there is a PR to include it in the official project: https://github.com/esphome/esphome/pull/5951