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

Rollershutter logic wrong state #40

Closed grzegorz914 closed 4 years ago

grzegorz914 commented 4 years ago

Hi,

in Rollershutter logic is something wrong,

if moving the rollershutter from 0 to 100 then Home Kit accessory display CLOSING if moving the rollershutter from 100 to 0 then HomeKit accessory display OPENING,

but if go to 100 then HomeKit accessory display OPEN and if go to 0 display CLOSED and that is wrong. Chenge "inverted" to true nothing help

my config:

 {
                    "name": "Kotłownia roleta 1",
                    "type": "windowcovering",
                    "item": "ParterKotlowniaRoleta1",
                    "inverted": "false",
                    "multiplier": "1",
                    "stateItem": "PLC_ParterKotlowniaRoleta1Pozycja",
                    "stateItemInverted": "false",
                    "stateItemMultiplier": "1",
                    "manuMode": "false"
                },

*.items

Rollershutter - ParterKotlowniaRoleta1 (for start moving)
Number - PLC_ParterKotlowniaRoleta1Pozycja (for positioning 0 - 100)

*rules

rule "Roleta kotłownia 1"
when
    Item ParterKotlowniaRoleta1 received command
then
    if(!(receivedCommand instanceof Number))
        switch receivedCommand {
            case UP :    if (PLC_ParterKotlowniaRoleta1Zamykanie.state == OPEN && ParterKotlowniaRoleta1.state == 0) {
                                 ParterKotlowniaRoleta1.sendCommand(STOP)} // simulate STOP command for HK 
                            else
                                {PLC_ParterKotlowniaRoleta1Otworz.sendCommand(ON)
                                 PLC_ParterKotlowniaRoleta1Otworz.sendCommand(OFF)}
            case DOWN : if (PLC_ParterKotlowniaRoleta1Otwieranie.state == OPEN && ParterKotlowniaRoleta1.state == 100) {
                                ParterKotlowniaRoleta1.sendCommand(STOP)}  // simulate STOP command for HK                             else 
                                {PLC_ParterKotlowniaRoleta1Zamknij.sendCommand(ON)
                                 PLC_ParterKotlowniaRoleta1Zamknij.sendCommand(OFF)}
            case STOP :  if (PLC_ParterKotlowniaRoleta1Otwieranie.state == OPEN) { 
                             PLC_ParterKotlowniaRoleta1Otworz.sendCommand(ON)
                             PLC_ParterKotlowniaRoleta1Otworz.sendCommand(OFF)} 
                            else if (PLC_ParterKotlowniaRoleta1Zamykanie.state == OPEN) { 
                                     PLC_ParterKotlowniaRoleta1Zamknij.sendCommand(ON)
                                     PLC_ParterKotlowniaRoleta1Zamknij.sendCommand(OFF)}    
        }
       else 
           logInfo("Roleta","received Number {}, doing nothing!",receivedCommand)
end

log for HomeKit button declared in OH as rollershutter: Command UP moving to 0

2019-08-03 11:54:46.969 [ome.event.ItemCommandEvent] - Item 'ParterKotlowniaRoleta1' received command UP
2019-08-03 11:54:46.980 [vent.ItemStateChangedEvent] - ParterKotlowniaRoleta1 changed from 100 to 0

CurrentTargetPosition.js (UP and DOWN inverted)


 case 'RollershutterSetter':
        case 'Rollershutter':
        case 'Number':
            //This part is only invoked if this is used in a setter context and the item is a rollershutter
            **if(type === 'RollershutterSetter' && value === 100) {
                transformedValue = 'UP';**
            } else if(type === 'RollershutterSetter' && value === 0) {
                transformedValue = 'DOWN';
            } else {

                if (inverted) {
                    transformedValue = Math.floor(100 - (parseFloat(value) * multiplier));
                } else {
                    transformedValue = Math.floor(parseFloat(value) * multiplier);
                }
                if (transformedValue >= 99) { // Weird not showing 100 or 0 bug of openHAB
                    transformedValue = 100;
                }
                if (transformedValue <= 1) {
                    transformedValue = 0;
                }

Thanks Grzegorz

EjvindHald commented 4 years ago

I am using windowcovering as you are, and it is working fine for me. My number item is called KLF200Rulleskodde, and the config is:

{"type": "windowcovering", "items": [ {"name": "Rulleskodde scenarie", "item": "ForsteSalRulleskoddeRoller", "inverted": "true", "manuMode": "true"} ,{"name": "Markise vest", "item": "MarkiseVestRoller", "inverted": "true", "manuMode": "true"} ,{"name": "Markise syd", "item": "MarkiseSydRoller", "inverted": "true", "manuMode": "true"} ,{"name": "Rulleskodde", "item": "KLF200Rulleskodde", "inverted": "true", "manuMode": "true"} ]

grzegorz914 commented 4 years ago

Sorry but the moving direction does not corresponded the end state. If moving from 0 to 100 (CLOSING) then after stop on 100 need to be displayed CLOSED but isn't.

As I described in previous post CurrentTargetPosition.js uses inverted state for 0 and 100 position. Position 100 for rollershutter is DOWN (window completely shaded).

Same rollerschutter in OH app are displayed correctly.

EjvindHald commented 4 years ago

I might have a different setup than yours, but it is working fine. I am also using "inverted":"true" and in openHAB it is defined as "slider" in the sitemap. This is important and makes things a lot eaiser.

Changes done in Homekit app: Opening.. and Closing... are shown correctly for the direction in the iPhone app.

Changes done in openHAB numeric value: Opening... and Closing.. are not shown in the iPhone app. Instead, if the value is changed to 0 or 100 it simply changes to open or closed in the iPhone app when this is done.

grzegorz914 commented 4 years ago

OK,

all is correct.