Mysensors HVAC not showing up

Hi guys,

I’ve been having the same issues and the sketch below solves it (it’s messy, but it’s a proof of concept):

/*
#define MODE_AUTO   1
#define MODE_HEAT   2
#define MODE_COOL   3
#define MODE_DRY    4
#define MODE_FAN    5
#define MODE_MAINT  6

#define FAN_AUTO    0
#define FAN_1       1
#define FAN_2       2
#define FAN_3       3
#define FAN_4       4
#define FAN_5       5

#define VDIR_AUTO   0
#define VDIR_MANUAL 0
#define VDIR_SWING  1
#define VDIR_UP     2
#define VDIR_MUP    3
#define VDIR_MIDDLE 4
#define VDIR_MDOWN  5
#define VDIR_DOWN   6

#define HDIR_AUTO   0
#define HDIR_MANUAL 0
#define HDIR_SWING  1
#define HDIR_MIDDLE 2
#define HDIR_LEFT   3
#define HDIR_MLEFT  4
#define HDIR_MRIGHT 5
#define HDIR_RIGHT  6
 
 */

// Enable debug prints to serial monitor
#define MY_DEBUG 

// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

#define CHILD_ID_HVAC 3

#define MY_RF24_PA_LEVEL RF24_PA_MAX

// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE

#include <MySensors.h>
#include <MideaHeatpumpIR.h>

//Some global variables to hold the states
int POWER_STATE;
int TEMP_STATE;
int FAN_STATE;
int MODE_STATE;
int VDIR_STATE;
int HDIR_STATE;
String HA_MODE_STATE = "Off";
String HA_FAN_STATE = "Min";

IRSenderPWM irSender(3);       // IR led on Arduino digital pin 3, using Arduino PWM

HeatpumpIR *heatpumpIR = new MideaHeatpumpIR();

MyMessage msgHVACSetPointC(CHILD_ID_HVAC, V_HVAC_SETPOINT_COOL);
MyMessage msgHVACSpeed(CHILD_ID_HVAC, V_HVAC_SPEED);
MyMessage msgHVACFlowState(CHILD_ID_HVAC, V_HVAC_FLOW_STATE);

bool initialValueSent = false;

void before() {
  loadState(CHILD_ID_HVAC);
}

void setup()  
{
  Serial.begin(115200);
}

void presentation() {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("MasterBedroomUnit", "2.0.3");
  
  Serial.println("Presenting sensor...");
  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID_HVAC, S_HVAC, "");
}


void loop()
{
  if (!initialValueSent) {
    Serial.println("Sending initial values");
    POWER_STATE = 0;
    MODE_STATE = MODE_AUTO;
    FAN_STATE = 1;
    TEMP_STATE = 24;
    sendHeatpumpCommand();
    sendNewStateToGateway();
    
    request(CHILD_ID_HVAC, V_HVAC_SETPOINT_COOL);
    wait(3000, C_SET, V_HVAC_SETPOINT_COOL);
    request(CHILD_ID_HVAC, V_HVAC_SPEED);
    wait(3000, C_SET, V_HVAC_SPEED);
    request(CHILD_ID_HVAC, V_HVAC_FLOW_STATE);
    wait(3000, C_SET, V_HVAC_FLOW_STATE);
    //initialValueSent = true;
  }
}

