Daikin Heat Pump

Highlights

  • Powered by Daikin
  • Direct injection to Daikin IR Receiver (no IR blaster)
  • Direct feedback
  • OpenHAB controlled to activate for heat when below 11 degrees and room has been marked as in use. Opposite will occur when I code for the opposite in summer time here.
  • Heat pump remote can still be used and OpenHAB syncs to its state

 

WARNING: This build works around high voltage and directly injects into your heat pump.

My Company and I accept no liability whatsoever for your own well being or that of your heat pump.

 

Controlling the heat pump

In this modification, the Daikin heat pump is controlled directly from the Arduino. No IR Transmitter or blaster is used. It’s more technical, less portable, but more truly integrates and establishes the device as internet ready.

The basis of the code comes from the Arduino\Examples\HeatpumpIR\MySensorsNode example which in turn is based heavily on Ken Shirriff’s IRRemote library.

However, because we’re injecting directly into the IR Receiver and not using a transmitter, there are two small minor adjustments required.

  1. As the Arduino output connects directly to the Daikin’s IR receiver output pin, it only needs to transmit the coded signal, not the PWM carrier signal.Within the IRSender.cpp code, identify the setFrequency method. Set the output pin to High, then exit the method so the carrier is not established e.g.
    void IRSender::setFrequency(int frequency)
    {
      uint8_t pwmval8 = F_CPU / 2000 / (frequency);
      uint16_t pwmval16 = F_CPU / 2000 / (frequency);
      pinMode(_pin, OUTPUT);
    //  digitalWrite(_pin, LOW); // When not sending PWM, we want it low
    digitalWrite(_pin, HIGH); // Comment out the LOW above and set this to high
    return; //Then return out of here so PWM is not activated<br>
      switch (_pin)
      {…
  2. To allow the standard IR remote, we must set the Arduino pin back to Input, so it doesn’t interfere with normal operations. In the main MySenors code after the heatpump instruction is send to this
    heatpumpIR[model]->send(irSender, power, mode, fan, temp, VDIR_UP, HDIR_AUTO);
    pinMode(3, INPUT); //When not sending IR signals, PIN 3 must be in INPUT mode so that the true Daikin remote control can send its IR signal.

     

Powering the MySensors Node

The node is running on 5V sourced from the Daikin unit’s IR Receiver. Ground is also from this. There’s a couple of pictures on this page describing and showing this connection and describing the pin out. As per further info below, don’t short this else you’ll be pulling the header units board out to replace fuse.

Regarding load on this voltage source and the mentioned fuse, I never had any issues with it, but to reduce potential & ensure no red light shines through the unit, I removed the Pro mini’s power LED (simply carefully crushed and pulled it off with my wire cutters). As I write this now though, I can’t recall if I did the same on the 3.3v regulator for the radio. That has a bright LED too. On one of the earlier builds, I simply covered that with a bit of paint 🙂

 

Obtaining the heat pump status

The heat pump status is obtained by connecting the heat pump status LED to the Arduino and a simple MySensors binary switch. However, the Daikin status LED has ~16v across it which is too high for the Arduino for a direct wiring. I used a EL4N35 Optocoupler in parallel with the LED to isolate the circuits.

In addition, to stop the Daikin status LED from dimming, a 330ohm resister was places in series with the optocopler.

 

Again, please be extremely careful with this build & I accept no liability whatsoever for any issues you may have with either your heat pump or your own life. You are dealing with high voltage components on one end and high cost components at the other.

I was extremely careful right through the prototyping stage to not cross the 5v wires from the heat pump. Unfortunately on the final wiring, they crossed and killed the Daikin board. After researching worst case alternatives & second hand ~$100 USD units from China, I set out to try and fix my board.

 

Two more nodes

Regarding this video: This is absolutely not a normal thing to to. The board is open and on the kitchen bench because I had to replace the fuse.

It’s connected to 240v and as I turn it on, you see the on-board LED begin to flash. As the camera then shows the laptop screen, after several seconds, the MySensors node which is connected to the board, the establishes communication with the MySensors Gateway and MQTT.

The re-occuring 1s and 0s represents the flashing status LED back within the black plastic. It will be doing this because it’s not happy that it’s not installed properly. In normal operation, the status LED is represented properly as either 1 or 0, On or Off back in OpenHAB.

I really don’t recommend you do this sort of thing yourself. This video is only for interested people and is not a how to guide. You run the risk of either killing yourself or your electronics. I don’t want to hear about either!

 

OpenHAB & Climate Control

We have a heat pump outlet in each bedroom. Each heat pump has 3 OpenHAB settings. Off, On & Auto. The first two are self explanatory and when using the standard Daikin remote, OpenHAB is synced automatically to the Off/On setting.

When OpenHAB has the heat pump set to Auto, this is when the fun begins. No longer do we control the heat pump, but instead we say that we are “Staying in the room”. This way, the house controls weather to turn on the heat pump or not. When the temperature outside goes below 11 degrees, the heat pump is turned on (and to Heat). When it rises above 12, it turns off again. There’s a 1 degree difference to stop is oscillating around 11 degrees while the night is still cooling.

I’ll configure the opposite controls when it gets to summer time here in New Zealand.

OpenHAB reports the current state of the heat pump.

The OpenHAB rules seem like a lot and they possibly are. However, I spent quite a lot of time getting them stable and to this point. I’m not to worried if there’s an extra line or two of logic in there. Certainly the tracing came in handy!

One day I’ll replace the manual “Staying in the room” selection with some smart presence detection. I’ll also be adding a rule that says around 9am in the morning, that regardless of the temperature outside, this switch will be set to false – basically, you should be out of bed!

Group   gClimate                "Climate"               (All)<br>
Group   gClimateControls        "Climate Controls"      (All)


Number  Temperatures_Chart_Period                               "Chart Period"


Number Shed_Temperature2        "temporary temperature [%.1f C]"        <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/45/0/1/0/0:state:default]"}
Number Garage_Temperature       "Garage Temperature [%.1f C]"   <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/46/2/1/0/0:state:default]"}
Number Garage_Attic_Temperature "Attic Temperature [%.1f C]"    <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/46/0/1/0/0:state:default]"}
Number Outdoor_Temperature      "Outdoor Temperature [%.1f C]"  <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/46/1/1/0/0:state:default]"}


