1technophile / OpenMQTTGateway

MQTT gateway for ESP8266 or ESP32 with bidirectional 433mhz/315mhz/868mhz, Infrared communications, BLE, Bluetooth, beacons detection, mi flora, mi jia, LYWSD02, LYWSD03MMC, Mi Scale, TPMS, BBQ thermometer compatibility & LoRa.
https://docs.openmqttgateway.com
GNU General Public License v3.0
3.6k stars 791 forks source link

Could you add support for AC's maybe, like Mitsubishi #33

Closed 1technophile closed 6 years ago

1technophile commented 7 years ago

geoisis: Awesome project !!! Although i can't get 433ghz receiver to snif anything, IR works fine. Could you add support for AC's maybe, like Mitsubishi. ex: https://github.com/markszabo/IRremoteESP8266

thank you for work, keep it up :D !

PetricaM commented 6 years ago

Hi Florian,

I don't think it is feasible to implement support for AC protocols as they are simply too many and require quite advanced knowledge for average user. Moreover, the support should be implemented in IRRemote in order for OpenMQTT to recognize the signal.

However, there's an workaround. I think that it should work for most of the AC.

  1. Simply record all the button codes send by the remote as raw signals; here IRRemote has an issue as for AC signals are much longer than for regular IR sent by TV/VCR as it includes the full state of the device (target temperature, mode, fan, swing, etc); you actually told me what line to modify in IRRemote as it was recording only about 400 char (I think that it was IRRecv.h line #define RAWBUF 100U // Length of raw duration buffer but I don't I recall exactly :) ); when you release the pre-compiled versions of OpenMQTT you can modify the respective IRRecv.h line to have the full signal recorded.

The buttons on my remote are On/Off; Sleep; Fan; Swing; Mode; Temp. As a result, there are 153 different signals sent by the remote.

  1. Create a script with the payload for each button press (153 scripts :) ). The name of the script is important as it includes the button pressed.

    livinghvacoff:
    alias: off
    sequence:
    - service: mqtt.publish
      data:
        topic: "home/GatewayOpenMQTT7/commands/IR_Raw"
        payload: "3106,1704,526,..."
    livinghvaconnoautofalsecool16:
    alias: onnoautoFALSEcool16
    sequence:
    - service: mqtt.publish
      data:
        topic: "home/GatewayOpenMQTT7/commands/IR_Raw"
        payload: "3052,1702,528,..."
  2. Set component MQTT HVAC; the topics where the component posts the commands are being used in step 4 to be concatenated and matched against scripts names:

    - platform: mqtt
    name: HVAC Living
    modes:
    - dry
    - cool
    - fan
    swing_modes:
    - yes
    - no
    fan_modes:
    - auto
    - high
    - medium
    - low
    hold:
    - yes
    - no
    power_command_topic: "hvac/living/power/set"
    mode_command_topic: "hvac/living/mode/set"
    temperature_command_topic: "hvac/living/temperature/set"
    fan_mode_command_topic: "hvac/living/fan/set"
    swing_mode_command_topic: "hvac/living/swing/set"
    hold_command_topic: "hvac/living/swing/set"
    current_temperature_topic: "hvac/living/state/temperature"
    payload_on: "on"
    payload_off: "off"
    retain: true
    initial: 22
  3. Sensors; the first 6 sensors are intermediary and are based on the topics sent by the HVAC component for each of the remote buttons; the next 6 are used for dealing with the error messages after a reboot (5% core code, 95% error handling :) ).

- platform: mqtt  
  state_topic: "hvac/living/power/set"
  name: 'HVACi living power'  
- platform: mqtt  
  state_topic: "hvac/living/mode/set"
  name: 'HVACi living mode'  
- platform: mqtt  
  state_topic: "hvac/living/temperature/set"
  name: 'HVACi living temperature'  
- platform: mqtt  
  state_topic: "hvac/living/fan/set"
  name: 'HVACi living fan'
- platform: mqtt  
  state_topic: "hvac/living/swing/set"
  name: 'HVACi living swing'
- platform: mqtt  
  state_topic: "hvac/living/sleep/set"
  name: 'HVACi living sleep'
- platform: template
  sensors:
    hvac_living_power:
      friendly_name: HVAC living power
      value_template: >
        {% if is_state('sensor.hvaci_living_power', 'unknown') %}
          off
        {% else %}
          {{ states.sensor.hvaci_living_power.state }}
        {% endif %}