void receive(const MyMessage &message) {
  if (message.isAck()) {
     Serial.println("This is an ack from gateway");
     //return;
  }

  Serial.print("Incoming message for: ");
  Serial.print(message.sensor);

  String recvData = message.data;
  recvData.trim();

  Serial.print(", New status: ");
  Serial.println(recvData);
  switch (message.type) {
    case V_HVAC_SPEED:
      Serial.println("V_HVAC_SPEED");

      if(recvData.equalsIgnoreCase("auto")) {
        FAN_STATE = 0;
        HA_FAN_STATE = "Auto";
      }
      else if(recvData.equalsIgnoreCase("min")) {
        FAN_STATE = 1;
        HA_FAN_STATE = "Min";
      }
      else if(recvData.equalsIgnoreCase("normal")) {
        FAN_STATE = 2;
        HA_FAN_STATE = "Normal";
      }
      else if(recvData.equalsIgnoreCase("max")) {
        FAN_STATE = 3;
        HA_FAN_STATE = "Max";
      }
    break;

    case V_HVAC_SETPOINT_COOL:
      Serial.println("V_HVAC_SETPOINT_COOL");
      TEMP_STATE = message.getFloat();
      Serial.println(TEMP_STATE);
    break;

    case V_HVAC_FLOW_STATE:
      Serial.println("V_HVAC_FLOW_STATE");
      if (recvData.equalsIgnoreCase("coolon")) {
        POWER_STATE = 1;
        MODE_STATE = MODE_COOL;
        HA_MODE_STATE = "CoolOn";
      }
      else if (recvData.equalsIgnoreCase("heaton")) {
        POWER_STATE = 1;
        MODE_STATE = MODE_HEAT;
        HA_MODE_STATE = "HeatOn";
      }
      else if (recvData.equalsIgnoreCase("autochangeover")) {
        POWER_STATE = 1;
        MODE_STATE = MODE_AUTO;
        HA_MODE_STATE = "AutoChangeOver";
      }
      else if (recvData.equalsIgnoreCase("off")){
        POWER_STATE = 0;
        HA_MODE_STATE = "Off";
      }
      initialValueSent = true;
      break;
  }
  sendHeatpumpCommand();
  sendNewStateToGateway();
}

void sendNewStateToGateway() {
  send(msgHVACSetPointC.set(TEMP_STATE));
  wait(1000, C_SET, V_HVAC_SETPOINT_COOL);
  char fan_state[HA_FAN_STATE.length() + 1];
  HA_FAN_STATE.toCharArray(fan_state, HA_FAN_STATE.length() + 1);
  send(msgHVACSpeed.set(fan_state));
  wait(1000, C_SET, V_HVAC_SPEED);
  char mode_state[HA_MODE_STATE.length() + 1];
  HA_MODE_STATE.toCharArray(mode_state, HA_MODE_STATE.length() + 1);
  send(msgHVACFlowState.set(mode_state));
  wait(1000, C_SET, V_HVAC_FLOW_STATE);
}

void sendHeatpumpCommand() {
  Serial.println("Power = " + (String)POWER_STATE);
  Serial.println("Mode = " + (String)MODE_STATE);
  Serial.println("Fan = " + (String)FAN_STATE);
  Serial.println("Temp = " + (String)TEMP_STATE);

  heatpumpIR->send(irSender, POWER_STATE, MODE_STATE, FAN_STATE, TEMP_STATE, VDIR_AUTO, HDIR_AUTO);
}
2 Likes

Wow! Where have you been before? It works. The only question is that in the climate component there is a graph for the current temp? To integrate DHT connected to my sensors - which topic shall it send to? Is it a standard V_TEMP like

MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); ???

Almost, you should use the same child id as for the HVAC.

MyMessage msgTemp(CHILD_ID_HVAC, V_TEMP);

Thank you. Sounds great. So i can supply the reading as a separate sensor and as a part of climate component.

1 Like

Yes, if you present another child as S_TEMP and report the V_TEMP for that child it will show as a separate sensor.

1 Like

Well after much struggle did get it together. Still a question remains - in the climate component the temperature is set in a 0.5 increment. While most airconds use only a 1C incriment. Is there any setting for this?

1 Like

Yes, by setting target_temp_step for the entity_id in question under the customize key under homeassistant in your configuration.yaml.

homeassistant:
...
  customize:
    climate.test:
      target_temp_step: 1
1 Like

Can you please add it to the docs? i’ve rechecked the customization documentation, climate component, mysensors component and seems couldn’t find it

If I get some time, yes, but the docs are very easy to update for even a novice githubber. Every page has an edit on github button. Just follow this guide:

This change should go to the climate component page and possibly the customize page.

Ok will do that. It’s just that it is only one of the parameters. Any others can be customized?

I’m glad I found this thread! I set up an ESP8266 MQTT gateway on the weekend and couldn’t work out how to get the HVAC control working.

I’ll work through the solutions presented here and will report back.

All entity state attributes can be customized, but some don’t make sense to customize cause they are just info for the user or part of the sensor report, and some are hidden by default so can be hard to find out about.