Number Climate_Control_Master_Bedroom   "Climate control required in Master bedroom"                    {}
Number Heatpump_Master_Bedroom_Status   "Master Bedroom Heatpump [MAP(on_off.map):%s]"  <light> (gClimateControls)      {mqtt="<[mosquitto:mygateway1-out/55/2/1/0/16:state:default]"}
String Heatpump_Master_Bedroom_Control  "[%s]"                                                                          {mqtt=">[mosquitto:mygateway1-in/55/1/0/0/32:command:*:default]"}
Switch Climate_Staying_Master_Bedroom   "Staying in Master bedroom"                                     {}

Number Climate_Control_xxxxx_Bedroom   "Climate control required in xxxxx bedroom"                    {}
Number Heatpump_xxxxx_Bedroom_Status   "xxxxx Bedroom Heatpump [MAP(on_off.map):%s]"  <light> (gClimateControls)      {mqtt="<[mosquitto:mygateway1-out/56/2/1/0/16:state:default]"}
String Heatpump_xxxxx_Bedroom_Control  "[%s]"                                                                          {mqtt=">[mosquitto:mygateway1-in/56/1/0/0/32:command:*:default]"}
Switch Climate_Staying_xxxxx_Bedroom   "Staying in xxxxx bedroom"                                     {}
Number Heatpump_xxxxx_Temperature      "xxxxxh's Room [%.1f C]"                <temperature>   (gClimate)              {mqtt="<[mosquitto:mygateway1-out/56/0/1/0/0:state:default]"}
  Group label="Climate Control"{
                        Frame{
                                Text item=Outdoor_Temperature
                        }

                        Frame label="Master Bedroom"{
                                Switch item=Climate_Control_Master_Bedroom mappings=[0="Off", 1="On", 2="Auto"]
                                Switch item=Climate_Staying_Master_Bedroom
                                Text item=Heatpump_Master_Bedroom_Status
                        }

                        Frame label="xxxxx Bedroom"{
                                Text item=Heatpump_xxxxx_Temperature
                                Switch item=Climate_Control_xxxxx_Bedroom mappings=[0="Off", 1="On", 2="Auto"]
                                Switch item=Climate_Staying_xxxxx_Bedroom
                                Text item=Heatpump_xxxxx_Bedroom_Status
                        }                     

                        Frame {
                                Switch item=Temperatures_Chart_Period label="" mappings=[0="Hour", 1="Day", 2="Week"]
                                Chart item=gClimate period=h refresh=30000 visibility=[Temperatures_Chart_Period==0]
                                Chart item=gClimate period=D refresh=90000 visibility=[Temperatures_Chart_Period==1]
                                Chart item=gClimate period=W refresh=300000 visibility=[Temperatures_Chart_Period==2, Temperatures_Chart_Period=="Uninitialized"]
                        }
                }
