Homekit scene activation bug

Hi,
I was able to use this amazing platform to integrate my gadgets with HomeKit, but I think I discovered a bug. Before posting I have upgraded to latest snapshot.

Setup: OH2 latest snapshot downloaded 17. Dec 12:00 p.m., Win. Server 2012 R2, Aeon Z-Stick, Fibaro Dimmer 2, HomeKit Integration addon

Status: I’m able to set particular illumination level using HomeKit manually.

Bug: When I create a scene in HomeKit mobile app with one light which should be set to 20% illumination and click test scene, it works as expected and the light is set to 20%.

OH2 log when scene is tested in HomeKit app:

12:13:45.044 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Dimmer' received command ON
12:13:45.047 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Dimmer' received command 20
12:13:45.047 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer changed from 0 to 100
12:13:45.051 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer changed from 100 to 20

But when the scene is saved and then activated, the light is set to 100% after activation.

OH2 log when a the scene is activated in HomeKit app:

12:12:47.256 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Dimmer' received command 20
12:12:47.258 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Dimmer' received command ON
12:12:47.258 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer changed from 0 to 20
12:12:47.261 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer changed from 20 to 100

I installed latest snapshot yesterday. Everything works fine.

You have to create rule for you lighting item. See example -

rule:

rule "Populate lr_Light from zwave_device_1590aeb5569_node6_switch_dimmer"
when
Item zwave_device_1590aeb5569_node6_switch_dimmer received update or
System started
then
lr_Light.postUpdate(zwave_device_1590aeb5569_node6_switch_dimmer.state)
end

rule "lr_Light switched"
when
Item lr_Light received command
then
if (receivedCommand != ON) {
zwave_device_1590aeb5569_node6_switch_dimmer.sendCommand(receivedCommand)
}
end

Item:

Dimmer lr_Light “Living Room Light [%s]” (livingRoom) [ “Lighting” ]

1 Like

Thanks for the reply. As I understand you have an item added in Paper UI as “zwave_device_1590aeb5569_node6_switch_dimmer” and you have created “lr_Light” in text file .items and using this rule you are reflecting changes between them.

In my case, I just have added Z-Wave Dimmer item in Paper UI and tagged it with “Lighting”.

Now, after a couple of restarts, when using scene, the behavior is OK. But when I say “Hey Siri, set bedroom light to 20%” is set to 100% and log looks as follows:

14:56:58.242 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Nocni_Lampa_Matus_Dimmer' received command 20
14:56:58.243 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Nocni_Lampa_Matus_Dimmer' received command ON
14:56:58.246 [INFO ] [marthome.event.ItemStateChangedEvent] - Nocni_Lampa_Matus_Dimmer changed from 0 to 20
14:56:58.249 [INFO ] [marthome.event.ItemStateChangedEvent] - Nocni_Lampa_Matus_Dimmer changed from 20 to 100

Maybe I missed something in documentation, and I need to create a duplicate of each Z-Wave item dimmer and reflect changes between them, but it seems like double work.

Yes, to make “lights” properly work with homekit you need separate item created in .items and tagged.

Thanks, I have used your rule and it works perfectly.

This is related only to items defined outside .items file?

Or do I need to have duplicates e.g. for thermostat .items (I think there are 3 of them) and make a sync rule also for them? Asking because as now, when I change the heating/cooling mode in OH2 is then instantly projected into HomeKit app, but not vice versa.

It depends how your thermostat item setup. Is it slider .item ? I have ecobee and using native home kit integration.

This is my thermostat group populated to HomeKit using tags. I have no other items related to thermostat.

Group Group_VirtualThermostat "Virtual Thermostat" [ "Thermostat" ]

Number Number_ActualTemp  "Actual Temp [%.1f °C]" <temperature> (Group_VirtualThermostat) [ "CurrentTemperature" ] { snmp="<[192.168.1.4:shakira:.1.3.6.1.4.1.19865.1.2.3.1.0:60000:JS(actualTemp.js)]" } 

Number Setpoint_TargetTemp "Living Room Setpoint [%.1f °C]" <temperature> (Group_VirtualThermostat) [ "TargetTemperature" ]

String Switch_HeatingMode "Heating Mode" <heating> (Group_VirtualThermostat) [ "homekit:HeatingCoolingMode" ]


Switch  Switch_HeatingRelay "Heating [%s]" <fire> { snmp="<[192.168.1.3:shakira:.1.3.6.1.4.1.19865.1.2.2.1.0:60000:MAP(SwitchState.map)] >[OFF:192.168.1.3:shakira:.1.3.6.1.4.1.19865.1.2.2.1.0:0] >[ON:192.168.1.3:shakira:.1.3.6.1.4.1.19865.1.2.2.1.0:1]"}

To operate the thermostat I’m using thermostat rule. Now it’s operating only heating and it’s semi-prepared also for cooling:

ule "Thermostat"
when
    Item Switch_HeatingMode changed or
    Item Setpoint_TargetTemp changed or
    Item Number_ActualTemp changed
then
    if (Switch_HeatingMode.state == "Off") {
        // heater&cooler off
        Switch_HeatingRelay.sendCommand(OFF)
        //insert truning off cooler here
    } else if (Switch_HeatingMode.state == "HeatOn") {
        // heater on, cooler off
        Switch_HeatingRelay.sendCommand(ON)
        //insert truning off cooler here
    } else if (Switch_HeatingMode.state == "CoolOn") {
        // cooler on
        //insert turning on cooler here
    } else if (Switch_HeatingMode.state == "Auto") {
            // get the current setpoint for the room
            var Number setpoint = Setpoint_TargetTemp.state as DecimalType

            // calculate the turn on/off temperatures
            var Number turnOnTemp = setpoint - 0.4
            var Number turnOffTemp = setpoint + 0.3

            // get the current temperature in the room
            var Number temp = Number_ActualTemp.state as DecimalType
            
            // determine whether we need to turn on/off the heater
            if (temp <= turnOnTemp) {
                // turn on temp has been reached so switch on the heater
                Switch_HeatingRelay.sendCommand(ON)
            } else if (temp >= turnOffTemp) {
                // turn off temp has been reached so switch off the heater
                Switch_HeatingRelay.sendCommand(OFF)
                }
                
            }  
end

And finally the sitemap file:

sitemap heating label="Heating"
{
  Frame label="Heating" {
   	Switch item=Switch_HeatingMode label="Thermostat Mode" mappings=[Off="Off", HeatOn="Heating", CoolOn="A/C", Auto="Auto"]
   	Text item=Switch_HeatingRelay label="Heating Status"
	Setpoint item=Setpoint_TargetTemp label="Target Temperature [%.1f °C]" minValue=16 maxValue=27 step=0.5 visibility=[Switch_HeatingMode==Auto]
	Text item=Number_ActualTemp
  }
  }

I thought that when I change the heating mode in HomeKit app ti will update item Switch_HeatingMode, but it doesn’t. Not sure how to catch this change and update this item. It works when I change the heating mode in OH2 UI it’s instantly changed in HomeKit app. I have no troubles with populating the target temperature change from HomeKit app to Setpoint_TargetTemp item.