Can I use just the temperature setpoint without fan speed etc? Just got this in mysensors.json:

    "131": {
        "sensor_id": 131,
        "children": {
            "1": {
                "id": 1,
                "type": 29,
                "description": "Thermostat Biuro",
                "values": {
                    "45": "14.0",
                    "2": "0"
                }
            }

But there is no entity that corresponds to it. I was thinking this will make a thermostat faceplate anyway, but this is not the case.

@martinhjelmare could you tak a look at the problem I have described above? Many thanks in advance!

Well summer time. And aircons don’t work anymore. I can switch on|off. But for example speed control is not working anymore. Same for temp change. Temp change is even more interesting. Set it from lets say 18 to 20 and than it just reverts back. Seems a lot of changes have been done from last summer

Mysensors.json of node in question

    "41": {
        "sensor_id": 41,
        "children": {
            "0": {
                "id": 0,
                "type": 29,
                "description": "",
                "values": {
                    "0": "24.8",
                    "44": "18",
                    "21": "CoolOn",
                    "22": "Max"
                }
            },
            "2": {
                "id": 2,
                "type": 7,
                "description": "",
                "values": {
                    "1": "43.1",
                    "0": "1102525219"
                }
            },
            "3": {
                "id": 3,
                "type": 6,
                "description": "",
                "values": {
                    "0": "24.8",
                    "32": "25.3",
                    "4": "16.100"
                }
            },
            "4": {
                "id": 4,
                "type": 22,
                "description": "",
                "values": {
                    "45": "87.0",
                    "37": "269.0"
                }
            },
            "5": {
                "id": 5,
                "type": 24,
                "description": "",
                "values": {
                    "45": "00A0604702",
                    "37": "160.62"
                }
            },
            "136": {
                "id": 136,
                "type": 8,
                "description": "",
                "values": {}
            },
            "110": {
                "id": 110,
                "type": 7,
                "description": "",
                "values": {}
            },
            "16": {
                "id": 16,
                "type": 0,
                "description": "",
                "values": {}
            },
            "218": {
                "id": 218,
                "type": 1,
                "description": "",
                "values": {}
            },
            "164": {
                "id": 164,
                "type": 32,
                "description": "",
                "values": {}
            },
            "148": {
                "id": 148,
                "type": 38,
                "description": "",
                "values": {}
            },
            "254": {
                "id": 254,
                "type": 19,
                "description": "",
                "values": {}
            },
            "85": {
                "id": 85,
                "type": 4,
                "description": "45470FE7F8",
                "values": {}
            }
        },
        "type": 7,
        "sketch_name": "MYS Zal",
        "sketch_version": "2.1",
        "battery_level": 0,
        "protocol_version": "1.4",
        "heartbeat": 0
    },

Any errors in your Home Assistant log?

@firstof9

Thanks for asking. Actually quite some. Didn’t notice. Seems several HA upgrades broke the MYS integration

Logger: mysensors.sensor
Source: /usr/local/lib/python3.8/site-packages/mysensors/sensor.py:141
First occurred: 8 июля 2021 г., 19:26:44 (5 occurrences)
Last logged: 8 июля 2021 г., 19:27:16

* Invalid <Message data="41;0;1;0;44;18">: Not valid message sub-type: 44 for object value @ data['sub_type']. Got 44 not a valid value for object value @ data['payload']. Got '18'
* Invalid <Message data="41;0;1;0;22;Max">: value must be either 0 or 1 for object value @ data['payload']. Got 'Max'
* Invalid <Message data="41;0;1;1;22;Auto">: value must be either 0 or 1 for object value @ data['payload']. Got 'Auto'
* Invalid <Message data="41;0;1;1;22;Min">: value must be either 0 or 1 for object value @ data['payload']. Got 'Min'
* Invalid <Message data="41;0;1;1;44;20.0">: Not valid message sub-type: 44 for object value @ data['sub_type']. Got 44 not a valid value for object value @ data['payload']. Got '20.0'

I’d open an issue on github about it.

https://github.com/home-assistant/core/issues/52781

Ok done

1 Like

Sorry for replying to this old topic, is this one resolved?? I get exactly the same issue as @moskovskiy82