steilerDev / homebridge-openhab2-complete

A homebridge plugin for openHAB, that has the expectation to fully support all Services offered by Apple's Homekit Accessory Protocol (HAP)
GNU General Public License v3.0
52 stars 16 forks source link

OpenHAB expects UP/DOWN/STOP, instead sending 0/100 #2

Closed piejanssens closed 5 years ago

piejanssens commented 5 years ago

OH event log: The UP/DOWN/STOP commands you see are being sent from Paper UI. The others (0/100) are being sent from Home app.

2019-01-31 20:15:28.757 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command 0
2019-01-31 20:15:28.760 [nt.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become 0
2019-01-31 20:15:28.762 [vent.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 100 to 0
2019-01-31 20:15:38.465 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command 100
2019-01-31 20:15:38.466 [nt.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become 100
2019-01-31 20:15:38.471 [vent.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 0 to 100
2019-01-31 20:16:12.259 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command UP
2019-01-31 20:16:12.259 [nt.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become UP
2019-01-31 20:16:12.260 [vent.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 100 to 0
2019-01-31 20:16:13.366 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command STOP
2019-01-31 20:16:14.698 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command DOWN
2019-01-31 20:16:14.699 [nt.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become DOWN
2019-01-31 20:16:14.700 [vent.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 0 to 100
2019-01-31 20:17:10.974 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command 0
2019-01-31 20:17:10.975 [nt.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become 0
2019-01-31 20:17:10.976 [vent.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 100 to 0
2019-01-31 20:17:12.944 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command 100
2019-01-31 20:17:12.945 [nt.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become 100
2019-01-31 20:17:12.947 [vent.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 0 to 100
2019-01-31 20:17:14.708 [ome.event.ItemCommandEvent] - Item 'RFXCOMRfyActuator_Shutter' received command 0
2019-01-31 20:17:14.709 [nt.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become 0
2019-01-31 20:17:14.714 [vent.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 100 to 0

homebridge log:

[1/31/2019, 8:15:28 PM] [openHAB2-Complete] Transformed 0 with inverted set to false for Rolluiken to 0
[1/31/2019, 8:15:28 PM] [openHAB2-Complete] Change target state of Rolluiken [RFXCOMRfyActuator_Shutter] to 0 (transformed to 0)
[1/31/2019, 8:15:28 PM] [openHAB2-Complete] Changed target state of Rolluiken [RFXCOMRfyActuator_Shutter] to 0
[1/31/2019, 8:15:28 PM] [openHAB2-Complete] Received push with new state for item RFXCOMRfyActuator_Shutter: 0
[1/31/2019, 8:15:28 PM] [openHAB2-Complete] Transformed 0 with inverted set to false for Rolluiken to 0
[1/31/2019, 8:15:38 PM] [openHAB2-Complete] Transformed 100 with inverted set to false for Rolluiken to 100
[1/31/2019, 8:15:38 PM] [openHAB2-Complete] Change target state of Rolluiken [RFXCOMRfyActuator_Shutter] to 100 (transformed to 100)
[1/31/2019, 8:15:38 PM] [openHAB2-Complete] Changed target state of Rolluiken [RFXCOMRfyActuator_Shutter] to 100
[1/31/2019, 8:15:38 PM] [openHAB2-Complete] Received push with new state for item RFXCOMRfyActuator_Shutter: 100
[1/31/2019, 8:15:38 PM] [openHAB2-Complete] Transformed 100 with inverted set to false for Rolluiken to 100
[1/31/2019, 8:16:12 PM] [openHAB2-Complete] Received push with new state for item RFXCOMRfyActuator_Shutter: 0
[1/31/2019, 8:16:12 PM] [openHAB2-Complete] Transformed 0 with inverted set to false for Rolluiken to 0
[1/31/2019, 8:16:14 PM] [openHAB2-Complete] Received push with new state for item RFXCOMRfyActuator_Shutter: 100
[1/31/2019, 8:16:14 PM] [openHAB2-Complete] Transformed 100 with inverted set to false for Rolluiken to 100

Bonus: Push notification when shutter operates works (when it was triggered from Paper UI) šŸŽ‰

steilerDev commented 5 years ago

So your item does not work when receiving percentages, but needs to get the commands 'UP', 'DOWN' or 'STOP'?

piejanssens commented 5 years ago

Indeed. Do you have shutters or anything alike in your own setup?

I read your comment that you don't know how to invoke 'STOP': I'm not sure, but I think normally the STOP is invoked by HomeKit when the shutter is moving (animated on screen) and while moving you press the button again. This probably requires this to be invoked by OH. If the shutter does not do this automatically then a rule can be created in either OH or HomeKit to send the command after a timer (measure time it takes to open or close shutters).

Is this called both when sending commands to OpenHAB as when receiving events from OpenHAB?

steilerDev commented 5 years ago

My shutters accept a percentage state, so when calling them with e.g. 40 they will automatically stop at 40, therefore I didn't think of implementing UP/DOWN, since I thought all of them would behave that way ;)

About the comment: When pressing again on a closing or opening window covering in the Home.app it just reverses the action and opens or closes the covering again. I didn't find the control in the Home.app to tell the accessory to stop.

Yes, the transformation function needs to be adjusted to send UP and DOWN whenever the item receives a 100 or a 0. However there won't be a possibility through this to send a correctly timed STOP whenever it reaches the correct percentage between those two. Your covering (from the perspective of Homebridge) will look more like a binary switch that can be either open or closed but nothing in between. I think the best way would be to time the operation, create a virtual Rollershutter item and control the in-between states through an openHAB rule.

steilerDev commented 5 years ago

I implemented a fix in my V0.8.0 branch. If you want to test it you have to manually clone the repo, switch to the branch and make a local npm install. Let me know if this behaves as expected.

piejanssens commented 5 years ago

It operates! But the state never changes in HomeKit. It stays in 'closing...' or 'opening...'.

steilerDev commented 5 years ago

Apparently the current state of the roller shutter is either not updated by the device or openHAB. Could you please check the item's state when opening and closing (you can use the openhab console and smarthome:status <itemname> or follow the logs). It is expected, that the Rollershutter reports 0 for a closed state and 100 for an opened state, as soon as you hit the close button the Target state of the accessory is updated and Opening and Closing is displayed based on the difference between Target and Current State. If the current state is not updated correctly, this leads to this behavior.

So, in order to find the problem, could you please share the logs of Homebridge with an interaction of closing and opening the covering? Please start Homebridge in debug mode (homebridge -D) for that.

piejanssens commented 5 years ago

I learned that RFXcom has chosen not to implemented the events from the Somfy rolling shutters for security reasons. I will have to look into creating a fake item and trying to provide the events myself using timers. If you have any guides on this that would be very helpful. šŸ˜‰

I have to create a fake item in OH, then create rules for it that will send state update (% open/stopped) events that are catched by homebridge?

steilerDev commented 5 years ago

Yes, I would create a Rollershutter item with no bindings.

That should do the trick. Let me know if everything works out, so we can close the issue ;)

P.S.: I just released v0.8.0 with the changes required for the initial issue, therefore you can now go back to the official npm release channel

piejanssens commented 5 years ago

What should I send to the fake item from within the rule?

rule "rollingshutters"
when
    Item RFXCOMRfyActuator_Shutter received command
then
    logInfo("Test rule","Test rule triggered")
    if(receivedCommand == UP || receivedCommand == 0){
        Rolluiken_Somfy.postUpdate(0)
    }
    if(receivedCommand == DOWN || receivedCommand == 100){
        Rolluiken_Somfy.postUpdate(100)
    }
end 
                {
                    "name": "Rolluiken",
                    "type": "windowcovering",
                    "item": "RFXCOMRfyActuator_Shutter",
                    "stateItem": "Rolluiken_Somfy"
                }
[2/7/2019, 6:56:13 PM] [openHAB2-Complete] Transformed 100 with inverted set to false and multiplier set to 1 for Rolluiken (type: RollershutterSetter) to UP
[2/7/2019, 6:56:13 PM] [openHAB2-Complete] Change target state of Rolluiken [RFXCOMRfyActuator_Shutter] to 100 (transformed to UP)
[2/7/2019, 6:56:13 PM] [openHAB2-Complete] Context: [object Object], connectionID: 03bdcacb-d5f9-4bce-9997-b28fd7f21bbc
[2/7/2019, 6:56:13 PM] [openHAB2-Complete] Changed target state of Rolluiken [RFXCOMRfyActuator_Shutter] to UP
[2/7/2019, 6:56:13 PM] [openHAB2-Complete] Received push with new state for item Rolluiken_Somfy: 0
[2/7/2019, 6:56:13 PM] [openHAB2-Complete] Checking if actual state is within threshold (3) of target state
[2/7/2019, 6:56:13 PM] [openHAB2-Complete] Transformed 0 with inverted set to false and multiplier set to 1 for Rolluiken (type: Rollershutter) to 0
[2/7/2019, 6:56:16 PM] [openHAB2-Complete] Transformed 0 with inverted set to false and multiplier set to 1 for Rolluiken (type: RollershutterSetter) to DOWN
[2/7/2019, 6:56:16 PM] [openHAB2-Complete] Change target state of Rolluiken [RFXCOMRfyActuator_Shutter] to 0 (transformed to DOWN)
[2/7/2019, 6:56:16 PM] [openHAB2-Complete] Context: [object Object], connectionID: 03bdcacb-d5f9-4bce-9997-b28fd7f21bbc
[2/7/2019, 6:56:16 PM] [openHAB2-Complete] Changed target state of Rolluiken [RFXCOMRfyActuator_Shutter] to DOWN
[2/7/2019, 6:56:16 PM] [openHAB2-Complete] Received push with new state for item Rolluiken_Somfy: 100
[2/7/2019, 6:56:16 PM] [openHAB2-Complete] Checking if actual state is within threshold (3) of target state
18:53:07.993 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'home.rules'
18:53:34.648 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'RFXCOMRfyActuator_Shutter' received command UP
18:53:34.654 [INFO ] [arthome.event.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become UP
18:53:34.658 [INFO ] [smarthome.event.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 100 to 0
18:53:34.777 [INFO ] [ipse.smarthome.model.script.Test rule] - Test rule triggered
18:53:34.789 [INFO ] [smarthome.event.ItemStateChangedEvent] - Rolluiken_Somfy changed from NULL to 0
18:53:37.913 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'RFXCOMRfyActuator_Shutter' received command DOWN
18:53:37.917 [INFO ] [ipse.smarthome.model.script.Test rule] - Test rule triggered
18:53:37.921 [INFO ] [arthome.event.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become DOWN
18:53:37.924 [INFO ] [smarthome.event.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 0 to 100
18:53:37.932 [INFO ] [smarthome.event.ItemStateChangedEvent] - Rolluiken_Somfy changed from 0 to 100
18:56:09.735 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'home.rules'
18:56:13.474 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'RFXCOMRfyActuator_Shutter' received command UP
18:56:13.483 [INFO ] [arthome.event.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become UP
18:56:13.491 [INFO ] [smarthome.event.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 100 to 0
18:56:13.727 [INFO ] [ipse.smarthome.model.script.Test rule] - Test rule triggered
18:56:13.738 [INFO ] [smarthome.event.ItemStateChangedEvent] - Rolluiken_Somfy changed from 100 to 0
18:56:16.253 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'RFXCOMRfyActuator_Shutter' received command DOWN
18:56:16.258 [INFO ] [arthome.event.ItemStatePredictedEvent] - RFXCOMRfyActuator_Shutter predicted to become DOWN
18:56:16.259 [INFO ] [ipse.smarthome.model.script.Test rule] - Test rule triggered
18:56:16.260 [INFO ] [smarthome.event.ItemStateChangedEvent] - RFXCOMRfyActuator_Shutter changed from 0 to 100
18:56:16.271 [INFO ] [smarthome.event.ItemStateChangedEvent] - Rolluiken_Somfy changed from 0 to 100
18:56:37.916 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'home.rules'
steilerDev commented 5 years ago

I'm a little bit irritated, which one of them is your 'fake' item and which one is the actual shutter?

The way I would do it is that:

rollershutter.items

Rollershutter myRollershutter (rollershutter) {channel="..."} // The 'real' rollershutter device
Rollershutter myRollershutter_HK (rollershutter_hk) // The 'fake' rollershutter device

homekit_rollershutter.rules

rule "Homekit send rollershutter command"
when
    Member of rollershutter_hk received command
then
    val ruleName = "hk_rollershutter_command"
    val blind = triggeringItem as RollershutterItem
    val blindDeviceName = blind.name.replaceAll("_HK", "")
    val command = "DOWN"
    if(receivedCommand == "UP" || receivedCommand >= 50) {
        command = "UP"
    }
    logInfo(ruleName, blind.name + " received command " + command + " sending it to " + blindDeviceName)
    sendCommand(blindDeviceName, command)
end

Using groups allows you to reuse the rule for every of your roller shutter (I did not test the if statement, so you might need to check if the command will be send as string or integer and maybe adjust this part).

config.json

 {
    "name": "Rolluiken",
    "type": "windowcovering",
    "item": "myRollershutter_HK"
}

Since sending the command already set's the state this should already work (and your roller shutter should show closed/open immediately.

steilerDev commented 5 years ago

Merged into master with d25d6df04dbc959da8cd1d74589541e40c89b31f and released as v0.9.0

jeremybdk commented 4 years ago

@steilerDev first let me thanks you for your work, it's amazing, I wanted to use something like this for a long time and your work is really amazing. I commenting here because it might be interesting regarding this issue. Basically my shutter can only receive UP, Down and STOP. most of the time I want to use UP and then stop when I need it or down and stop it when I need it.

Is there a way to do that with the current version of openhab2-complete ? I'm thinking of creating 2 fake devices (one for up and stop and another one for down and stop). I can't figure out a way to do this with the current openhab2-complete version.

Thanks a lot for your help,

Best,