<span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1">​</span>
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.java.math.*
import org.joda.time.*



var String heatpump_heat        = "00012112"
var String heatpump_off         = "00002112"

var String heatpump_setting     = ""
var int turn_off                = 0

var int cold_temperature        = 11


var int openhab_controlled_master_bedroom = 0
var DateTime last_set_by_openhab


rule "Climate Control"
when
        Item Outdoor_Temperature changed or
        Item Climate_Control_Master_Bedroom changed or
        Item Climate_Staying_Master_Bedroom changed or
        Item Climate_Control_xxxxx_Bedroom changed or
        Item Climate_Staying_xxxxx_Bedroom changed or
then
        logInfo("Climate Control", "Running Climate Control. Outdoor temperature is [{}]", Outdoor_Temperature.state)

        turn_off = 0

        if((Outdoor_Temperature.state < cold_temperature)
                || (Heatpump_Master_Bedroom_Status.state==1 && Outdoor_Temperature.state < cold_temperature + 1)){
                //the OR bit above ensures if the heatpump is on and the temperature flucuates above the
                //trigger by less than a degree, the pump remains on

                logInfo("Climate Control", "Outdoor temperature is below cold temperature. Heatpumps will be set to Heat if necessary")
                heatpump_setting = heatpump_heat
        }//else todo, outdoor > hot_temperature //I'll do this in the summer time!
        
        
        else{
                logInfo("Climate Control", "Neither hot, nor cold. Heatpumps will be turned off"
                turn_off = 1
        }



//0 = Off, 1=On, 2=Auto

        /* MASTER BEDROOM */
        if(Climate_Control_Master_Bedroom.state==0){
                logInfo("Climate Control", "Master Bedroom state has been selected to be off")
                if(Heatpump_Master_Bedroom_Status.state!=0){
                        logInfo("Climate Control", "Master bedroom is on, so turning it off")
                        last_set_by_openhab = now
                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
               }

        }else if(Climate_Control_Master_Bedroom.state==1){
                logInfo("Climate Control", "Master Bedroom state has been selected to be On")
                if(Heatpump_Master_Bedroom_Status.state!=1){
                        logInfo("Climate Control", "Master bedroom is off, so turning it on")
                        last_set_by_openhab = now
                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                //      Thread::sleep(1000)
                //      Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                }

        }else if(Climate_Control_Master_Bedroom.state==2){
                logInfo("Climate Control", "Master Bedroom requries Auto climate control")

                if(Climate_Staying_Master_Bedroom.state==ON){

                        if(turn_off==1){
                                if(Heatpump_Master_Bedroom_Status.state==0){
                                        logInfo("Climate Control", "Master Bedroom presence, but heatpump should be off and it already is")
                                }else{
                                        logInfo("Climate Control", "Master Bedroom presence, but heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
                                }
                        }else{

                                if(Heatpump_Master_Bedroom_Status.state!=1){
                                        logInfo("Climate Control", "Master Bedroom presence, heatpump needs to be turned on. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_Master_Bedroom_Control.sendCommand(heatpump_setting)
                                }else{
                                        logInfo("Climate Control", "Master Bedroom presence, heatpump is alreay in an on state")
                                }
                        }
                }else{
                        //No presence, turn off if necessary
                        if(Heatpump_Master_Bedroom_Status.state!=1){
                                logInfo("Climate Control", "Master Bedroom no presence, heatpump should be off and it already is")
                        }else{
                                logInfo("Climate Control", "Master Bedroom no presence, heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                last_set_by_openhab = now
                                Heatpump_Master_Bedroom_Control.sendCommand(heatpump_off)
                        }
                }
        }





/* xxxxx BEDROOM */
        if(Climate_Control_xxxxx_Bedroom.state==0){
                logInfo("Climate Control", "xxxxx Bedroom state has been selected to be off")
                if(Heatpump_xxxxx_Bedroom_Status.state!=0){
                        logInfo("Climate Control", "xxxxx bedroom is on, so turning it off")
                        last_set_by_openhab = now
                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
               }

        }else if(Climate_Control_xxxxx_Bedroom.state==1){
                logInfo("Climate Control", "xxxxx Bedroom state has been selected to be On")
                if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                        logInfo("Climate Control", "xxxxx bedroom is off, so turning it on")
                        last_set_by_openhab = now
                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                //      Thread::sleep(1000)
                //      Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                }

        }else if(Climate_Control_xxxxx_Bedroom.state==2){
                logInfo("Climate Control", "xxxxx Bedroom requries Auto climate control")

                if(Climate_Staying_xxxxx_Bedroom.state==ON){

                        if(turn_off==1){
                                if(Heatpump_xxxxx_Bedroom_Status.state==0){
                                        logInfo("Climate Control", "xxxxx Bedroom presence, but heatpump should be off and it already is")
                                }else{
                                        logInfo("Climate Control", "xxxxx Bedroom presence, but heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
                                }
                        }else{

                                if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                                        logInfo("Climate Control", "xxxxx Bedroom presence, heatpump needs to be turned on. Sending [{}]", heatpump_setting)
                                        last_set_by_openhab = now
                                        Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_setting)
                                }else{
                                        logInfo("Climate Control", "xxxxx Bedroom presence, heatpump is alreay in an on state")
                                }
                        }
                }else{
                        //No presence, turn off if necessary
                        if(Heatpump_xxxxx_Bedroom_Status.state!=1){
                                logInfo("Climate Control", "xxxxx Bedroom no presence, heatpump should be off and it already is")
                        }else{
                                logInfo("Climate Control", "xxxxx Bedroom no presence, heatpump needs to be turned off. Sending [{}]", heatpump_setting)
                                last_set_by_openhab = now
                                Heatpump_xxxxx_Bedroom_Control.sendCommand(heatpump_off)
                        }
                }
        }







end




rule "Heatpump_Master_Bedroom_Status changed" when
        Item Heatpump_Master_Bedroom_Status changed
then

        //if someone has set the heatpump and it wasn't openhab recently, then wait a little bit for any lights to stop flashing
        //and sync the state

        if(last_set_by_openhab == null || !last_set_by_openhab.plusSeconds(5).isAfter(now)){

                logInfo("Climate Control", "Heatpump_Master_Bedroom_Status changed and it wasn't by openhab")

                Thread::sleep(1500)

                //if new state is not on (off), set openhab to off
                if(Heatpump_Master_Bedroom_Status.state != 1
                        && Climate_Control_Master_Bedroom.state != 0){
                        logInfo("Climate Control", "Climate_Control_Master_Bedroom.postUpdate(0);"
                        Climate_Control_Master_Bedroom.postUpdate(0);
                }


                //if new state it not off (on), set openhab to on
                if(Heatpump_Master_Bedroom_Status.state != 0
                        && Climate_Control_Master_Bedroom.state != 1 ){

                        logInfo("Climate Control", "Climate_Control_Master_Bedroom.postUpdate(1);"

                        Climate_Control_Master_Bedroom.postUpdate(1);
                 }
        }else{
                logInfo("Climate Control", "Heatpump_Master_Bedroom_Status changed, but OpenHAB had changed it, so not syncing ")
        }

end


rule "Heatpump_xxxxx_Bedroom_Status changed" when
        Item Heatpump_xxxxx_Bedroom_Status changed
then

        //if someone has set the heatpump and it wasn't openhab recently, then wait a little bit for any lights to stop flashing
        //and sync the state

        if(last_set_by_openhab == null || !last_set_by_openhab.plusSeconds(5).isAfter(now)){

                logInfo("Climate Control", "Heatpump_xxxxx_Bedroom_Status changed and it wasn't by openhab")

                Thread::sleep(1500)

                //if new state is not on (off), set openhab to off
                if(Heatpump_xxxxx_Bedroom_Status.state != 1
                        && Climate_Control_xxxxx_Bedroom.state != 0){
                        logInfo("Climate Control", "Climate_Control_xxxxx_Bedroom.postUpdate(0);"
                        Climate_Control_xxxxx_Bedroom.postUpdate(0);
                }


                //if new state it not off (on), set openhab to on
                if(Heatpump_xxxxx_Bedroom_Status.state != 0
                        && Climate_Control_xxxxx_Bedroom.state != 1 ){

                        logInfo("Climate Control", "Climate_Control_xxxxx_Bedroom.postUpdate(1);"

                        Climate_Control_xxxxx_Bedroom.postUpdate(1);
                 }
        }else{
                logInfo("Climate Control", "Heatpump_xxxxx_Bedroom_Status changed, but OpenHAB had changed it, so not syncing ")
        }

end

 

Software on the MySensors node

/**
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 *******************************
 *
 * REVISION HISTORY
 * Version 1.0 - Henrik Ekblad
 *
 * DESCRIPTION
 * 
 * 
 */

// Enable debug prints to serial monitor
//#define MY_DEBUG

#define MY_NODE_ID 57


// Enable and select radio type attached
#define MY_RADIO_NRF24

// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE


#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>


#include <DallasTemperature.h>
#include <OneWire.h>

#include <DaikinHeatpumpIR.h>

HeatpumpIR *heatpumpIR[] = {new DaikinHeatpumpIR(), NULL};

// IR led on PWM output-capable digital pin 3
IRSender irSender(3);

#define CONTROL_CHILD_ID 1
#define STATUS_LED_CHILD_ID 2
#define STATUS_LED_PIN  4 
Bounce statusLedDebouncer = Bounce(); 
int oldStatusLedValue=-1;

MyMessage binStatusLedmsg(STATUS_LED_CHILD_ID,V_TRIPPED);





//Temperature stuff
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No

#define ONE_WIRE_BUS 7   // Pin where dallase sensor is connected 
#define MAX_ATTACHED_DS18B20 16
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0;
bool receivedConfig = false;
bool metric = true;
// Initialize temperature message
MyMessage msg(0,V_TEMP);


unsigned long timeOfLastTempCheck = SLEEP_TIME * -1;


void before()
{
  // Startup up the OneWire library
  sensors.begin();
}

void setup()
{
  pinMode(3, INPUT);    //Set Control on Daikin to input as the very first thing so it doesn't influece the heatpump

  pinMode(STATUS_LED_PIN,INPUT);
  // Activate internal pull-up
  digitalWrite(STATUS_LED_PIN,HIGH);
  statusLedDebouncer.attach(STATUS_LED_PIN);
  statusLedDebouncer.interval(20);


  // requestTemperatures() will not block current thread
  sensors.setWaitForConversion(false);

 
}

void presentation()
{
	// Send the sketch version information to the gateway and Controller
	sendSketchInfo("Daiken Heatpump", "1.0");
	present(CONTROL_CHILD_ID, S_IR, "Heatpump Control");	
  present(STATUS_LED_CHILD_ID, S_BINARY, "Heatpump Status");  

  // Fetch the number of attached temperature sensors  
  numSensors = sensors.getDeviceCount();

  // Present all sensors to controller
  for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
     present(i, S_TEMP);
  }

  
}


void loop()
{

   statusLedDebouncer.update();
  
   int value = statusLedDebouncer.read();  
   if (value != oldStatusLedValue) {
       // Send in the new value
       send(binStatusLedmsg.set(value==LOW ? 1 : 0));   //The optocoupler representing the Daiken Status LED will connect us to Ground. Therefore Low is Heatpump ON (1)
       oldStatusLedValue = value;
    }


 if(millis() -  timeOfLastTempCheck > SLEEP_TIME){
    timeOfLastTempCheck = millis();
    checkTemperature();
 //   checkpressure();
  }

}

void receive(const MyMessage &message)
{
  const char *irData;


	// We only expect one type of message from controller. But we better check anyway.
  // V_IR type message

Serial.println(message.type);
  
  if (message.type==V_IR_SEND) {
    Serial.println(F("Received IR send command..."));
    irData = message.getString();
    Serial.print(F("Code: 0x"));
    Serial.println(irData);
    sendHeatpumpIRCommand(irData);
  }

}



// Decode the IR command and send the IR command to the heatpump
void sendHeatpumpIRCommand(const char *irCommandString) {

  // irCommandString is an 8-digit hex digit
  long irCommand = 0;
  int sscanfStatus = sscanf(irCommandString, "%lx", &irCommand);

  if (sscanfStatus == 1) {
    Serial.print(F("IR code conversion OK: 0x"));
    Serial.println(irCommand, HEX);
  } else {
    Serial.println(F("Failed to convert IR hex code to number"));
  }

/*
The heatpump command is packed into a 32-bit hex number, see
libraries\HeatpumpIR\HeatpumpIR.h for the constants

12345678
  3 MODEL
   4 POWER
    5 OPERATING MODE
     6 FAN SPEED
      78 TEMPERATURE IN HEX

00213416 (as an example of a valid code)
  2 = PanasonicJKE
   1 = Power ON
    3 = COOL
     4 = FAN 4
      16 = Temperature 22 degrees (0x16 = 22)
 */

  byte model = (irCommand & 0x00F00000) >> 20;
  byte power = (irCommand & 0x00010000) >> 16;
  byte mode  = (irCommand & 0x0000F000) >> 12;
  byte fan   = (irCommand & 0x00000F00) >> 8;
  byte temp  = (irCommand & 0x000000FF);

  const char* buf;
  Serial.print(F("Model: "));

  buf = heatpumpIR[model]->model();
  // 'model' is a PROGMEM pointer, so need to write a byte at a time
  while (char modelChar = pgm_read_byte(buf++))
  {
    Serial.print(modelChar);
  }
  Serial.println();

  Serial.print(F("Model #: ")); Serial.println(model);
  Serial.print(F("Power: ")); Serial.println(power);
  Serial.print(F("Mode: ")); Serial.println(mode);
  Serial.print(F("Fan: ")); Serial.println(fan);
  Serial.print(F("Temp: ")); Serial.println(temp);

  // Heatpump models start from 0, i.e. model number is always less than the number of different models
  
  heatpumpIR[model]->send(irSender, power, mode, fan, temp, VDIR_UP, HDIR_AUTO);
  pinMode(3, INPUT);
}





void checkTemperature(){


 // Fetch temperatures from Dallas sensors
  sensors.requestTemperatures();

  // query conversion time and sleep until conversion completed
  int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
  // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
  sleep(conversionTime);

  // Read temperatures and send them to controller 
  for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {

    // Fetch and round temperature to one decimal
    float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;

    // Only send data if temperature has changed and no error
    #if COMPARE_TEMP == 1
    if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
    #else
    if (temperature != -127.00 && temperature != 85.00) {
    #endif

      // Send in the new temperature
      send(msg.setSensor(i).set(temperature,1));
      // Save new temperatures for next compare
      lastTemperature[i]=temperature;
    }
  }
  
}

 

Related posts

Leave a Comment