- platform: template
  sensors:
    hvac_living_mode:
      friendly_name: HVAC living mode
      value_template: >
        {% if is_state('sensor.hvaci_living_mode', 'unknown') %}
          cool
        {% else %}
          {{ states.sensor.hvaci_living_mode.state }}
        {% endif %}
- platform: template
  sensors:
    hvac_living_temperature:
      friendly_name: HVAC living temperature
      value_template: >
        {% if is_state('sensor.hvaci_living_temperature', 'unknown') %}
          22
        {% else %}
          {{ states.sensor.hvaci_living_temperature.state }}
        {% endif %}
- platform: template
  sensors:
    hvac_living_fan:
      friendly_name: HVAC living fan
      value_template: >
        {% if is_state('sensor.hvaci_living_fan', 'unknown') %}
          auto
        {% else %}
          {{ states.sensor.hvaci_living_fan.state }}
        {% endif %}
- platform: template
  sensors:
    hvac_living_swing:
      friendly_name: HVAC living swing
      value_template: >
        {% if is_state('sensor.hvaci_living_swing', 'unknown') %}
          false
        {% else %}
          {{ states.sensor.hvaci_living_swing.state }}
        {% endif %}
- platform: template
  sensors:
    hvac_living_sleep:
      friendly_name: HVAC living sleep
      value_template: >
        {% if is_state('sensor.hvaci_living_sleep', 'unknown') %}
          no
        {% else %}
          {{ states.sensor.hvaci_living_sleep.state }}
        {% endif %}
  1. Automations; each command sent by the HVAC component modifies the sensors values and executes the script with the name resulted from the concatenation of the sensors names.
- alias: 'HVAC living operation'
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id:
        - sensor.hvac_living_mode
        - sensor.hvac_living_temperature
        - sensor.hvac_living_fan
        - sensor.hvac_living_swing
  action:
    - service: homeassistant.turn_on
      data_template:
        entity_id: script.livinghvac{{states.sensor.hvac_living_power.state|replace("ON","on")|replace("OFF","off")}}{{states.sensor.hvac_living_sleep.state}}{{states.sensor.hvac_living_fan.state}}{{states.sensor.hvac_living_swing.state|replace("False","false")|replace("True","true")}}{{states.sensor.hvac_living_mode.state}}{{states.sensor.hvac_living_temperature.state|replace(".0","")}}
- alias: 'HVAC living off'
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: sensor.hvac_living_power
      to: "off"
  action:
    - service: homeassistant.turn_on
      entity_id: script.livinghvacoff
- alias: 'HVAC living sleep mode off'
  initial_state: 'on'
  trigger:
    - platform: sun
      event: sunrise
      offset: "+02:00:00"
  action:
    - service: mqtt.publish
      data:
        topic: 'hvac/living/sleep/set'
        payload: "no"
- alias: 'HVAC living sleep mode on'
  initial_state: 'on'
  trigger:
    - platform: sun
      event: sunset
      offset: "+02:00:00"
  action:
    - service: mqtt.publish
      data:
        topic: 'hvac/living/sleep/set'
        payload: "yes"
waraileron commented 6 years ago

Hi there, this is my temporary workaround for my mitsubishi ac(raw code didnt seem to work for me), activates on mqtt topic IR_AIRCON with 0 being off and anything above 10 being on. (I do not see the need to change other parameters but could be a point to start looking into it if you do need them.)

  1. add in config_IR.h #define IR_AIRCON
  2. add in ZgatewayIR.ino #include <ir_Mitsubishi.h>
  3. then add this bit of code in ZgatewayIR.ino above #ifdef ESP8266 // IR_RCMM not available on arduino
    //test aircon code here  
    #ifdef IR_AIRCON
    if (strstr(topicOri, "IR_AIRCON") != NULL){
    IRMitsubishiAC mitsubir(IR_EMITTER_PIN);
    mitsubir.begin();
    if (data == 0){
    mitsubir.off();
    mitsubir.setFan(0);
    mitsubir.setMode(MITSUBISHI_AC_COOL);
    mitsubir.setTemp(data);
    mitsubir.setVane(MITSUBISHI_AC_VANE_AUTO);}
    else if (data > 10){
    mitsubir.on();
    mitsubir.setFan(0);
    mitsubir.setMode(MITSUBISHI_AC_COOL);
    mitsubir.setTemp(data);
    mitsubir.setVane(MITSUBISHI_AC_VANE_AUTO);}
    #ifdef ESP8266
    mitsubir.send();
    #endif
    signalSent = true;
    }
    #endif
    //end test code
1technophile commented 6 years ago

Added

1technophile commented 6 years ago

@PetricaM I took the opportunity to add your idea to the wiki thanks