Homematic heater and Homekit - need some help

I need some help to control my Homematic heaters with Homekit.

My setup: OpenHAB 2.5.6 running on a Pi 4 with Homegear.
This setup is running since months/years very stable and I control my heaters primarily with rules and a wall-mounted display with HABPanel.

But since I’m an Apple user, I want to use Homekit more and more.

It was “easy” to include switches, sensors and even my garage door opener, but I’m struggling with my heaters :slight_smile:

If I have one heater in a room, I control it with the following items:

Switch  HM_OG_SZ_HK_Battery     "HM_OG_SZ_HK_Battery"                           (gHmOgSz, gBattery)    {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801910:0#LOWBAT"}                
Number  HM_OG_SZ_HK_Signal      "HM_OG_SZ_HK_Signalstärke"     <network>        (gHmOgSz, gHmSignal)     {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801910:0#SIGNAL_STRENGTH"} 
Number:Temperature  HM_OG_SZ_HK_CURRTEMP    "Schlafzimmer Ist [%.1f °C]"         <temperature>    (gHmOgSz, gHmHeat, gHmOgSzHk, gHmOgSzHkTemp)      {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801910:4#ACTUAL_TEMPERATURE"}
Number:Temperature  HM_OG_SZ_HK_SETTEMP     "Schlafzimmer Soll [%.1f °C]"       <temperature>    (gHmOgSz, gHmHeat, gHmOgSzHk, gHmOgSzHkTemp)       {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801910:4#SET_TEMPERATURE"}
String  HM_OG_SZ_HK_MODE        "Schlafzimmer Modus"                                 (gHmOgSz, gHmOgSzHk, gHmHkMode)            {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801910:4#CONTROL_MODE"}
Number  HM_OG_SZ_HK_VALVE       "Schlafzimmer Ventil"           (gHmOgSz, gHmOgSzHk)       {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801910:4#VALVE_STATE"}

If I have more than one heater in a room, I’m using a group:

//Wohnzimmer Heizkörper Gruppe
Group   gHmEgWzHkTemp              "Heizkörper Wohnzimmer Temperaturen"       
Group   gHM_EG_WZ_HK               "Wohnzimmer"    
Group:Number:Temperature   gHM_EG_WZ_HK_SETTEMP       "Wohnzimmer Soll [%.1f °C]"        <temperature>                  (gHM_EG_WZ_HK, gHmEgWzHkTemp)  
Group:Number:AVG   gHM_EG_WZ_HK_CURRTEMP       "Wohnzimmer Ist [%.1f °C]"        <temperature>       (gHM_EG_WZ_HK, gHmEgWzHkTemp)                      
Group:Number:AVG   gHM_EG_WZ_HK_VALVE       "Wohnzimmer Ventil"

//Wohnzimmer Heizkörper links
Group   gHmEgWzHkLi                "Heizkörper Wohnzimmer links"       
Group   gHmEgWzHkLiTemp            "Heizkörper Wohnzimmer links Temperaturen"       
Switch  HM_EG_WZ_HK_LI_Battery     "HM_EG_WZ_HK_LI_Battery"                           (gHmEgWz, gBattery)    {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0802290:0#LOWBAT"}                
Number  HM_EG_WZ_HK_LI_Signal      "HM_EG_WZ_HK_LI_Signalstärke"     <network>        (gHmEgWz, gHmSignal)     {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0802290:0#SIGNAL_STRENGTH"} 
Number:Temperature  HM_EG_WZ_HK_LI_CURRTEMP    "Wohnzimmer links Ist [%.1f °C]"         <temperature>    (gHmEgWz, gHmHeat, gHmEgWzHkLi, gHmEgWzHkLiTemp, gHM_EG_WZ_HK_CURRTEMP)      {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0802290:4#ACTUAL_TEMPERATURE"}
Number:Temperature  HM_EG_WZ_HK_LI_SETTEMP     "Wohnzimmer links Soll [%.1f °C]"       <temperature>    (gHmEgWz, gHmHeat, gHmEgWzHkLi, gHmEgWzHkLiTemp, gHM_EG_WZ_HK_SETTEMP)       {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0802290:4#SET_TEMPERATURE"}
String  HM_EG_WZ_HK_LI_MODE        "Wohnzimmer links Modus"                                 (gHmEgWz, gHmEgWzHkLi, gHmHkMode)            {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0802290:4#CONTROL_MODE"}
Number  HM_EG_WZ_HK_LI_VALVE       "Wohnzimmer links Ventil"           (gHmEgWz, gHmEgWzHk, gHM_EG_WZ_HK_VALVE)       {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0802290:4#VALVE_STATE"}

//Wohnzimmer Heizkörper rechts
Group   gHmEgWzHkRe                "Heizkörper Wohnzimmer rechts"       
Group   gHmEgWzHkReTemp            "Heizkörper Wohnzimmer rechts Temperaturen"       
Switch  HM_EG_WZ_HK_RE_Battery     "HM_EG_WZ_HK_RE_Battery"                           (gHmEgWz, gBattery)    {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801911:0#LOWBAT"}                
Number  HM_EG_WZ_HK_RE_Signal      "HM_EG_WZ_HK_RE_Signalstärke"     <network>        (gHmEgWz, gHmSignal)     {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801911:0#SIGNAL_STRENGTH"} 
Number:Temperature  HM_EG_WZ_HK_RE_CURRTEMP    "Wohnzimmer rechts Ist [%.1f °C]"         <temperature>    (gHmEgWz, gHmHeat, gHmEgWzHkRe, gHmEgWzHkReTemp, gHM_EG_WZ_HK_CURRTEMP)      {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801911:4#ACTUAL_TEMPERATURE"}
Number:Temperature  HM_EG_WZ_HK_RE_SETTEMP     "Wohnzimmer rechts Soll [%.1f °C]"       <temperature>    (gHmEgWz, gHmHeat, gHmEgWzHkRe, gHmEgWzHkReTemp, gHM_EG_WZ_HK_SETTEMP)       {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801911:4#SET_TEMPERATURE"}
String  HM_EG_WZ_HK_RE_MODE        "Wohnzimmer rechts Modus"                                 (gHmEgWz, gHmEgWzHkRe, gHmHkMode)            {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801911:4#CONTROL_MODE"}
Number  HM_EG_WZ_HK_RE_VALVE       "Wohnzimmer rechts Ventil"           (gHmEgWz, gHmEgWzHk, gHM_EG_WZ_HK_VALVE)       {channel="homematic:HG-HM-CC-RT-DN:12bf3b22:MEQ0801911:4#VALVE_STATE"}

If I want to set a new target temperature, I send the new value only to the group item.

So far, everything is fine (without using homekit).

I want to use homekit for two (or three) things:

  1. Current temperature
  2. Target temperature
  3. Current mode (depending on the valves)

My approach:

New Homekit items per room:

Group           gHK_HK_SZ                "Schlafzimmer Heizung"                                    {homekit="Thermostat"}
Number          HK_HK_SZ_current_temp    "Schlafzimmer Current Temp[%.1f C]"    (gHK_HK_SZ)        {homekit="Thermostat.CurrentTemperature"}
Number          HK_HK_SZ_target_temp     "Schlafzimmer Target Temp[%.1f C]"     (gHK_HK_SZ)        {homekit="Thermostat.TargetTemperature"  [minValue=12, maxValue=27, step=0.5]}  
String          HK_HK_SZ_current_mode    "Schlafzimmer Current Mode"            (gHK_HK_SZ)        {homekit="Thermostat.CurrentHeatingCoolingMode"}          
String          HK_HK_SZ_target_mode     "Schlafzimmer Target Mode"             (gHK_HK_SZ)        {homekit="Thermostat.TargetHeatingCoolingMode"}           

And the following rules:

// Schlafzimmer
rule "1 Heizung Schlafzimmer Current temp"
    Item HM_OG_SZ_HK_CURRTEMP received update
    logInfo("Heizung Schlafzimmer", "Currenttemp geändert - Regel ausgeführt")
    HK_HK_SZ_current_temp.postUpdate(HM_OG_SZ_HK_CURRTEMP.state as Number)
    HK_HK_SZ_current_temp.sendCommand(HM_OG_SZ_HK_CURRTEMP.state as Number)     

rule "2 Heizung Schlafzimmer Current mode"
    Item HM_OG_SZ_HK_VALVE received update
   if (HM_OG_SZ_HK_VALVE.state > 10) {
    else {

rule "3 Heizung Schlafzimmer Target temp"
    Item HM_OG_SZ_HK_SETTEMP received update
    logInfo("Heizung Schlafzimmer", "Settemp geändert - Regel ausgeführt")
        HK_HK_SZ_target_temp.postUpdate(HM_OG_SZ_HK_SETTEMP.state as Number)
        HK_HK_SZ_target_temp.sendCommand(HM_OG_SZ_HK_SETTEMP.state as Number)         

rule "4 Heizung Schlafzimmer Target temp HK"
    Item HK_HK_SZ_target_temp received update
    logInfo("Heizung Schlafzimmer", "Targettemp Homekit geändert - Regel ausgeführt")
        HM_OG_SZ_HK_SETTEMP.postUpdate(HK_HK_SZ_target_temp.state as Number)
        HM_OG_SZ_HK_SETTEMP.sendCommand(HK_HK_SZ_target_temp.state as Number)     

My results:
Rule 2 is working fine. Homekit shows “Heating” when valves are >10.
Rule 1 is NOT working … but I have no error or warning in the logfile. Could it be a type mismatch?
Rule 3 is NOT working … target temperature still shows the old value … no update
Rule 4 is working. I can set the target temperature with homekit.

I’m sure that the approach is not the only way how it could work. But it should work.

Any help is appriciated.

Let me answer myself :slight_smile:

I partly solved this issue: All rules are working :slight_smile:
The only thing I had to do: removing the “:temperature” in the items definition of the Homematic items (settemp and currtemp).

But I have still an issue with the group of two Homegear devices.
I took away the “:temperature” from the two heaters and also from the group.
But rule 3 is still not working.
Rule 3 means : The target value was changed thru OpenHAB and shoulb be transferred to Homekit.

The error message in the logfile is:

2020-10-20 16:53:37.693 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Heizung Alina Target temp': Could not cast UNDEF to java.lang.Number; line 89, column 46, length 36

This is the corresponding line in the rule:

HK_HK_AL_target_temp.sendCommand(gHM_OG_AL_HK_SETTEMP.state as Number)

The value of gHM_OG_AL_HK_SETTEMP is “22.0 °C” … but the value of the two group members is “22.00” and “22.00” – without “°C”.
This seems to be the problem.

This is the item definition:

Group   gHmOgAlHkTemp              "Heizkörper Alina Temperaturen"       
Group:Number   gHM_OG_AL_HK_SETTEMP       "Alina Soll [%.1f °C]"         <temperature>            (gHmOgAlHkTemp)
Group:Number:AVG   gHM_OG_AL_HK_CURRTEMP       "Alina Ist [%.1f °C]"        <temperature> (gHmOgAlHkTemp)
Group:Number:AVG   gHM_OG_AL_HK_VALVE       "Alina Ventil"

But before it was:

Group   gHmOgAlHkTemp              "Heizkörper Alina Temperaturen"       
Group:Number:Temperature   gHM_OG_AL_HK_SETTEMP       "Alina Soll [%.1f °C]"         <temperature>            (gHmOgAlHkTemp)
Group:Number:AVG   gHM_OG_AL_HK_CURRTEMP       "Alina Ist [%.1f °C]"        <temperature> (gHmOgAlHkTemp)
Group:Number:AVG   gHM_OG_AL_HK_VALVE       "Alina Ventil"

Why has the group item still “°C” at the end even if I changed it in the items definition?

Maybe someone can help now.

Thank you so much for the example. I’ve got only one problem: When I use rule 3 and 4 I create an endless loop.

My fault was to use only a Number Item:

Number thermostat_target_temp “Thermostat Target Temp[%.1f C]” (gThermostat) {homekit=“Thermostat.TargetTemperature”}

when I use Number:Temperature thermos… the temperatur will not be transmitted to the Thermostat.

I think thats also your “last problem” so i hope you answer your question again :wink:


regarding the loop, it is triggered by sendCommand.
the difference between postUpdate and sendCommand is that

  • “postUpdate” only change the state and not trigger any rules,
  • sendCommand change the state and trigger related rules.

so, if you remove

HM_OG_SZ_HK_SETTEMP.sendCommand(HK_HK_SZ_target_temp.state as Number)  
HK_HK_SZ_target_temp.sendCommand(HM_OG_SZ_HK_SETTEMP.state as Number)         

then the loop will stop